コード例 #1
0
ファイル: SCPIConf.cs プロジェクト: HanRD/SCPI-Device-Control
 public void SendSCPIcommand(string str, string device)
 {
     rm    = new Ivi.Visa.Interop.ResourceManagerClass();
     ioobj = new Ivi.Visa.Interop.FormattedIO488Class();
     try
     {
         ioobj.IO = (Ivi.Visa.Interop.IMessage)rm.Open(device, Ivi.Visa.Interop.AccessMode.NO_LOCK, 50, "");//在这里输入设备地址
         ioobj.WriteString(str, true);
     }
     catch (Exception e)
     {
         Console.WriteLine("An error occurred: " + e.Message);
     }
     finally
     {
         try
         {
             Console.WriteLine("Session Ended");
             ioobj.IO.Close();
         }
         catch { }
         try
         {
             System.Runtime.InteropServices.Marshal.ReleaseComObject(ioobj);
         }
         catch { }
         try
         {
             System.Runtime.InteropServices.Marshal.ReleaseComObject(rm);
         }
         catch { }
     }
 }
コード例 #2
0
ファイル: SCPIConf.cs プロジェクト: HanRD/SCPI-Device-Control
        //搜索可用设备
        private List <string> SearchConnectedDevice(string port)
        {
            rm    = new Ivi.Visa.Interop.ResourceManagerClass();
            ioobj = new Ivi.Visa.Interop.FormattedIO488Class();
            selectabledevicelist = new List <string>();
            string[] availabledevice;
            string[] deviceInfList;
            try
            {
                availabledevice = (string[])rm.FindRsrc(port + "?*INSTR");
                if (availabledevice.Length > 0)
                {
                    foreach (string addr in availabledevice)
                    {
                        try
                        {
                            ioobj.IO = (Ivi.Visa.Interop.IMessage)rm.Open(addr, Ivi.Visa.Interop.AccessMode.NO_LOCK, 50, "");
                            ioobj.WriteString("*IDN?");
                            deviceInfList = (string[])ioobj.ReadList(Ivi.Visa.Interop.IEEEASCIIType.ASCIIType_Any, ",");
                            string deviceinf = deviceInfList[0] + "," + deviceInfList[1];
                            selectabledevicelist.Add(deviceinf);
                        }
                        catch (Exception)
                        {
                            throw;
                        }
                    }
                }
                else
                {
                    //备选设备列表置空,提示未搜索到设备

                    MessageBox.Show("没有搜索到可用设备,请确认设备连接状态", "未搜索到设备");
                }
                return(selectabledevicelist);
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                try
                {
                    Console.WriteLine("Session Ended");
                    ioobj.IO.Close();
                }
                catch { }
                try
                {
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(ioobj);
                }
                catch { }
                try
                {
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(rm);
                }
                catch { }
            }
        }
コード例 #3
0
 private void FindAvailableInstrument()
 {
     Ivi.Visa.Interop.ResourceManagerClass rm = new Ivi.Visa.Interop.ResourceManagerClass();
     try
     {
         object[] idnItems;
         string[] availabledevice;
         deviceDict = new Dictionary <string, string>();
         comboBox1.Items.Clear();
         List <string> ConnectedDeviceList = new List <string>();
         availabledevice = (string[])rm.FindRsrc("USB?*INSTR");
         if (availabledevice.Length > 0)
         {
             foreach (string item in availabledevice)
             {
                 string devicedetail = scpiconf.SendSCPICommandAndReadString("*IDN?", item);
                 if (devicedetail != "error")
                 {
                     Console.Out.WriteLine(devicedetail);
                     string[] detailtips = devicedetail.Split(',');
                     string   devicedesc = detailtips[0] + detailtips[1];
                     if (!deviceDict.ContainsKey(devicedesc))
                     {
                         comboBox1.Items.Add(devicedesc);
                         deviceDict.Add(devicedesc, item);
                     }
                     else
                     {
                     }
                 }
             }
             MessageBox.Show("搜索到" + deviceDict.Count + "个可用设备", "搜索到设备");
         }
         else
         {
             MessageBox.Show("没有搜索到可用设备,请确认设备连接状态", "未搜索到设备");
         }
     }
     catch (Exception e)
     {
         MessageBox.Show("没有搜索到可用设备,请确认设备连接状态", "未搜索到设备");
         Console.WriteLine("An error has occured:" + e.Data);
         throw;
     }
     finally
     {
         try
         {
             Console.WriteLine("Session Ended");
             ioobj.IO.Close();
         }
         catch { }
         try
         {
             System.Runtime.InteropServices.Marshal.ReleaseComObject(rm);
         }
         catch { }
     }
 }
コード例 #4
0
        public VNAInterface(string GPIBConnectionString)
        {
            this.GPIBConnectionString = GPIBConnectionString;
            rm = new Ivi.Visa.Interop.ResourceManagerClass();
            io = new Ivi.Visa.Interop.FormattedIO488Class();

            try
            {
                // connect to the VNA
                io.IO = (Ivi.Visa.Interop.IMessage)rm.Open(GPIBConnectionString, Ivi.Visa.Interop.AccessMode.NO_LOCK, 0, "");
            }
            catch (Exception e)
            {
                Console.WriteLine("An error occured: {0}", e.Message);
                Dispose();
                throw;
            }
        }