C#编程Unisource 4100 GPIB DMM

时间:2016-02-03 14:57:01

标签: c# visa gpib

我正在尝试从Unisource 4100 GPIB DMM读取电压测量值。我知道我可以连接到设备,因为我使用命令'* RST'和'* IDN?'获得了适当的响应,但是我无法使用其他命令获得任何响应,例如'SYST:ERR?'或'CONF:VOLT:DC 1000,0.001'。我已经在Agilent 34410A上测试了我正在尝试的代码,并设法得到我想要的响应,但没有使用Unisource 4100.我正在使用NI GPIB-USB-HS控制器进行接口。我已经包含了以下代码。 SCPI命令是否不适用于所有GPIB接口?我需要做些什么来引起Unisource 4100的响应?

我已经提供了一些代码供参考:

using System;
using System.Collections.Generic;
using System.Threading;
using System.Text;
using Ivi.Visa.Interop;


namespace CsharpExample
{
    class VoltageExample
    {

    static void Main(string[] args)
    {

        VoltageExample DmmClass = new VoltageExample(); //Create an instance of this class so we can call functions from Main


            Ivi.Visa.Interop.ResourceManager rm = new Ivi.Visa.Interop.ResourceManager(); //Open up a new resource manager
            Ivi.Visa.Interop.FormattedIO488 myDmm = new Ivi.Visa.Interop.FormattedIO488(); //Open a new Formatted IO 488 session 

        try
        {
            string DutAddr = "GPIB0::12::INSTR"; //String for GPIB

            myDmm.IO = (IMessage)rm.Open(DutAddr, AccessMode.NO_LOCK, 10000, ""); //Open up a handle to the DMM with a 2 second timeout
            //myDmm.IO.Timeout = 20000;


            myDmm.IO.Clear(); //Send a device clear first
            myDmm.WriteString("*RST", true); //Reset the device
            myDmm.WriteString("*IDN?", true); //Get the IDN string                
            string IDN = myDmm.ReadString();
            Console.WriteLine(IDN); //report the DMM's identity

            myDmm.WriteString("*TST?", true); //Get the IDN string 
            Thread.Sleep(5000);             
            string TST = myDmm.ReadString();
            Console.WriteLine(TST); //report the DMM's identity

            myDmm.WriteString("SYST:ERR?", true); //Get the IDN string    
            string ERR = myDmm.ReadString();
            Console.WriteLine(ERR); //report the DMM's identity

            myDmm.WriteString("CONF:VOLT:DC 1000, 0.001", true);
            DateTime time = DateTime.Now;  //Timer to measure the time difference to get all the readings
            TimeSpan diff;
            Console.WriteLine("Measurement in Volts");
            for(int i = 0; i<10; i++){
                //Configure for DCV 100V range, 100uV resolution
                myDmm.WriteString("READ?", true);
                String DCVResult = myDmm.ReadString();
                Console.WriteLine("DCV Reading = " + DCVResult); //report the DCV reading
                DmmClass.CheckDMMError(myDmm); //Check if the DMM has any errors
                Thread.Sleep(1000);
                diff = DateTime.Now.Subtract(time);
                //diff = DateTime.Now.Subtract(time.AddSeconds(1).AddMilliseconds(20));
                Console.WriteLine("\t\t\t" + diff);
            }

            myDmm.WriteString("CONF:RES 100, MAX", true);
            Console.WriteLine("Measurement in Ohms");
            for (int i = 0; i < 10; i++)
            {

                //Configure for res 1000 Ohm range, 100uV resolution
                myDmm.WriteString("READ?", true);
                String OHMResult = myDmm.ReadString();
                Console.WriteLine("Resistance Measurement = " + OHMResult); //report the DCV reading
                DmmClass.CheckDMMError(myDmm); //Check if the DMM has any errors
                Thread.Sleep(500);
            }


        }
        catch (Exception e)
        {
            Console.WriteLine("Error occured: " + e.Message);
        }
        finally
        {
            //Close out your resources
            try { myDmm.IO.Close(); }
            catch{}
            try{ System.Runtime.InteropServices.Marshal.ReleaseComObject(myDmm);}
            catch {}
            try{
            System.Runtime.InteropServices.Marshal.ReleaseComObject(rm);
            }
            catch {}
            Console.WriteLine("Press any key to continue...");
            Console.ReadKey();

        }

    }

0 个答案:

没有答案