Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

How to close GPIB VISA session in VisaTask.mxb ?

Hello,

 

We are streaming data from an Agilent oscilloscope via GPIB VISA using VS 2008 C# and MS 8.6.1 .  We are generating the relevant C# code automatically with the MS VisaTask.mxb utility.  At the moment we are opening the VISA session with the scope at the beginning of the VisaTask.mxb worksheet, and then we do not close it explicitly.  The code runs for a little while and then crashes with a VISA error, probably because we keep telling the VISA session to (re)open, and nothing ever closes it.  So we have two questions:

 

1.  How can we close the VISA session explicitly within the VisaTask.mxb?

 

2.  Is it possible to both open and close the VISA session someplace else, other than in the VisaTask.mxb?  It would probably speed up our data acquisition to open and close the VISA session just one time, instead of having to open and close every time we want to grab a scope trace.

 

Thanks in advance for any thoughts!

 

Best regards,

Penny

 

0 Kudos
Message 1 of 7
(4,754 Views)

Hello Penny,

 

Thanks for posting!  My name is Shawn.  Would you mind sending me a screen shot of the error you are experiencing? I was able to find the a VisaTask.mxb file on my machine from an exercise (5-2) from a Measurement Studio for .NET course.  Is this the same VisaTask.mxb file you are referring to?  I'll research this further while I wait for your response. 

Regards,

Shawn S. | NIC
Instrument Driver/IVI PSE
National Instruments
0 Kudos
Message 2 of 7
(4,745 Views)

Hi Shawn,

 

Thanks for replying.  I don't have a copy of the error message right now as it takes a little while to produce it and comes at unpredictable times.  However the error has the word "VISA" in it and the VS debugger points to this line in the VisaTask.mxb-generated VisaTask.cs code:  "_instrumentSession.TerminationCharacterEnabled = false" .  So I have started to suspect that something is wrong with my VISA communication.  Then, after further inspection I have noticed that my VISA session is never being closed anywhere in the code.

 

I am just wondering how I can close that GPIB VISA session, whether it will help with my error message or not.  If I "Add Step" to my VisaTask.mxb worksheet, I can either make the new step a "Read", "Write", or "Query and Parse".  If I "Write" a command to the oscilloscope, it has to be in the IEEE programming language, which as far as I know does not allow for closing GPIB VISA sessions.

 

Do you happen to have a link to that course you mentioned?  Maybe it would help to go back through the examples.

 

Thanks again,

Penny

 

0 Kudos
Message 3 of 7
(4,739 Views)

Hi Shawn,

The attached NI document describes a 'walk through' starting on page 2-50.  This is similar to what we are doing.  Even in the 'walk-through', there don't seem to be any explicit instructions on how to close the VISA session.   Maybe it is supposed to happen someplace else, outside of the VisaTask(.mxb,.cs)?   Any thoughts would be great.  Thanks!

Regards,

Penny

 

0 Kudos
Message 4 of 7
(4,736 Views)

Hi Shawn,

We did find a screenshot of one of our crashes.  It doesn't have the NI error number, but does show where the VS debugger is highlighting the VISA communication inside the automatically generated VisaTask.cs code.

Thanks,

Penny

 

0 Kudos
Message 5 of 7
(4,728 Views)

Hello,

 

Have you done research on the following error (from your screen shot ErrorJune09238pm.jpg):

 

AJAX.jpg

 

 

I found the following article and would try its suggestions to get a more clear error message.

 

Exception has been thrown by the target of an invocation

http://forums.asp.net/t/1070216.aspx/1?Exception+has+been+thrown+by+the+target+of+an+invocation

Regards,

Shawn S. | NIC
Instrument Driver/IVI PSE
National Instruments
0 Kudos
Message 6 of 7
(4,710 Views)

Hi Shawn,

Thanks for the link.  In the meantime we have figured out how to close the VISA session - the default instance of VisaTask has a Dispose() routine that takes care of it.  We are not sure if this will stop our crashes, but it does answer the question about closing the session.

Best regards,

Penny

 

0 Kudos
Message 7 of 7
(4,703 Views)