08-18-2014 07:30 AM
I am using NI VISA to control and acquire waveforms from a Tektronix oscilloscope in my application and so far everything works well but sometimes the USB connection can easily disconnect (and then connect immediately) and the MessagedBasedSession object then becomes invalid. My question is how can one setup events to know when a VISA device is connected and disconnected from an application so that these events can be captured and possibly notify the user or reconnect to the instrument. I know there are some functions such as Disable or Enable events but there are little documentation about these functions.
Thank you.
08-18-2014 01:07 PM
Make sure to disable Windows turning off USB ports as power saving.
08-19-2014 04:12 AM
Hi falopsy!
Thank you for contacting National Instruments.
From what I understand of your problem you have a Tektronix scope connected to your computer via USB and you're communicating with it with the use of the VISA drivers. When the connection drops (briefly) and reconnects again, your MessageBasedSession expires and is no longer useful. I have found a few links that I think might help:
Firstly, this method here simply detects an error; you can then notify the user of the error and ask them to reconnect.
http://forums.ni.com/t5/LabVIEW/USB-Serial-VISA-problem-when-reset-happens/m-p/1442352
You also mention VISA Events in your post, although I couldn't find a specific event for a connection drop I feel that it may still be of use:
http://zone.ni.com/reference/en-XX/help/371361J-01/lvinstio/visa_events/
Lastly, I have attached an example VI of how to detect a serial break when transmitting data serially, this may also be of use. It might also be a good idea to swap the USB cable in case this is causing the connection drop.
I hope this helps! Let me know how these go and if there's anything else I can do - Have a great day!
Max
NOTE: If the attachement fails to open, it can be found in LabVIEW under Help>>Find Examples... and searching for "detect serial break".
08-19-2014 07:13 PM
Hi msimmonds,
Thank you for your reply. I hope I haven't posted my question to the wrong forum as my application is written in .NET and will appreciate if the examples are either in C# or Visual basic. I will lootk through the links and see how I can incorporate these in my application.
Thank you.
08-22-2014 04:57 AM - edited 08-22-2014 04:57 AM
Hi falopsy,
My mistake, you have posted it in the correct forum. I would advise looking at the attached VI - This vi demonstrates how to use the .NET event callback to fire an event on a value change. This example uses a C# project file to create the event. The constructor from this project is then used to register the event. It might be useful to see how events are handled in .NET applications.
Kind Regards,
Max
08-22-2014 04:54 PM