LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

serial timeout on first iteration

I am doing serial communication with the USB to RS-485 NI box.  I first write a command to my instrument and then try to read back a fixed amount of data.  The first time the VI goes through the loop where the read and write take place, I immediately get a timeout error (Error -1073807339).  On consecutive iterations of the loop, no errors are reported.
 
My guess is that all the data is not getting written to the port before I try to read it back.  But with the timeout set at 10 seconds, why would the read function not wait 10 seconds to see if the rest of the data I have requested shows up?
 
Thanks for your help,
Michelle
0 Kudos
Message 1 of 9
(3,856 Views)
Hi Michelle,
 
I use USB - RS-232 box (not from NI) without any problem. Can you post your VI  so I can try them on my PC to see if I can reproduce (or not) this error.
0 Kudos
Message 2 of 9
(3,834 Views)
If you can't post your VI, can you post a SPY capture?
 
Logan S.
0 Kudos
Message 3 of 9
(3,816 Views)
I'll see what I can do because my VI's a little large...  I'll try to post just the part of the code pertaining to RS422!
0 Kudos
Message 4 of 9
(3,809 Views)

Hi Michelle,

It is often related to the end-of-line character ( '\n' vs '\r\n' ), where there is a mismatch between the amount of bytes being reported as available and the actual length of the data that is available.  If this is the case, you may be trying to read a string (let's say 8 bytes) with an end of line character (\r\n) being counted as 2 bytes, giving you a total of 10 reported bytes.  But when you read it, there are only 9 bytes available.  So giving more time will not solve this (one trick is to read 1 less byte... as an experiment ONLY).   The solution would be to fix the source which reports the string length....

However, you are saying that you see this with an instrument?  Do you mean a test instrument?  ( if so, that would be strange).

Have you tried using MAX (Measurement and Automation Explorer) to communicate with your instrument using *IDN? command?
It will also provide you Instrument model plus serial number in text string also with number of bytes returned.

Ray

Message 5 of 9
(3,808 Views)

I'm actually reading back 60 bytes of information from a third party board.  I request status from the board, and then "bytes at port" is reported as 0 and the read operation times out.  On the next iteration of the loop, 60 bytes are available, so they are read back.

Even though 0 bytes are available originally, shouldn't the read VI wait until the timeout (10 seconds) before reporting a timeout?  Is it possible that the read VI is executed before the write VI completely finishes?

0 Kudos
Message 6 of 9
(3,802 Views)
Michelle,

Why are you attempting a read if the Bytes at Port reports 0? If Bytes at Port is zero, do not read, else read the number of bytes actually available. This should avoid all timeouts. You may need to implement you own timeout in the event the device is not active and bytes at port remains zero indefinitely.

Lynn
0 Kudos
Message 7 of 9
(3,796 Views)
Lynn,
Sounds pretty silly to try to read if there's nothing there...
 
I guess I was hoping that the read VI would wait for 10 seconds before giving up reading, during which time I expect that the 60 bytes I want to read should show up...  Maybe this is futile thinking?
 
Thanks,
Michelle
0 Kudos
Message 8 of 9
(3,789 Views)

Hi Michelle,

LOL!!  😄  I have to agree with Lynn.  You should never attempt to read more bytes than are available.  So for 0 bytes, you should not read anything.  I am not sure why it timesout before the 10 seconds, but it may depend on how your read serial port is configured (if my memory is ok -- early morning ).

Reading what may show up in the serial buffer may (or actually will) lead to strange and unexpected behavior.  It is better to create a loop for 10 seconds that reads the contents of the serial port based on the number of bytes available, and append to the same string (within that loop).  This means that you start with an empty string, read any data available for a given amount of time (and up until it is empty), then pass what was read at the output of the loop.  This may do what you attempted to achieve, without timing out.  😉

Ray

Message Edited by JoeLabView on 11-22-2005 08:18 AM

Message 9 of 9
(3,777 Views)