LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

GetAttributeViSession() and SetAttributeViSession()

What is the purpose of the IVI functions GetAttributeViSession() and SetAttributeViSession()?  By its definition, ViSession is a session handle, which cannot be set or read with any Attribute ID.  Since there aren't any defined Attributes of type ViSession, how can one use these functions?  I suppose that one could create an instrument specific attribute of type ViSession, but I can't think of a practical application for that.

 

Thanks.

0 Kudos
Message 1 of 4
(240 Views)

Hi  DanZimmermann61

GetAttributeViSession()

Retrieves a VISA session (ViSession) that is associated with a specific attribute of an IVI driver session. You can use this when you need to access the underlying VISA session to perform low-level VISA operations. For example, you can get the I/O session used by the driver.

 SetAttributeViSession()

Assigns a VISA session to a specific attribute of an IVI driver session. You can use this when you want to reuse an existing VISA session or override the default session used by the driver, f.e, setting a custom VISA session.

0 Kudos
Message 2 of 4
(204 Views)

Hi mane___avagyan,

 

I understand and thank you for your answer but can't think of a way to implement it.  Here's the prototype for the Get function:

 

GetAttributeViSession(ViSession vi, ViConstString repCapName, ViAttr attributeId, ViSession *value);

 

The first parameter is the session ID.  It doesn't make sense to query for the session ID because you have to know the session ID when the function is called.  Let's say that a test system contains three programmable instruments:  a Power Supply, DMM, and Oscilloscope.  A test program would typically call the init() function for each instrument and save the handles in global variables.  The parameter vi in the function GetAttributeViSession() is the handle to a driver session, not the handle to the Resource Manager. You call the function viOpenDefaultRM() to get the handle of the Resource Manager.

 

I don't see a way to use SetAttributeViSession because IVI doesn't define any writeable attributes of type ViSession.  The header file ivi.h only defines two attributes of type ViSession and both are read-only.  They are listed below.  I would think the driver will be disconnected from its session if one overwrites the session ID, if there is even a way to do it.

 

IVI_ATTR_VISA_RM_SESSION = 1050321

IVI_ATTR_SYSTEM_IO_SESSION = 1050322

 

I am writing a wrapper and need to validate that our wrapper works properly, including the functions SetAttributeViSession() and GetAttributeViSession() .  How can I do this?  I initialized a session to a scope and called GetAttributeViSession() for the two attributes listed above.  The driver returned error 0xBFFA000C (Attribute ID '1050321' not recognized.) for the first call and Attribute ID '1050322' not recognized. for the second call.  The first error makes sense because the scope session doesn't know anything about the Resource Manager session, plus that attribute is described as hidden in ivi.h.

 

Thanks.

0 Kudos
Message 3 of 4
(189 Views)

 DanZimmermann61

 

You noticed that IVI_ATTR_VISA_RM_SESSION and IVI_ATTR_SYSTEM_IO_SESSION They are read-only and hidden. Attempting to query them returns error. This is expected behavior because these attributes are not exposed by most IVI drivers. IVI-C drivers typically do not define any writable ViSession attributes. SetAttributeViSession() It is rarely used in practice and often unsupported by standard drivers.

So to test these functions, you can 

1. Use a custom IV Driver or Simulation Layer

If you're writing a wrapper, you could create a mock IVI driver or a simulation layer that defines a custom writable ViSession attribute. This allows you to test both SetAttributeViSession() and GetAttributeViSession() in isolation.

2. Try to use a Driver That exposes a writable ViSessionattribute.

Some non-IVI or vendor-specific drivers may expose writable session attributes. You can check the driver's header file or documentation for any #define constants of type  ViAttr that are writable and of type ViSession.

3. Use GetAttributeViSession() with IVI_ATTR_IO_SESSION

This is the most commonly supported ViSession attribute:

 

ViSession ioSession;
status = GetAttributeViSession(instrSession, IVI_ATTR_IO_SESSION, &ioSession);

 

This should return the VISA I/O session used by the driver.

You can then use viWrite() or viRead() directly on ioSession.

IVI_ATTR_IO_SESSION Is read-only. You can retrieve it, but not set it.

 

If your goal is wrapper validation, I recommend mocking the driver behavior in your wrapper test suite, simulating the presence of a writable ViSession  attribute, Verifying that your wrapper correctly calls the IVI functions and handles errors gracefully.
Also, you can use examples in the NI Example Finder.

0 Kudos
Message 4 of 4
(178 Views)