Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

Serial Timeout

Hi. I am using LV8.2 to monitor a serial data from a magnetic compass sensor. I used the VISA Configure Serial Port, VISA Write and VISA Read function to communicate to the sensor. Between VISA Write and Read function I placed a Property Node to set millisecond timeout. Kindly see the attached VI.
If i set the timeout for instance to 400ms, I can get a good steady value but it is a "delayed data". "Delayed" I meant is even i moved the compass, the data being read lags behind.
On the otherhand, If i set the timeout for instance to 200ms, once i move the compass, the data being read is close to real time as i move the compass. But the problem on this case is sometimes i get random values (not steady).
Is there a way I can improve my VI?
I want to get a fast response and a steady output data from the sensor.
Thanks a lot for any advise.
 
Best regards,
0 Kudos
Message 1 of 14
(5,364 Views)

Hi,

I would suggest you to try out setting the Timeout before the Visa Write Function. See the attached Serial.jpeg file for the same. Hope this will help u.

Please let me know, if the solution works out for u.

Regards,

Alifiya

 

0 Kudos
Message 2 of 14
(5,330 Views)
Since a timeout of 400ms produces steady data and the 200ms produces some random values, my guess is that every once in a while the compass takes longer that 200mS to reply and a timeout occurs.  Have you taken a closer look at your random values?  My guess is that the VISA Read is generating an error at the same time.  The trick is to modify your vi to capture and log any errors from the VISA Read without using highlight execution.  It slows things down so much the error would never happen.
 
It looks like you are sending a command to the compass and then reading the reply.  Does the compass documentation spec how long it will take it to reply?  Does the compass have a mode where it streams data?  That would give the the live feel you are looking for.
 
 
0 Kudos
Message 3 of 14
(5,328 Views)

Hi Alif and Centerbolt,

Thank you for your kind reply. Attached are the variations i made for the Timeout Property Node function. But i do get the same result. If i set to more than 300msec i get a steady value but lags a little behind, but if i put timeout to 200 msec, i get a faster data and sometimes randomly wobbles. By the way, i would like to add that whichever time 200 or 400msec, i get an Error message, -1073807339!

It looks like you are sending a command to the compass and then reading the reply. 

>>>Yes. I am sending a command to the sensor and actually reading the reply.

Does the compass documentation spec how long it will take it to reply? 

>>> There is no spec on how long it will take to reply in its documentation. But i sent an inquiry to the maker.

Does the compass have a mode where it streams data? 

>>> Yes. If i send the command "go", it will just give all the compass data continuously.

Thanks a lot.

0 Kudos
Message 4 of 14
(5,284 Views)

Hi,

You can try using the following steps to debug serial timeout errors(Error code 1073807339):

  1. Verify that all the serial settings are correct (for example, baud rate, data bits, and stop bits). The device and the serial port must have the same settings.

  2. Try increasing the VISA session timeout value.  This error often occurs when you are reading or writing large amounts of data and it takes longer than the default timeout to send or receive the data.
    I would like to suggest to find out the Timeout value of your compass. Also, u need to make sure about the delay in the while loop.
    E.g. say your device timeout = 200ms then your while loop delay should be greater than 200ms otherwise there will be timing issues.

    3. If you are experiencing this error for a VISA Read, verify that you are not trying to read too many bytes. Read only 1 byte at a time while debugging.

Note: If you do not get the error now, increment the number of bytes you read until you get the timeout error again. This tells you how many bytes that command sends back.

You can also use a Property Node to read the Number of Bytes at the Serial Port. Right-click the Property Node and select Select VISA Class»I/O Session»Serial Instr. Then right-click the Property Node and select Properties»Serial Setttings»Number of Bytes at Serial Port.

    4. If you still receive the error while reading only 1 byte, verify the command to make sure it has been written correctly.

Note: Verify that you have terminated the command string correctly. A new line or carriage return is often required at the end of a command. A good way to test this in LabVIEW is to right-click the command string control on the front panel and change the display to '\' Codes Display mode. In this mode, a carriage return is \r, a line feed is \n, and an end of line is \r\n. Verify that the command being sent to the serial device has the termination character that the device requires.


Hope this will Help u.

Regards,

Alif

0 Kudos
Message 5 of 14
(5,272 Views)
Hi,
 
I was just having a closure look at your code and found that u r not clearing the TX & RX buffer between two data reads. If you are not going to clear the buffer, then the next incoming data will mingle up with the existing data thereby resulting in a garbage data. Therefore,I would strongly suggest you to flush the Transmit and Recieve buffer IO buffer between two consecutive data reads. Because I used to face the same problem in my application. 
 
U can c the attached serial. JPG to know how I have used the Flush Io Buffer before VISA Write function to flush the recieve buffer and After VISA Read Function to Flush the Transmit buffer.
 
I believe this will definitely solve ur problem. Plz revert back if u have any problems. Also, plz let me know if dis solution solves ur problem.
 
Regards,
Alif
 
0 Kudos
Message 6 of 14
(5,274 Views)
Just hold up a minute. Changing the timeout will not make a read go faster or slower. Changing the timeout will only change the speed with which you will get the timeout error. Repeatedly flushing the buffers will not fix things either, imho. That will just remove unread characters and I think you want to read everything the instrument is sending. Let me try to explain how VISA handles serial communication and what causes timeout errors. There is a setting on the VISA Configure Serial Port for enabling the termination character. This is used when the instrument appends a termination character (i.e. a CR of LF) at the end of the data it is transmitting. With a termination character, you can specify a large number of bytes to read because the VISA read will automatically terminate when the term character is detected. The VISA read will take as long to read the response as is required for the instrument to send a complete packet of data. Shortening the VISA timeout to a time less than the amount it requires for the instrument to send the packet will just result in truncated data and an error. If the instrument does not append a termination character, then the setting in VISA Configure Serial Port should be set to false. The problem then is how to determine exactly how many bytes to read. There is a function called VISA Bytes at Serial Port. This returns the number of bytes in the buffer. You can place this function in a while loop and when the number of available bytes is greater than zero, exit that loop, passing the number of bytes to another loop through a shift register. In the second loop, you do a VISA Read of that number of bytes and then another VISA Bytes at Serial Port. With this loop, you exit when the nunmber of available bytes is zero. Wire the result of the VISA Read to a concatanate string function that is wired to a different shift register.
0 Kudos
Message 7 of 14
(5,266 Views)

Dennis,

I would like to comment on the solution u suggested. As per ur suggestion (There is a function called VISA Bytes at Serial Port. This returns the number of bytes in the buffer. You can place this function in a while loop and when the number of available bytes is greater than zero, exit that loop, passing the number of bytes to another loop through a shift register. In the second loop, you do a VISA Read of that number of bytes and then another VISA Bytes at Serial Port. With this loop, you exit when the nunmber of available bytes is zero. Wire the result of the VISA Read to a concatanate string function that is wired to a different shift register. ), he would exit the while loop even the correct/desired no. of bytes r not recieved at the port. I mean at times there will be a case of garbled communication, where the no of bytes recieved will be > 0 but less than/ greater than the desired no. of bytes. This will result in garbage data.

Regards,

Alif

0 Kudos
Message 8 of 14
(5,260 Views)
Nonsense. The instrument sends one packet of data for each request sent with the VISA Write. As already stated, the instrument is not in continuous send mode and you want to read all bytes that the instrument sends.
Message 9 of 14
(5,256 Views)
Before communicating in a mannerless way, I think u should have a look at the read_timeout.xls file from jtc where the sensor data is read continuously using a while loop. Although a single request for read will transmit the entire data packet. But then he  is going to read the packets repeatedly and that is why I commented on ur solution, becoz I have faced the same problem when I was developing an application. I strongly believe that I m correct and it does make sense.
 
 
I believe this forum is for exchanging ideas , helping each other to find a solution to their problems and not for commenting rudely on anyones suggestion.
 
 
Sometimes you need to listen to the whole story before you interrupt!!!!!
0 Kudos
Message 10 of 14
(5,247 Views)