LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Visa Read Error

Hello, I'm currently getting a Visa read error with my the SubVI attached. Essentially, there will be random times when this SubVI just randomly decides to quit and not work properly. I have the SubVI in a while loop connected to some push buttons on my main VI front panel. It's used with a Numato Relay to turn devices on and off. Anyone have any idea how I could resolve my issue?

 

Thanks.

image.png

0 Kudos
Message 1 of 7
(3,096 Views)

Your VI only runs one time.  I don't see any master while loop.  Is this a subVI being called from somewhere else?  IF so, don't configure the serial port or close it in the subVI.  That should be done before and after whatever master while loop is repeating this code in the main VI.

 

Why are you configuring the serial port multiple times?

Why are you writing and reading to the serial port 4 times in parallel?  It is very likely the the written commands are stomping on each other, and likewise the response.  It is possible one of the VISA reads is getting multiple responses, and another is is getting none.  And that would be why you're getting a timeout error.  How do you know each VISA read is even getting the response intended for it?

 

When you are using a serial port, your VISA Writes and Reads should be in SERIES.

 

Do your responses come with termination characters?  Your commands to write have a carriage return going out.  I think it is likely the responses would do.  If so, then enable the termination character when you configure the serial port.  Then use it.  Don't use Bytes at Port which is the wrong thing to use 99% of the time.  Set your VISA Read to be higher than the longest message you expect to get back.  Then you can kill the Time delay functions.

 

Follow these tips and your project will be more reliable and more responsive.

0 Kudos
Message 2 of 7
(3,085 Views)

This is a SubVI, so yes it runs more than once in a while loop. I'm now configuring it once outside the while loop and I'm still getting the same error. I need the Visa write inside the while loop because there are comparisons of data and if a value gets above a set upper limit, then it sends a close to the relay. I'm now getting this error instantly, instead of previously it would only happen every so often.

0 Kudos
Message 3 of 7
(3,079 Views)

Even if I run the SubVI once it gives me an error.

0 Kudos
Message 4 of 7
(3,076 Views)

It's fine to have the VISA Writes inside the loop.  Just make sure you do things in series.  Write message 1.  Read Response 1.  Write Message 2.  Read Response 2. ...

 

Write now you are writing 4 messages at once with no control over what order they get written.  Then you wait 1/10th of second at 4 different spots all in parallel, though some waits may start and end a little before the others.  Then you determine how many bytes at port are there at 4 different spots.  Some or all of the responses might have come back then.  Let's say each response is 10 bytes and they have all replied by then.  Each one of those Bytes at Port will return a 40.  Then one VISA read gets 40 bytes putting out all 4 responses.  Then another VISA Read will look for 40 bytes, but guess what, they've already been read and it will wait forever for nothing to come.  Likewise for #3 and #4.  The whole VI is one big race condition.

0 Kudos
Message 5 of 7
(3,073 Views)

Sorry the whole VISA thing is fairly new to me and this was a suggestion from someone. So what if I didn't care at all what each one read? What if I only cared about writing to each different port of the relay board? Could I in theory just have one read and have the others have no read section? I have 4 different relay switches I'd like to control that's why I have 4 different writes.

0 Kudos
Message 6 of 7
(3,067 Views)

You want to have a VISA Read.  The devices are sending back responses, so you want to make sure you read the messages so you don't fill up the receive buffer and get an error.

 

Or you could forgo the VISA Read, and periodically flush the receive buffer.

 

Don't think of it as a "VISA thing".  VISA is just the NI level of device drivers between LabVIEW and the hardware serial drivers.  Just think of it has basic serial port functionality.

0 Kudos
Message 7 of 7
(3,039 Views)