LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

comport communication problem

Hi,

I have this particular problem on programming a serial comport communication application.

I tried to create my own serial port communication protocol with a and as the start and end terminators for a valid command. My commands are to be sent from one computer to another computer. After i send a command e.g. "GO HOME", i will wait for the other computer to perform the task and then confirm that it has received by command before proceeding to send it another command. The confirmation message from the receiving computer looks like the sent command but with a "DONE" appended behind i.e. "GO HOME DONE".

However, there are frequent cases where after i have received the confirmation reply and then sent a new command, the
receiving computer does not receive this new command even though by sending computer has sent it. This is especially true if i do a loop the sending of commands automatically => resend the "GO HOME" command everytime i receive "GO HOME DONE". There are times when the command can be resent > 10 or even more but there are times when it hangs after 2 loops. I found that if i used a faster processor, the number of successful loop increases.

I wonder if using hardware/software control of comport communication will help. Or is it a common problem when communicating through comport between two computers of different processor types and speeds.

can anyone please advice. Thank you.
0 Kudos
Message 1 of 5
(3,552 Views)
owlowl wrote in message news:<5065000000080000005CAE0000-1068850981000@exchange.ni.com>...
> Hi,
>
> I have this particular problem on programming a serial comport
> communication application.
>

I think that your description is too generic.
It might be useful if you provide a piece of the receiving code.
For example, are you using callbacks to read com port or are you polling for data?
0 Kudos
Message 2 of 5
(3,552 Views)
Like Elio said, you need to post soem code. I have used STX/ETX
protocols without any problems so its probably nothing to do with serial
hardware.

BTW - PCs speed has nothing to do with your UART. What baud rates you
are using?


vishi

owlowl wrote:
> Hi,
>
> I have this particular problem on programming a serial comport
> communication application.
>
> I tried to create my own serial port communication protocol with a
> and as the start and end terminators for a valid command.
> My commands are to be sent from one computer to another computer.
> After i send a command e.g. "GO HOME", i will wait for the other
> computer to perform the task and then confirm that it has received by
> command before proceeding to send it another command. The
> conf
irmation message from the receiving computer looks like the sent
> command but with a "DONE" appended behind i.e. "GO HOME DONE".
>
> However, there are frequent cases where after i have received the
> confirmation reply and then sent a new command, the receiving computer
> does not receive this new command even though by sending computer has
> sent it. This is especially true if i do a loop the sending of
> commands automatically => resend the "GO HOME" command everytime i
> receive "GO HOME DONE". There are times when the command can be
> resent > 10 or even more but there are times when it hangs after 2
> loops. I found that if i used a faster processor, the number of
> successful loop increases.
>
> I wonder if using hardware/software control of comport communication
> will help. Or is it a common problem when communicating through
> comport between two computers of different processor types and speeds.
>
> can anyone please advice. Thank you.
Message 3 of 5
(3,552 Views)
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
0 Kudos
Message 4 of 5
(3,552 Views)
owlowl wrote in message news:<506500000005000000033D0100-1068850981000@exchange.ni.com>...
> do{
> bytes_read3 = ComRdTerm (comport3, read_data3,
> read_cnt3,read_term3);
> }while(bytes_read3 == 0);
> ***************End of Code*******************
The problem might be in this code: if an error condition happens
(negative return from ComRdTerm) you get the loop interrupted, and you
are not checking for error.
Also, how do you set read_cnt3 and read_term3? If read_cnt3 is less
than the correct value you loose bytes.
I suggest that you output the read bytes with DebugPrintf.
I personally don't use ComRdTerm, however, by I prefer reading bytes
at once in a loop until the termination byte is received.
Hope this helps
Message 5 of 5
(3,552 Views)