Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

serial read, timout error

using serial port to continually read from a data collection device. using VISA read without the error wires hooked together it does not work (read times out and stops the program). with the error wires hooked together (from start to read to close) it works and reades perfectly but is somewhat slow. to slow for what I need. I was wondering if there was a way to read the serial port continoulsy without haveing a timeout.
0 Kudos
Message 1 of 8
(4,268 Views)
How did you setup the VISA Configure Serial Port? Do you enable or disable the termination character input? With it unwired or a true wired to it, VISA read will wait until the number of bytes specified is read or until the termination character is received The default termination character is 0xA or the LF character. If the data you expect to read does not end with a LF, you will get a timeout. Wire a false constant to the Configure Serial Port and then before you do a read, use the VISA Bytes at Serial Port to determine exactly how many bytes are in the buffer and wire this to the Byte count input of VISA Read.
0 Kudos
Message 2 of 8
(4,259 Views)
VISA Configure Serial Port:
COM1
baud rate 9600
8 data bits
no parity
1 stop bit
everything else is unwired

I did what you sugested and wired a false and used a VISA bytes at serial port. and It sortof works. I need to read 10 bytes per line. when using the external device sometimes all 10 show up in labview and sometime only 7 or 6. The external device is sending ID codes to it is very important that i recece the entire number

Thanks for the help!
-Ben
0 Kudos
Message 3 of 8
(4,256 Views)
So the VISA Bytes at Serial Port property node returns simply that. If your instrument has not sent all 10 bytes by the time you do a read, it will return however many have been sent, whether it's 1, 2, 7 or all 10 bytes. One way to get around this is to once again use Dennis' suggestion to disable termination and tell the VISA Read to read 10 bytes each time. One caveat to this is if it takes longer than your configured timeout to read 10 bytes, you will once again get the timeout. You may want to increase the timeout to some larger value to ensure that you can always get the data before timing out.

Logan S.
0 Kudos
Message 4 of 8
(4,244 Views)
You're going to have to do some syncronization first. Because the instrument is always sending out 10 bytes and there's no termination character, specifying a 10 byte read might get you part of one message and another part of a second message. You'll have to read some number of bytess and determine how much of a complete message you've received. So, if you read 10 bytes and get 3 bytes of message 1 and 7 bytes of message 2, the next read you do, read 3 bytes and after that, you should be synched to the message stream and a constant 10 byte read will work. This all depends on you knowing where in the message you are. You need to have some sort of format you can depend on. A character that precedes the data or a fixed numeric format such as some fixed number of digits, a decimal point, followed by another fixed number of digits.
0 Kudos
Message 5 of 8
(4,243 Views)
This all kind of works. But it relies on keeping synchronisation whenever it was reached once. Loosing a byte or getting corrupted data can desynchronise your code 'forever'.

It is better to have a While loop with a shift register (SR), initialised to an empty string. Also have your port setup before the While, feeding the reference to it. Than, inside the while loop, get the number of bytes availabel and read them, Append them to the content of SR. Check for the first complete message and remove it (and all preceding bytes). Repeat the check until no more complete messages are availabel. Feed remaining incomplete messages into the right connector of the SR. Add a wait 10ms into the case when no complete messages are detected.
It may be apropriate to not process the detected messages inside that while loop, but instead transfer them to another VI (for instance using a (named) queue.
The above mentioned While might be stopped by a button or whenever there was no byte detected within a given period of time. Don't forget to cleanup (closing the port and all refs.

Greetings from Germany!
--
Uwe
0 Kudos
Message 6 of 8
(4,240 Views)
My biggest problem is time. This read has to be done as quickly as possible because while this is going on I am taking other measurments some of which are pulses that I cannot miss. So I really can't afford to sit and wait for bits to be sent. It doesn't matter if I process the info right away or in a nother section of the code where speed is not important. Also the data comming from my device will be comming at unknown times and unknown intervals. so I would like to get all 10 bytes before moving on to the next ID code. I am trying to find out if the ID codes all start with the same format, It looks like so far that they do so that would help for syncronization.
Thanks everyone for all the help!
-Ben
0 Kudos
Message 7 of 8
(4,231 Views)
With a false constant at the enable termination character finding the number of Bytes at Port then reading that many of bytes, It works some of the time. It will read the 10 bytes but sometimes it misses and entire ID code when I know the external device has sent the data to labview. with this set up the speed is great but missing data is never a good thing 🙂
thanks again!
-Ben
0 Kudos
Message 8 of 8
(4,228 Views)