06-08-2017 01:37 AM - edited 06-08-2017 01:48 AM
Dear all,
I have created
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:
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
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.
06-08-2017 03:06 AM
The EDIT above seems to solve the problem. I have succesfully tested it by:
The problem could be solved as follows:
The NI Wrapper Genreator uses a wrong datataype for an IVI Attribute getter in the generated IVIC wrapper:
public static extern int GetAttributeViSession(HandleRef instrumentHandle, string channelName, int attributeId, out HandleRef attributeValue);
should be (you can add it as another overload):
public static extern int GetAttributeViSession(HandleRef instrumentHandle, string channelName, int attributeId, out IntPtr attributeValue);
This overload can be used to get the IoSession after the IviSessionHandle has been created using the wrapped Init method as follows:
IntPtr visaSessionPtr;
GetAttributeViSession(_iviSessionHandle, "", IVI_ATTR_IO_SESSION, out visaSessionPtr);
Afterwards you can of course create a VisaSessionHandle in a HandleRef.