Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Multiple instance in NI-VISA

Hello, I am actually reposting this and has more detailed information regarding the problem that I am encountering.
 
In the manner of finding if the NI-VISA is suitable in our business, I have been trying to figure-out the things that it can and cannot do. I am using NI-VISA with C#.net and my two devices right now (for testing) are power supply and multimeter.
 
One requirements that we need is a multiple instance application. My 1st instance is running/functionng just fine, whenever I am running and manipulating the 2nd instance I am encountering the error {"Unable to start operation because setup is invalid (usually due to attributes being set to an inconsistent state).  VISA error code -1073807302 (0xBFFF003A), ErrorInvalidSetup"} in the write function so I am thinking that there must be something missing in my code; maybe in relation with some sharing attributes that causes the error.  Also, error occurs too even if I am accessing different device in the 2nd instance.
 
Here is the excerpt from the manual, so if my understanding what I am trying to do is achievable in NI-VISA:

Multiple Applications Using the NI-VISA Driver

Multiple-application support is an important feature in all implementations

of theNI-VISA driver.You can have several applications that useNI-VISA

running simultaneously. You can even have multiple instances of the same

application that uses the NI-VISA driver running simultaneously, if your

application is designed for this. The NI-VISA operations perform in the

same manner whether you have only one application or several applications

(or several instances of an application) all trying to use the NI-VISA driver.

However, you need to be careful when you have multiple applications or

sessions using the low-level bus access functions. The memory windows

used to access the bus are a limited resource. Call the

viMapAddress()

operation before attempting to perform low-level bus access with

viPeek

XX() or viPokeXX(). Immediately after the accesses are

completed, always call the

viUnmapAddress() operation so that you free

up the memory window for other applications.

 
 
Below is my source code:
 
below codes are inside the function set voltage:

EGpibDevice eGpibDevice = new EGpibDevice();

IEGpibDevice iEGpibDevice = (IEGpibDevice)eGpibDevice;

iEGpibDevice.Connect(txtInstrument.Text);

iEGpibDevice.Write(txtInstrument.Text,

"APPLy 9.5,1.5");

iEGpibDevice.Write(txtInstrument.Text,

"OUTPut OFF");

iEGpibDevice.Disconnect();

--------

Below is the code inside the function of Write and Connect

public void Write(string instrument, string command)

{

if (mbs != null)

{

mbs.Write(command);

}

}

 

public void Connect(string instrument)

{

try

{

if (mbs == null)

{

mbs =

new MessageBasedSession(instrument,AccessModes.NoLock,2500);

}

}

catch (InvalidCastException)

{

throw new ApplicationException("Resource selected must be a messaged-based session");

}

catch (Exception ex)

{

throw new ApplicationException(ex.Message.ToString());

}

}

 

Can someone clarify this? Thanks in advance!!!

0 Kudos
Message 1 of 2
(2,923 Views)
Please see this post for additional details and troubleshooting.
Chris R.
Applications Engineer
National Instruments
0 Kudos
Message 2 of 2
(2,889 Views)