using Casic.Birmm.RbFreqStandMeasure.Tools; using Casic.Birmm.RbFreqStandMeasure.VISA.Port; using Casic.Birmm.RbFreqStandMeasure.VISA.Ulitity; using System; using System.Reflection; namespace Casic.Birmm.RbFreqStandMeasure.R_DevService.Service.Impl { class GPIBServiceImpl:GPIBService { public string[] getId() { string[] counterId; try { counterId = PortUltility.FindAddresses(PortType.GPIB); } catch (Exception ex) { LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "gpib getId : " + ex.Message); counterId = null; } return counterId; } private PortOperatorBase _portOperatorBaseGpib; public int open(string id) { int result = -1; if (NewPortInstance(id)) { try { _portOperatorBaseGpib.Open(); result = 0; } catch (Exception ex) { LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "gpib open:" + ex.Message); result = -1; } } return result; } public bool isOpen() { try { _portOperatorBaseGpib.WriteLine("*IDN?"); string idn = _portOperatorBaseGpib.ReadLine(); if (idn!=null||idn != "") return true; else return false; } catch (Exception ex) { return false; } /*if (_portOperatorBaseGpib == null || !_portOperatorBaseGpib.IsPortOpen) return false; else return true;*/ } private bool NewPortInstance(string sensitivityId) { bool hasAddress = false; bool hasException = false; try { _portOperatorBaseGpib = new GPIBPortOperator(sensitivityId); hasAddress = true; } catch (Exception ex) { hasException = true; } if (!hasException) _portOperatorBaseGpib.Timeout = 2000; return hasAddress; } public int close() { int result = -1; try { _portOperatorBaseGpib.Close(); result = 0; } catch (Exception ex) { LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "gpib close : " + ex.Message); result = -1; } return result; } public int write(string content) { int result = -1; try { _portOperatorBaseGpib.WriteLine(content); result = 0; } catch (Exception ex) { result = -1; } return result; } public string read() { string content = ""; try { content = _portOperatorBaseGpib.ReadLine(); } catch (Exception ex) { LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "read : " + ex.Message); content = ""; } return content; } } }