C# Visual Studio GPIB Commands

后端 未结 5 756
醉梦人生
醉梦人生 2021-01-05 14:10

What commands do you use to talk to a GPIB instrument in C#, visual studio? I need to be able to write commands to the instrument and read the output.

5条回答
  •  没有蜡笔的小新
    2021-01-05 14:45

    I'm using National Instruments VISA and NI 488.2.

    First make sure that you checked the VisaNS.NET API in the NI-VISA Setup, see the following figure:

    Add a reference to NationalInstruments.VisaNS and NationalInstruments.Common to your project.

    Create a MessageBasedSession, see the following code:

    string resourceName = "GPIB0::20::INSTR"; // GPIB adapter 0, Instrument address 20
    var visa = new NationalInstruments.VisaNS.MessageBasedSession(resourceName);
    visa.Write("*IDN?"); // write to instrument
    string res = visa.ReadString(); // read from instrument
    

    A MessageBasedSession can be used to communicate with your instrument over GPIB, Ethernet or USB.

    Update

    Ivi.Visa superseded NationalInstruments.VisaNS. So you should add a reference only to Ivi.Visa to your project.

    The example would look like that:

    string resourceName = "GPIB0::20::INSTR"; // GPIB adapter 0, Instrument address 20
    var visa = GlobalResourceManager.Open(resourceName) as IMessageBasedSession;
    visa.RawIO.Write("*IDN?\n"); // write to instrument
    string res = visa.RawIO.ReadString(); // read from instrument
    

    The benefit of using Ivi.Visa is that it works with one of the following libraries:

    • National Instruments VISA
    • Keysight IO Libraries Suite
    • Rohde & Schwarz VISA

提交回复
热议问题