Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

serial port reads are intermittently too short

I'm trying to read an asynchronus binary (not ASCII) serial message at 38400 baud, transmitted at 100 hz. I don't need to read all messages, just 10 or 20hz.
Each message length is 18 bytes, with a test word AA55 (hex) followed by a status/count word and data words. The status word is normally 0XXX, where XXX is the message sequential count from 0 to 800 decimal.  With "good" status, the status word will increment from 0800 hex to 0B20 (800 messages).  Checksum and checksum-not are at the end. 
 
The vi I'v written uses the visa read, set to read 72 bytes (to make sure I get at least one complete message).  My problem is that the LV visa read will read the full 72 bytes when the message begins with AA55 08xx, AA55 09xx or AA55 0Bxx but not AA55 0Axx. The read output always stops at AA55 0A, usually only 19 bytes containing the end of the previous message and the first 6 characters of the next. When the messages get to count AA55 0B the visa read will get the full 72 bytes again.
 
It looks like the port read is halting when it sees the 0A (0000 1010 bin) but not 08, 09 or 0B. I have used the "number of bytes at port" function in a while-loop to make sure there are 72 bytes available before reading, with a loop exit at 100 iterations. The while loop exits after executing 100 iterations before seeing 72 bytes in the port.
 
I can't understand why the failures always occur at the 0A messages.  Could there be something unique about the pattern AA55 0A that effects the port reading?  Other programs can read the data continuously so it is not a transmitter issue.
 
Thanks,
 
Rikard
0 Kudos
Message 1 of 3
(3,332 Views)
Of course there's something unique about 0A. It's the line feed character. Look at the VISA Configure Serial Port function. The default setting for the Enable Termaination Character input is true. The default termination character is 0A. With termination character enabled, VISA Read will terminate it's read whenever the character is detected. It doesn't matter what you have set for the byte count.
Message 2 of 3
(3,328 Views)

Dennis,

 

Thanks! I set the termination character to false and it's reading solidly all the way up to 200hz now.  The solution always seems so simple when someone tells you how to do it.

Thanks again,

Rickard

0 Kudos
Message 3 of 3
(3,323 Views)