void collectInput(var hPort)
{
(inputText.pstring)[0] = inputStr;
inputText.pos_y = screen_size.y - 25;
while(1)
{
result = inkey(inputStr);
// while(inkey_active == ON) wait(1);
if(result == 13)
{
port_write_bytes(hPort,_chr(inputStr), str_len(inputStr)+1,1);
appendLine(sendTxt, inputStr);
}
str_cpy(inputStr, " ");
wait(1);
}
}
byte singleByte = -1;
byte inputBytes[10] = {0,0,0,0,0,0,0,0,0,0};
double inputDouble = -1;
var resetCharArray()
{
var count = 0;
while(count < 10)
{
inputBytes[count] = 0;
count += 1;
}
}
void receiveData(var hPort)
{
STRING* inputStr = str_create("");
var count = 0;
while(1)
{
if(key_esc) break;
result = port_read_bytes(hPort,singleByte,1);
if(result > 0)
{
if(singleByte == 0 || count == 9)
{
count = 0;
appendLine(receiveTxt, _str(inputBytes));
resetCharArray();
}
else
{
inputBytes[count] = singleByte;
count += 1;
}
}
wait(1);
}
}
function main()
{
wait(1);
appendLine(sendTxt, "Started.");
on_close = exit_safely;
initLevel();
on_esc = NULL;
byte last_recieved = 0;
hPort = port_open_readwrite("COM2", "9600,n,8,1");
if(hPort)
{
collectInput(hPort);
receiveData(hPort);
wait_for(receiveData);
port_close(hPort);
}
else
{
error("Error connecting to Port");
while(key_esc == OFF) wait(1);
}
sys_exit("");
}