void getAvailableResources() { Ivi.Visa.Interop.ResourceManager rMgr = new ResourceManagerClass(); FormattedIO488 src = new FormattedIO488Class(); string [] resources = rMgr.FindRsrc("USB?*"); comboBox1.Items.AddRange(resources); string port = comboBox1.ToString(); // string srcAddress = "USB0::0xF4ED::0xEE3A::SDG2XBA3150073::INSTR"; // src.IO = (Ivi.Visa.Interop.IMessage)rMgr.Open(port, Ivi.Visa.Interop.AccessMode.NO_LOCK, 0, ""); /*src.IO = (IMessage)rMgr.Open(, AccessMode.NO_LOCK, 2000, ""); * src.IO.Timeout = 12000; * src.WriteString("*IDN?\n"); * string IDN = src.ReadString(); * * Console.WriteLine(IDN); */ }
public void BK8600() { //EC7::0x8800::802197036737120008::INSTR string srcAddress = "USB0::0x2EC7::0x8800::802197036737120008::INSTR"; ResourceManager rMgr = new ResourceManagerClass(); FormattedIO488 src = new FormattedIO488Class(); var addresses = rMgr.FindRsrc("USB?*"); var s = rMgr.Description; var x = rMgr.SpecVersion; src.IO = (IMessage)rMgr.Open(srcAddress, AccessMode.NO_LOCK, 2000, ""); src.IO.Timeout = 2000; src.IO.Clear(); src.WriteString("*RST; *OPC ?", true); src.WriteString("*IDN?", true); string temp = src.ReadString(); }
/// <summary> /// 寻找所有仪表资源 /// </summary> /// <returns></returns> public string[] FindAllResource() { IEnumerable <string> resources = m_IOResourceManager.FindRsrc("?*");//寻找仪表 return(resources.ToArray()); }
public static void ScanIOStatus(ref string[] m_IOAddress, ref string[] m_Description) { string empty = string.Empty; string str = string.Empty; try { ResourceManagerClass resourceManagerClass = new ResourceManagerClass(); string[] portNames = new string[1]; FormattedIO488Class formattedIO488Class = new FormattedIO488Class(); portNames = resourceManagerClass.FindRsrc("GPIB?*"); for (int i = 1; i < (int)portNames.Length; i++) { try { string empty1 = string.Empty; formattedIO488Class = new FormattedIO488Class() { IO = (IMessage)resourceManagerClass.Open(portNames[i], AccessMode.NO_LOCK, 20000, "") }; formattedIO488Class.IO.Clear(); try { formattedIO488Class.WriteString("*IDN?", true); Thread.Sleep(100); empty1 = formattedIO488Class.ReadString(); } catch { } if (!(empty1 != string.Empty) || !(empty1 != "\r\n")) { try { formattedIO488Class.WriteString("ID?", true); Thread.Sleep(100); empty1 = formattedIO488Class.ReadString(); } catch { } if (empty1 != string.Empty) { if (empty != string.Empty) { empty = string.Concat(empty, ";"); str = string.Concat(str, ";"); } empty = string.Concat(empty, portNames[i]); str = string.Concat(str, empty1); } } else { if (empty != string.Empty) { empty = string.Concat(empty, ";"); str = string.Concat(str, ";"); } empty = string.Concat(empty, portNames[i]); str = string.Concat(str, empty1); } formattedIO488Class.IO.Close(); } catch { } } try { portNames = resourceManagerClass.FindRsrc("TCPIP0::?*"); } catch { portNames = new string[0]; } for (int j = 0; j < (int)portNames.Length; j++) { try { formattedIO488Class = new FormattedIO488Class() { IO = (IMessage)resourceManagerClass.Open(portNames[j], AccessMode.NO_LOCK, 20000, "") }; formattedIO488Class.IO.Timeout = 2000; formattedIO488Class.WriteString("*IDN?", true); Thread.Sleep(100); string str1 = formattedIO488Class.ReadString(); if (str1 != string.Empty) { if (empty != string.Empty) { empty = string.Concat(empty, ";"); str = string.Concat(str, ";"); } empty = string.Concat(empty, portNames[j]); str = string.Concat(str, str1); } } catch { } } try { portNames = resourceManagerClass.FindRsrc("ASRL?*"); } catch { portNames = new string[0]; } for (int k = 0; k < (int)portNames.Length; k++) { try { formattedIO488Class = new FormattedIO488Class() { IO = (IMessage)resourceManagerClass.Open(portNames[k], AccessMode.NO_LOCK, 20000, "") }; formattedIO488Class.WriteString("*IDN?", true); Thread.Sleep(100); string str2 = formattedIO488Class.ReadString(); if (str2 != string.Empty) { if (empty != string.Empty) { empty = string.Concat(empty, ";"); str = string.Concat(str, ";"); } empty = string.Concat(empty, portNames[k]); str = string.Concat(str, str2); } formattedIO488Class.IO.Close(); } catch { } } try { portNames = resourceManagerClass.FindRsrc("USB?*"); } catch { portNames = new string[0]; } for (int l = 0; l < (int)portNames.Length; l++) { try { formattedIO488Class = new FormattedIO488Class() { IO = (IMessage)resourceManagerClass.Open(portNames[l], AccessMode.NO_LOCK, 20000, "") }; formattedIO488Class.WriteString("*IDN?", true); Thread.Sleep(100); string str3 = formattedIO488Class.ReadString(); if (str3 != string.Empty) { if (empty != string.Empty) { empty = string.Concat(empty, ";"); str = string.Concat(str, ";"); } empty = string.Concat(empty, portNames[l]); str = string.Concat(str, str3); } formattedIO488Class.IO.Close(); } catch { } } portNames = SerialPort.GetPortNames(); for (int m = 0; m < (int)portNames.Length; m++) { try { int num = 0; while (true) { string str4 = "*IDN?"; SerialPort serialPort = new SerialPort(portNames[m]) { BaudRate = 9600, DataBits = 8, Parity = Parity.None }; serialPort.Open(); Thread.Sleep(300); serialPort.Write("\r\n"); for (int n = 0; n < str4.Length; n++) { serialPort.Write(str4.Substring(n, 1)); Thread.Sleep(20); if (n == str4.Length - 1) { serialPort.Write("\r"); } } Thread.Sleep(300); string str5 = serialPort.ReadExisting(); serialPort.Close(); if (!(str5 != string.Empty) || str5.IndexOf("*IDN?") >= 0) { if (num >= 1) { break; } num++; } else { if (empty != string.Empty) { empty = string.Concat(empty, ";"); str = string.Concat(str, ";"); } empty = string.Concat(empty, portNames[m]); str = string.Concat(str, str5); break; } } } catch (Exception exception) { } } } catch { } char[] chrArray = new char[] { ';' }; m_IOAddress = empty.Split(chrArray); char[] chrArray1 = new char[] { ';' }; m_Description = str.Split(chrArray1); }