Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Multiple instance accessing one device

Hi - I am trying to launch 2 instance of my application by accessing one device. The first instance of my application is running just fine but when I tried sending command from my 2nd instance it is throwing me an error message of "Unable to start operation because setup is invalid(usually due to attributes being set to an inconsistent state). VISA error code -1073807302". I don't understand why it is throwing me that error; I am disposing my MessagedBasedSession after I send commands to the device. Can you tell me why?
 
Also, is it a good practice to close/dispose the messagedbasedsession once the command has been sent to the device?
 
Thanks!
0 Kudos
Message 1 of 14
(5,337 Views)

mbd

I am not so sure how do you control the instr, but there is some related stuff about the operation procedure http://digital.ni.com/public.nsf/3efedde4322fef19862567740067f3cc/c90d20f3a89871c2862569970073d282?O... , I do not think it is very good to dispose the resource after an action, if it is a long process control, you can keep handle the session for a long time, I do not know why you need to use two applications (instance) to communicate to a single instr.

I met several threads about this error, most of them were solved by update the VISA version, http://forums.ni.com/ni/board/message?board.id=170&message.id=85017&requireLogin=False

帖子被paulbin在09-02-2007 09:51 PM时编辑过了

********************************
*The best Chinese farmer*
********************************
0 Kudos
Message 2 of 14
(5,328 Views)
Hi mbd,

What type of instrument are you using?  You can only have one session open to an instrument at a time, otherwise you'll get an error, as you are seeing. 

Thanks,

Meghan
Applications Engineer
0 Kudos
Message 3 of 14
(5,307 Views)
Hi guys - Thanks for the reply. Please see below for my response.
 
Hi Meghan - I am trying to access the power supply using the NI-VISA in my c#.net code. Do you know any documentation that it says they are not allowing multiple session?
 
Hi Paulbon -  The link that you gave me is for labview. Does it work the same in NI-VISA referenced in C#.net code? Also, when I said disposing it means I want to close it to give way if there is another instance that has been called. I am just thinking this in how I managed a database server where you dont want your connection to be always opened. You can correct me if Im wrong if this is not the same case.
0 Kudos
Message 4 of 14
(5,300 Views)
Hi Meghan - Below is the excerpt I found in the NI-VISA manual. With the below statement, I think it is capable doing the multiple instances. The question is how? Anyone?
 

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.

0 Kudos
Message 5 of 14
(5,298 Views)
Hi mbd,

I think I may not have been clear.  When I said that you can only open one VISA session to an instrument at a time, I mean that you can open only one session per instrument.  You can open multiple sessions if you're using multiple instruments.

Thanks,

Meghan
Applications Engineer
0 Kudos
Message 6 of 14
(5,245 Views)
Oh ok.. That is pretty clear and I tried that and it is working.
 
 
My question is if I have 2 application or instance and with each instance I have 1 session, why am I getting an error? Even though I  closed the session in the first instance.
I am also getting an error even if my second instance is accessing different instrument.
 
Thanks for reply Meghan R!
 
 

Message Edited by mbd on 09-10-2007 02:08 PM

0 Kudos
Message 7 of 14
(5,241 Views)

Hi,

This problem seems to get more and more ambiguous. You have not made it very clear as to what your program does and how you are trying to control your instruments. Please see the following links, hopefully one of these will imply to your application, if not, then please write back with more details about program.

http://digital.ni.com/public.nsf/allkb/DDE6A6A773A4B1DC86256BC0005C8A8F?OpenDocument

http://digital.ni.com/public.nsf/allkb/D2084EC381319CC386256A1D006F1415?OpenDocument

http://forums.ni.com/ni/board/message?board.id=170&message.id=194794&requireLogin=False

Can you also try running NI-Spy to see what error messages it records.

Thanks,

Arjun K

National Instruments
Applications Engineer
0 Kudos
Message 8 of 14
(5,226 Views)
Thanks for the reply Arjun!
 
Below is my other posting regarding this matter. Please let me know if you need more information.
 
----
 
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/functioning just fine, but 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());

}

}

 

0 Kudos
Message 9 of 14
(5,219 Views)
Hi,
Looking at your code it really can't be said if your configuration is correct and if you are using the low level driver calls. Probably the parameters you are setting or the resource address you are providing are incorrect. Is it possible for you to try and run the two instances independently and see if it works without errors. Is there a specific reason why you need to have multiple instances running?
National Instruments
Applications Engineer
0 Kudos
Message 10 of 14
(5,208 Views)