private void button_Start_Click(object sender, EventArgs e) { OpcReaJetAdapter opcReaJetAdapter = new OpcReaJetAdapter(); opcReaJetAdapter.Settings.portName = this._portName; opcReaJetAdapter.Settings.baudRate = this._baudRate; opcReaJetAdapter.Settings.parity = this._parity; opcReaJetAdapter.Settings.dataBits = this._dataBits; opcReaJetAdapter.Settings.stopBits = this._stopBits; opcReaJetAdapter.Settings.readTimeOut = this._readTimeOut; opcReaJetAdapter.Settings.writeTimeOut = this._writeTimeOut; opcReaJetAdapter.Settings.ackTimeOut = this._ackTimeOut; opcReaJetAdapter.Settings.replyTelegramTimeOut = this._replyTelegramTimeOut; opcReaJetAdapter.Settings.HSK_ACK_TAG = this._HskAckTag; opcReaJetAdapter.Settings.HSK_INPUT_PARAMS_TAG = this._HskInputParam; opcReaJetAdapter.Settings.HSK_OUTPUT_PARAMS_TAG = this._HskOutputParamsTag; opcReaJetAdapter.Settings.HSK_TRIGGER_TAG = this._HskTriggerTag; opcReaJetAdapter.Settings.HSK_TRIGGER_FROM = (byte)this._triggerFromValue; opcReaJetAdapter.Settings.HSK_TRIGGER_TO = (byte)this._triggerToValue; SingleInstanceServiceWrapper<OpcReaJetAdapter> ControllerLoaderService = new SingleInstanceServiceWrapper<OpcReaJetAdapter>(opcReaJetAdapter); this.m_sm.Services.Add(ControllerLoaderService); this.m_sm.InitializeServices(); this.m_sm.ActivateServices(); }
static void Main(string[] args) { LogHelperLib.Helper.InitializeLogger(string.Format("ReaJetCommsService"), string.Format("ReaJetCommsServiceLog.sil")); CreateLibSessions(); ServiceManager sm = null; SiAuto.Main.EnterProcess("Main"); try { sm = new ServiceManager(); OpcReaJetAdapter opcReaJetAdapter = new OpcReaJetAdapter(); opcReaJetAdapter.Settings = ReadSettings(); SingleInstanceServiceWrapper<OpcReaJetAdapter> ControllerLoaderService = new SingleInstanceServiceWrapper<OpcReaJetAdapter>(opcReaJetAdapter); sm.Services.Add(ControllerLoaderService); sm.InitializeServices(); sm.ActivateServices(); Console.WriteLine("Services running"); Console.WriteLine("Press ENTER to stop services"); Console.ReadLine(); sm.DeactivateServices(); } catch (FaultException ex) { SiAuto.Main.LogException(ex); } finally { sm.UninitializeServices(); SiAuto.Main.LeaveProcess("Main"); } }
/*****************************************************************************************************/ protected override void OnStart(string[] args) { LogHelperLib.Helper.InitializeLogger(string.Format("OpcREAjetWindowsService"), string.Format("OpcREAjetWindowsServiceLog.sil")); CreateLibSessions(); SiAuto.Main.EnterMethod("OnStart"); try { SiAuto.Main.LogSeparator(); SiAuto.Main.LogSeparator(); SiAuto.Main.LogColored(Color.FromArgb(204, 0, 102), " "); SiAuto.Main.LogColored(Color.FromArgb(0, 0, 153), "Starting Windows Service"); SiAuto.Main.LogColored(Color.FromArgb(0, 153, 0), " "); ReadSettings(); OpcReaJetAdapter opcReaJetAdapter = new OpcReaJetAdapter(); opcReaJetAdapter.Settings.portName = this._portName; opcReaJetAdapter.Settings.baudRate = this._baudRate; opcReaJetAdapter.Settings.parity = this._parity; opcReaJetAdapter.Settings.dataBits = this._dataBits; opcReaJetAdapter.Settings.stopBits = this._stopBits; opcReaJetAdapter.Settings.readTimeOut = this._readTimeOut; opcReaJetAdapter.Settings.writeTimeOut = this._writeTimeOut; opcReaJetAdapter.Settings.ackTimeOut = this._ackTimeOut; opcReaJetAdapter.Settings.replyTelegramTimeOut = this._replyTelegramTimeOut; opcReaJetAdapter.Settings.OpcInterfaceRequired = this._OpcInterfaceRequired; opcReaJetAdapter.Settings.HSK_ACK_TAG = this._HskAckTag; opcReaJetAdapter.Settings.HSK_ACK_DESCRIPTION_TAG = this._HskAckDescTag; opcReaJetAdapter.Settings.HSK_TESTMODE_TAG = this._HskTestModeTag; opcReaJetAdapter.Settings.HSK_TRIGGER_ID_TAG = this._HskTriggerIdTag; opcReaJetAdapter.Settings.HSK_INPUT_PARAMS_TAG = this._HskInputParam; opcReaJetAdapter.Settings.HSK_OUTPUT_PARAMS_TAG = this._HskOutputParamsTag; opcReaJetAdapter.Settings.HSK_TRIGGER_TAG = this._HskTriggerTag; opcReaJetAdapter.Settings.HSK_TRIGGER_FROM = (byte)this._triggerFromValue; opcReaJetAdapter.Settings.HSK_TRIGGER_TO = (byte)this._triggerToValue; opcReaJetAdapter.Initialize(); opcReaJetAdapter.Activate(); this.m_host = new ServiceHost(opcReaJetAdapter); this.m_host.Faulted += new EventHandler(m_host_Faulted); this.m_host.Open(); // Register Channel listner to handle fault event. RegisterChannelListnersForFault(this.m_host); } catch (Exception ex) { SiAuto.Main.LogException(ex); throw ex; } finally { SiAuto.Main.LeaveMethod("OnStart"); } }