Hi Vishi and Elio,
I am using a baud rate of 56000 communicating between a AMD Athlon thunderbird 1.0+GHz running on win2000 and a pentinum III on a win98 system.
Below is part of the receiving code which is very much similar to the one given by NI in its serial communication example.
For the sending computer,
Basically i send the command and wait until a reply is received using a do-while loop in the same function.
***************Code*******************
//Sending data here
stringsize3 = StringLength (send_data3);
bytes_sent3 = ComWrt (comport3, send_data3, stringsize3);
RS232Error3 = ReturnRS232Err ();
//Waiting for reply here
do{
bytes_read3 = ComRdTerm (comport3, read_data3,
read_cnt3,read_term3);
}while(bytes_read3 == 0);
***************End of Code*******************
For the receiving computer,
it uses comcallback function on detecting data.
the code for the comcallback function is
***************Code*******************
void ReadCallBack (int comport, int eventMask,void *callbackData)
{
inqlen = GetInQLen (comport);
if(inqlen){
read_data[0] = '\0';
GetCtrlVal (panel_handle, SERIAL_READ_COUNT, &read_cnt);
GetCtrlIndex (panel_handle, SERIAL_READTERM, &read_term_index);
switch (read_term_index)
{
.
.
}
bytes_read = ComRdTerm (comport, read_data, read_cnt,
CopyString (tbox_read_data, 0, read_data, 0, bytes_read);
if(CompareStrings (tbox_read_data, 0, "END", 0, 0) == 0)
{
***some action
SendAscii();//to send acknowledge reply that command received and action performed
}
else if(CompareStrings (tbox_read_data, 0, "START", 0, 0) == 0)
{
***some action
SendAscii();//to send acknowledge reply that command received and action performed }
}
RS232Error = ReturnRS232Err ();
if (RS232Error)
DisplayRS232Error ();
}
***************End Of Code*******************
My problem is that using the first code on the sending computer, I will send a command to the receiving computer which uses the second code. After the receiving computer performed the required task (ie. writing to a file), it will send acknowledgement to the sending computer thru SendAscii(). Once the sending computer received this acknowledgement (it will wait for this acknowledgement as my code put it in a waiting loop), it will send another set of command. Hence, through this sequence of communication, it seems to me that this will ensure the receiving computer will receive new commands when it is free every time.
However, i have encountered a problem that is after a few loops of communication (the number of loops is random every time), the sending computer will wait for reply after sending a command... but the receiving computer does not receive the sent command at all.
I tried using XON/XOFF for software control but it did not help. However, i have recently tried to lower the baud rate.. it seemed to prolong the communication but the problem still surfaced.
Thanks