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, "getCounterId : " + 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, "open:" + ex.Message); result = -1; } } return result; } 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, "getCounterId : " + 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, "getCounterId : " + ex.Message); content = ""; } return content; } } }