02-06-2007 01:05 PM
I'm wondering if there is a bug
in this function (CVI 8.1) or if it might be something else. I'm probably
not going to do a good job of explaining this so bare with me, but here is the
problem I'm having....
I have a device that sends data (4800/n/8/1 no flowcontrol) in the form of
"$1234\r\n". It does not send the NULL terminator, or the
quotes and sends around 425 of these lines at a time.
To setup the callback function I'm actually looking for the '\r' termination
character or any character sent:
InstallComCallback (portNo, (LWRS_RECEIVE | LWRS_RXCHAR), 1,
'\r', CheckDeviceSerial, 0);
So basically the callback will be invoked on any character sent
In the actual callback function it disables itself and then loops while there
is data in the serial buffer, does the read, then re-enables itself when the
buffer is empty. A simplified code snippet of the main loop is below:
cnt = GetInQLen(portNo);
while(cnt)
{
//buffer is overkill so read upto the term char
numBytesRead = ComRdTerm(portNo, buffer,
254, '\r');
//just put this in to
catch the error
if( (buffer[0] == '\n') || (buffer[0] ==
'\r') )
{
cnt = 1;
}
<usefull processing stuff>
cnt = GetInQLen(portNo);
}
Putting a break on the "cnt = 1" line, it will be hit at random
times. To me, it seems that the comRdTerm isn't always removing the
following LF from the previous read. Examining the buffer, the first character is a LF, which must be from the previous read (should have been removed according to the docs).
If I change the termination character to LF, everything works ok (which I can do
just as well). I will just have to manually remove the CR before the LF.
02-06-2007 01:42 PM
02-06-2007 03:12 PM
02-06-2007 07:19 PM