LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

VISA timeout error on periodical communications

I have a VI which communicates with a USB instrument with VISA. First we send a "get status" message and wait for the response and the immediately send a "get error" message which returns a number and a string if the instrument is in an error. This is running in a while loop with a static wait of 250ms between the iterations. The VISA timeout is set to 500ms.

 

We are not worried too much about a timeout, we said if there is a timeout then repeat the operation max 3 time or until no timeout like below. Before say that this implementation makes no sense pls note that this is simplified just to show how the retry mechanism is implemented:

 

1984_1-1710413342565.png

 

Still from time to time I get an error message "-1073807339,"Message":"VISA: (Hex 0xBFFF0015) Timeout expired before operation completed."

 

There are no concurrent communication to the instruments. The communication is implemented like this, the wait for response is always set to true:

 

snip.png

Any ideas what could cause a timeout on the instrument? I'm quite lost, because the code is very simple and there are plenty of time between the messages.


Thanks.

0 Kudos
Message 1 of 19
(1,017 Views)

I have never needed to use the VISA Events.  And the Clear Buffers is another major red flag to me.  All you should need to do is do the VISA Write and then a VISA Read, letting the timeout work on the VISA Read.  Do not use the Bytes At Port when doing this:  just try to read more data than you expect in a response.

 

I would also recommend increasing your timeout.  It is not uncommon for devices (especially older ones) to freeze before sending out a response.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 2 of 19
(977 Views)

So my thinking process during writing the VI was this:

 

After getting the VISA refnum I flush whatever is on the bus because if previously I sent a command to the instrument but for whatever reasons I either didnt or couldnt read its response BUT the response has arrived then sending another command and then reading the response will have the response of the previous command as well. So flushing is a mechanism, I assume. Is this assumption incorrect?

 

Before I respond to the VISA event part... lets assume the instrument returns only 1 byte plus a \n termination char after 5ms. If set the VISA read to read 1000 bytes with a 1000ms timeout whats gonna be the execution time of the VISA read and what will be on the outputs? I can't test this at the moment because I dont have any instruments around me, but you might know it by heart.

 

thanks.

0 Kudos
Message 3 of 19
(970 Views)

Hi 1984,

 


@1984 wrote:

lets assume the instrument returns only 1 byte plus a \n termination char after 5ms. If set the VISA read to read 1000 bytes with a 1000ms timeout whats gonna be the execution time of the VISA read and what will be on the outputs? I can't test this at the moment because I dont have any instruments around me, but you might know it by heart.


VISARead stops for those conditions:

  • the requested number of bytes has been received
  • the timeout has been reached
  • the TermChar as configured has been received
  • an error within the driver of the communication port occurs (rather uncommon?)

For your question the 3rd item applies…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 4 of 19
(965 Views)

You are using a lot of things that normally are not used in serial communications like "bytes at port", VISA Flush Buffer, and VISA Discard events.

 

Most serial communication issues can be solved by watching this video: VIWeek 2020/Proper way to communicate over serial

 

 

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 5 of 19
(963 Views)

I see, thanks! In this case the VISA event is really not necessary, I can just try reading 1000 (or whatever) bytes an I'll be good.

 

I love the idea of this VISA event, but if you guys are saying that this fishy then I can remove that, no problem. I still think that the flush is necessary for the reason above. Any thoughts on that?

0 Kudos
Message 6 of 19
(960 Views)

Hi 1984,

 


@1984 wrote:

I still think that the flush is necessary for the reason above. Any thoughts on that?


When you send a command to your device then you should also read the expected answer!

What's the point of sending commands when you don't need/handle their answer???

 

I see only one reason for Flush: when you start communication with a device that sends data without request then it helps to flush the buffer to get rid of data garbage received between "start" and "first read"…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 7 of 19
(944 Views)


When you send a command to your device then you should also read the expected answer!

What's the point of sending commands when you don't need/handle their answer???

 

I understand that you dont use the flush which is alright with me, but it just a habbit or is there something wrong with it?

 

I find overusing question marks marks pretty condesending.

0 Kudos
Message 8 of 19
(933 Views)

@GerdW wrote:

I see only one reason for Flush: when you start communication with a device that sends data without request then it helps to flush the buffer to get rid of data garbage received between "start" and "first read"…


For ASCII protocols, I just do a read when I initialize the port.  The data from this read is thrown away, but it ensures the following reads are synched up, getting the full message.  Flush is not needed.

 

In the OP's situation, with the assumption the device only responds to requests (ie does not randomly send messages on its own), I can understand using the Flush before writing to make sure any previous unread response does not affect the current message and response.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 9 of 19
(924 Views)

Sorry for getting back pretty late on the subject there we other - non sw related - issues which had to be solved by our customer.

 

I modified the code per the suggestions. The only exception is that I kept using the visa flush before writing anything (see the snippet). 

visa.png

 

As mentioned before if the operation fails I repeat the it couple times before we say that we really have a problem.

 

It was not mentioned before but I use this VI to communicate with a GPT-9803 HIPOT tester instrument via USB. During the test we ramp up the voltage to couple kV (DC), then keep it steady for couple sec and finish the test. The instrument will respond to our query with a string indicating the current voltage, the current test time, a test in progress flag and a Pass/Fail flag. The instrument controls this porcess on its own, so losing the connection doesnt mean it will not shut the test down properly.

 

Once I also introduced pretty detailed logging of whats happened and I have found the followings:

 

  1. The communication is either OK so there is no retry at all, or it fails all the time
  2. When the problem occurs it exclusively occurs at the very end of the test. From logging the response from the instrument I see that the voltage increases and right at 0.1s before the test is completed the communication is lost.

Once fails the log shows the following:

1984_0-1712149321797.png

 

Notice that the steps follow each other in every ~10s. This is interesting as when I initialize the instrument I explicitly sets the timeout to 500ms. 

 

At this point I assume that the problem is not really the VI itself but something happens right when the instrument starts discharging. This is not confirmed at all, but it would explain why we see the problem at the end of the process everytime.

 

Also - and give me some hints here - I assume that this would explain the 10s timeout. 10s is the default timeout for VISA operations and I guess if something bad happens and the the communication is dropped then once I try to flush or write to the VISA resource the default settings are applied again.

 

Any ideas are welcomed.

 

 

 

 

0 Kudos
Message 10 of 19
(751 Views)