Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Visa Interop exception with C#

I'm developing a Windows console application that will talk to an Agilent DAQ via an NI IEEE-488 interface. I'm pretty sure I have the right objects in use, but when it gets to the "open" method it throws an exception. Here's a snippet of the code and the resulting error:

 

 

// attempt communications with 34980A DAQ
   Ivi.Visa.Interop.FormattedIO488 Data_Logger = new FormattedIO488();
   //create the resource manager
   ResourceManager mgr = new ResourceManager();
   string DAQ_Address = "GPIB0";
   // Try to open the device
   string option_string = "";
   Data_Logger.IO = (IMessage)mgr.Open(DAQ_Address, AccessMode.NO_LOCK, 2000, option_string); // This throws an exception

Exception: {"Unable to cast COM object of type 'System.__ComObject' to interface type 'Ivi.Visa.Interop.IMessage'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{DB8CBF05-D6D3-11D4-AA51-00A024EE30BD}' failed due to the following error: No such interface supported (0x80004002 (E_NOINTERFACE))."}

 

 

Can anyone point me to a solution? Thanks.

0 Kudos
Message 1 of 2
(417 Views)

Hi, 
Can you try using the NationalInstruments.VISA dll?

Usually it should work using NI-VISA DLL. 

Public gpibAddress As String

Public RM_VNA As NationalInstruments.Visa.ResourceManager

Public GPIBDevice_VNA As MessageBasedSession

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click



  gpibAddress = "ASRL5::INSTR"

  RM_VNA = New NationalInstruments.Visa.ResourceManager

  GPIBDevice_VNA = CType(RM_VNA.Open(gpibAddress), MessageBasedSession)

  Dim textToWrite As String = "HelloGPIB"

  GPIBDevice_VNA.RawIO.Write(textToWrite)

End Sub

The example Visual Basic code above worked on my end in sending string data using NI-VISA DLL. 

0 Kudos
Message 2 of 2
(365 Views)