Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

GpibSession VISA problems

Hey all,

I'm using C# and importing the following DLLs:

NationalInstruments.Common

NationalInstruments.NI4882

NationalInstruments.VisaNS

 

I have a pretty complex system setup with about 7 different pieces of instrumentation on teh GPIB bus, and a lod of serial devices.  

I have a function called VisaSend()

 

Everytime this function gets called, which is very frequently, I perform the following:

 

void VisaSend(string devAddr, string cmd); 

{

   GpibSession gpib = null;

   gpib = new GpibSession(devAddr);

   gpib.Timeout = 3000; // 3 sec timeout

   gpib.Write(cmd);

   Thread.Sleep(55); // let the command simma'

 

  // dispose of the session 

   (MessageBasedSession)(gpib).~MessageBasedSession();

 }

 

Now, my system will run for hours and hours, but at some point during the night I will get the error:

 

System.ArgumentException: The given session or object reference is invalid.  

VISA error code -1073807346 (0xBFFF000E), ErrorInvalidObject --->

NationalInstruments.VisaNS.VisaException: The given session or object reference is invalid.  

VISA error code -1073807346 (0xBFFF000E), ErrorInvalidObject 

 

 

The bad news is that it happens on random commands, and after random amounts of time.

The good news is, that it seems to be happening on the same device (HP 89441A VSA).

But I serously send it about 2000 different GPIB commands, and it seems fine...I just don't know why

it chokes, and chokes so hard.

 

My first suspision is that creating and destroying so many GpibSessions may be taking it's toll on the .NET garbage collector.

I don't know.  Its so hard to debug when it happens as randomly as this does.

 

Does anyone have any suggestions?

0 Kudos
Message 1 of 2
(1,327 Views)

Howdy Nick,

 

This sounds like it could be caused by some corner/race condition in your code.  While that might normally be impossible to track down, we have a great program that allows you to log all of the commands across the GPIB bus for later analysis called NI-Spy (see how to use it here).  Try using that to analyze the commands and post the file to the forums for us to take a look at.  We can see if there is anything surrounding the bad command that looks funny.  I look forward to hearing back from you.

Sincerely,

Chris G in AE
0 Kudos
Message 2 of 2
(1,299 Views)