Missing Data with Multiple Asynchronous VISA Read/Writes

Updated Nov 6, 2023

Reported In

Driver

  • NI-VISA

Issue Details

I have an application that is performing a single NI-VISA session open on a serial port but then goes on to performing multiple asynchronous VISA read/writes in parallel. After multiple iterations of VISA reading/writing, I notice strange behavior with my data. This strange behavior includes not receiving expected data, receiving too much data, or commands not being sent. What are some reasons this could occur?

Solution

If your application has parallel loops which are performing calls to VISA read and VISA write at different times and loop rates, you run the risk of overlap after running your program over time which can cause unexpected behavior. 

To mitigate this, you can place your calls to VISA write and read inside sub-VI's, which then you would set to be non-reentrant. In non-reentrant execution, when a VI is called as a subVI simultaneously by other VIs or the same VI, only one of those calls can enter and execute the subVI at a time.

By doing this, you ensure you won't perform a read or write at the same time another parallel loop tries to do so.
 

Additional Information

For example, let's assume you are individually addressing multiple devices on an RS232 daisy chain with a single VISA session. In your application, you have multiple parallel loops performing VISA writes followed by VISA reads. After a few iterations of your loops, you notice the data you expect to see at a certain VISA read call contains a message another loop should have received. 

This is likely due to a second loop performing a VISA read after your first loop performs a write. By placing these calls in non-reentrant sub VI's, this issue should be mitigated.

This could, however, cause longer loop execution times than expected.