Quantcast
Channel: Instrument Control (GPIB, Serial, VISA, IVI) topics
Viewing all articles
Browse latest Browse all 5661

Getting the IOSession from an IVISession that was created in a wrapped IVIC driver

$
0
0

Dear all,

 

I have created

  • a C# wrapper
  • for the IVIC driver of the 34420A Micro-Ohm Meter from Keysight (formerly Agilent)
  • using NI Measurement Studio

 

I am able to initialize the instrument using the (wrapped) init function, which returns a valid IVI Session Handle. However, as the wrapped driver does not expose full control over the underlying interface, I want to mix calls to the wrapped IVIC driver methods and "pure" Visa commands. Therefore, I would have to read the IVI_ATTR_IO_SESSION attribute from the IVI session, but I am not sure how to do this. The wrapped IVIC driver does expose the following getAttribute methods:

 

  • public static extern int GetAttributeViInt32(HandleRef instrumentHandle, string channelName, int attributeId, out int attributeValue);
  • public static extern int GetAttributeViReal64(HandleRef instrumentHandle, string channelName, int attributeId, out double attributeValue);
  • public static extern int GetAttributeViString(HandleRef instrumentHandle, string channelName, int attributeId, int arraySize, StringBuilder attributeValue);
  • public static extern int GetAttributeViBoolean(HandleRef instrumentHandle, string channelName, int attributeId, out ushort attributeValue);
  • public static extern int GetAttributeViSession(HandleRef instrumentHandle, string channelName, int attributeId, out HandleRef attributeValue);

However, calling 

GetAttributeViSession(_iviSessionHandle, "", IVI_ATTR_IO_SESSION, out visaHandleRef)

Results in a marshalling error, and calling 

GetAttributeViInt32(iviSessionHandle, "", IVI_ATTR_IO_SESSION, out visaSession);

returns 0.

  

What am I missing here?

 

 

EDIT:

 

I found a way to circumvent the Marshalling Error.

Within the C# wrapper, I added an overload of the GetAttributeViSession method that takes an IntPtr instead of a HandleRef

  • public static extern int GetAttributeViSession(HandleRef instrumentHandle, string channelName, int attributeId, out IntPtr attributeValue);

This method can be called using 

 

GetAttributeViSession(_iviSessionHandle, "", IVI_ATTR_IO_SESSION, out visaSessionPtr)

The pInvokeResult is "0", and visaSessionPtr contains a valid Int32 number. However I have not tested the functionality yet.

 


Viewing all articles
Browse latest Browse all 5661

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>