From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

NI VISA USB disconnection events

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.

0 Kudos
Message 1 of 6
(5,963 Views)

Make sure to disable Windows turning off USB ports as power saving.

0 Kudos
Message 2 of 6
(5,955 Views)

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".

 

0 Kudos
Message 3 of 6
(5,946 Views)

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.

0 Kudos
Message 4 of 6
(5,931 Views)

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

0 Kudos
Message 5 of 6
(5,898 Views)
Max,

Why do you continue to provide LabVIEW code when the poster has repeatedly said he is using .NET?
0 Kudos
Message 6 of 6
(5,878 Views)