First the pertinent details:
- VXI-11.3 Compliant ICS Electronics Model 8099 - Ethernet/MODBUS Interface controlling a Watlow F4 Temperature Controller
- NI-VISA 4.5.1 (licensed)
- CentOS Release 5.5
- TCP/IP connection to the device (direct connection with crossover cable as well as through a network - both produce similar behavior)
The connection to my device is over TCP/IP (I've tried both through my network and with a direct connection through a crossover cable - both seem to work the same).
Using the NI-VISA C library, I've written a few wrapper functions which are called from Python. Specifically, I'm using the NI-VISA functions (viOpen, viRead, viWrite, viClose), and that's it. In my Python script, I open a session to the device (without problem), and then I enter a loop which calls viWrite, waits for a response, then viRead and waits for a response, then repeats.
The problem I am seeing is that after a random number of (successful) iterations through the loop, I'll get a connection lost error (0xBFFF00A6). I can then immediately restart my script which will reestablish the connection, and things progress fine until I get another connection lost error. This led me to attempt to reestablish the connection (viOpen) each iteration through the loop, followed by a viClose at the end of the loop. This still produces the same behavior of a random number of successful iterations through the loop. Upon receiving the connection lost error, I am still able to successfully ping the TCP/IP device which leads me to believe it's not a network connection problem.
From my understanding, since I am using the synchronous viWrite, I am not writing to a write buffer, but instead directly to the device, thus there should be no need to flush any buffer contents. The same goes for my viRead calls. I am at a loss as to how to explain this behavior, so any ideas or suggestions would be greatly appreciated.
One thing that you could try would be to handle the specific error in your program. By this I mean check for the error during each iteration of your loop, and if it occurs, do a viClose and then a viOpen on the device. The close before the open will make sure that the connection isn't still lingering, before attempting to re-open it. The lost connection could happen for a number of reasons, such as a hiccup on the TCP connection. You are likely still able to ping the device because the TCP port is still open, but the VISA session may have failed. Try the above solution and see if you continue to have issues.