Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with mbSession.Dispose()

When I exit my application, the call to dispose a message base session hung (mbSession.Dispose())

 

Can anyone help me with this problem?

Thank you,

David

0 Kudos
Message 1 of 6
(6,313 Views)

You didn't give us a lot of information to go on. Have you tried looking at/running any of the example programs for .NET Instrument Control? They might give you an idea of what you're doing wrong. They install with VISA and can be found at Start->All Programs->National Instruments->VISA->Examples.

 

This document also provides a .NET Instrument Control Tutorial. Try working through the tutorial and see if you get the same results.

 

C# and Visual Basic .NET Instrument Control Tutorial

0 Kudos
Message 2 of 6
(6,284 Views)

I've got the same issue using visual studio 2013  and .NET 4.5.

Using VisaNS version 13.0.45.167  

 

 

In my app I have a messagebox just after calling the function below. I never see the messagebox  mbSession.Dispose(); never returns

 

 public void OpenSession(string visaName)  //Opens and closes a session used for initial debug
        {
            try
            {
                mbSession = (MessageBasedSession)ResourceManager.GetLocalManager().Open(visaName);
                mbSession.Dispose();
            }
            catch (InvalidCastException)
            {
                MessageBox.Show("Resource selected must be a message-based session");
            }
            catch (Exception exp)
            {
                MessageBox.Show(exp.Message);
            }
            
        }

 

Any help would be appreciated

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

Hi tde_boiler,

 

There are a few things I can suggest for you to try:

1. Try running an instrument example program to make sure that your computer is configured correctly (as mentioned above).

2. In the tutorial, they don't have the Dispose() call inside the try / catch statement- it shouldn't make a difference, but try calling Dispose() after the try / catch.

3. You could try breaking up the line containing Open(), so that you can step through each method to see if the session is being correctly set up.

 

Thanks,

 

Andrew

 

Andrew T.
"His job is to shed light, and not to master" - Robert Hunter
0 Kudos
Message 4 of 6
(5,397 Views)

Thanks Andrew,

 

 

I appear to failing at suggestion 1.

 

the example below from NI does the exact same thing. Once I click the close button in the example program it hangs there and never exits out of the Dispose() method.

 

...\National Instruments\NI-VISA\Examples\DotNET4.5\SimpleReadWrite\cs

0 Kudos
Message 5 of 6
(5,393 Views)

And the fix is in the message board below. Root Cause. Agilent/Kesight Visa and NI-Visa do not play nice together in .NET.

 

https://forums.ni.com/t5/Instrument-Control-GPIB-Serial/NI-VISA-NET-MessageBasedSession-Dispose-Hang...

0 Kudos
Message 6 of 6
(5,391 Views)