#include <acknex.h>
#include <default.c>
#include "Port_IO.h"
TEXT* debug = { pos_x=20; pos_y=20; size_y=400; font="Arial#20b"; strings=20; flags=SHOW + WWRAP; }
var hPort;
var temp;
var temp2;
byte sent_data[3] = {0xFF, 0x10, 0x00};
byte received_data[3] = {0x00, 0x00, 0x00};
function main()
{
wait(1); level_load(NULL); wait(1); diag("\n\n\n");
on_esc = NULL;
//
//
hPort = port_open_readwrite("COM1", "2400,n,8,1");
wait(-1);
if(port_read_status(hPort))
{
temp = port_write_bytes(hPort, sent_data, 3, 500); // write to com1 1 byte 500ms time out
}
else
{
str_cpy((debug.pstring)[0], "Port is Busy");
port_close(hPort);
while(proc_status(port_close)) wait(1);
//
//
while(!key_any){wait(1); }
sys_exit("");
}
wait(-1);
while(!port_read_status(hPort)){ wait(1);}
if(port_read_status(hPort))
{
port_read_bytes(hPort, received_data, 3); // read data from com1 3 byte
}
//
while(1)
{
str_cpy((debug.pstring)[0], "Port Handle = ");
str_cat((debug.pstring)[0], _chr(str_for_int(NULL,hPort)));
str_cpy((debug.pstring)[1], "Data Sent = ");
str_cat((debug.pstring)[1], _chr(str_for_int(NULL,temp)));
str_cpy((debug.pstring)[2], "Data Read [0]= ");
str_cat((debug.pstring)[2], _chr(str_for_int(NULL,(long)received_data[0])));
str_cpy((debug.pstring)[3], "Data Read [1]= ");
str_cat((debug.pstring)[3], _chr(str_for_int(NULL,(long)received_data[1])));
str_cpy((debug.pstring)[4], "Data Read [2]= ");
str_cat((debug.pstring)[4], _chr(str_for_int(NULL,(long)received_data[2])));
if(key_esc) break;
wait(1);
}
port_close(hPort);
// while(proc_status(port_close)) wait(1);
//
//
sys_exit("");
}