11-18-2008 06:05 AM
Hello,
we are currently using the VisaNS .NET Library in combination with a NI PCMCIA-GPIB card in a multi-threaded C# application.
Our application requires to communicate with the same physical instrument from different threads and we use lock() statements to make sure that we don't interrupt e.g. a query from one thread by another write or query from another thread (possibly resulting in a timeout generated by that instrument).
This seems to work just fine.
As soon as a 2nd instrument is involved, we run into problems (one of the instruments uses embedded XP and generates a blue screen indicating IRQL_NOT_LESS_OR_EQUAL as soon as we continuously acquire data from both instruments).
We only use a lock() when communicating to the same instrument (from different threads). We use a different lock() for the 2nd instrument (to make sure that a query is not interrupted as explained above).
However, we do not use a common lock() for both instruments, because we assumed that NI-VISA is thread-safe when communicating with different instruments, i.e. the required low-level handshaking related to the communication with the 1st instrument is nicely completed before another thread kicks in as part of the communication with the 2nd instrument.
Given the above, can we really assume NI-VISA to be thread-safe ?
If so, how to explain the blue screen on one of the instruments ? (First we thought that there was a hardware problem with the GPIB interface of that instrument; however, intensive queries to that instrument work just fine as long as we use one thread; as such we conclude the problem is related to the multi-threaded nature of our application and possibly incorrect interpretation of the thread-safety of NI-VISA).
Any relevant comments, remarks and especially answers are very much appreciated.
11-21-2008 05:07 AM
NI-VISA indeed is thread-safe, regardless of the used OS.
What driver version are you using for the PCMCIA-GPIB? And on what OS?
11-21-2008 09:52 AM
Hello,
Just to add to what Michiel said, while the VisaNS library is thread safe, we do give the user the ability to exclusively lock a resource while it is in use. As stated in the Measurement Studio VisaNS .NET Library Overview help topic:
"... you can synchronize access to a particular VISA resource by using the LockResource and UnlockResource methods. In general, when a session has a lock on a VISA resource, no other session can access that VISA resource while the resource is locked no matter which thread or process the session resides in. This method proves useful when you need exclusive access to a device or interface."
Please let us know if this does not prove to be helpful.
NickB
National Instruments
11-23-2008 10:44 AM
Dear Nick and Michiel,
locking a resource (using the built-in VISA support) will not help because we (continuously) communicate to two different resources from different threads. When using NI-VISA as is, a blue screen is generated (intermittent problem) on an instrument which uses embedded XP as OS. When using Agilent-VISA, we found that the result of a query to one instrument was returned to the other instrument (intermittent problem).
After a colleague added a lock as provided by the C# language such that a query to one instrument can not be interrupted by (or intermixed with) a query to another instrument, the problem mentioned above disappears, both with NI-VISA and Agilent-VISA.
As such, we tend to conclude that both NI-VISA and Agilent-VISA are not thread-safe when communicating to different resources from different threads.
Although we seem to have found a solution to our problem, any feedback on what might go wrong when using NI-VISA as is, would be much appreciated.
Regards,
Frans