//搜索可用设备 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 { } } }
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 { } } }
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; } }