public ReaJetComms(string portName, int baudRate, Parity parity, int dataBits, StopBits stopBits, int readTimeout, int writeTimeOut) { string appName = GUROCK_APP_NAME; if ((SiAuto.Si.AppName != appName) && (!SiAuto.Si.Enabled)) LogHelperLib.Helper.InitializeLogger(appName, string.Format("{0}.sil", GUROCK_APP_NAME)); if (!GurockSessionExists()) { SiAuto.Si.AddSession(GUROCK_SESSION_NAME, true); } this.m_CommandValidator = new CommandValidator(); this._portName = portName; if (serialPort == null) serialPort = new SerialPort(portName, baudRate, parity, dataBits, stopBits); serialPort.ReadTimeout = readTimeout; serialPort.WriteTimeout = writeTimeOut; //serialPort.DataReceived += new SerialDataReceivedEventHandler(serialPort_DataReceived); serialPort.ErrorReceived += new SerialErrorReceivedEventHandler(serialPort_ErrorReceived); this.ACK_TIMEOUT = 150; this.REPLY_TELEGRAM_TIMEOUT = 150; this.Command = 0x00; this.CommandParams = null; this.m_Workflow = new CommandWorkflow(CmdWorklowStates.INITIAL_STATE); this.m_ReceivedTelegram = new REAjetTelegram(); ConnectMethodsToWorkflow(); this.m_Workflow.Configure(); // OpenPort(); }
public PurgeCommandHandler() { this.m_Workflow = new CommandWorkflow(CmdWorklowStates.INITIAL_STATE); ConnectMethodsToWorkflow(); this.m_Workflow.Configure(); }
// Dispose(bool disposing) executes in two distinct scenarios. // If disposing equals true, the method has been called directly // or indirectly by a user's code. Managed and unmanaged resources // can be disposed. // If disposing equals false, the method has been called by the // runtime from inside the finalizer and you should not reference // other objects. Only unmanaged resources can be disposed. protected virtual void Dispose(bool disposing) { try { LogSession.EnterMethod(this, "Dispose"); /*--------- Your code goes here-------*/ // Check to see if Dispose has already been called. if (!this.disposed) { // If disposing equals true, dispose all managed // and unmanaged resources. if (disposing) { // Free any managed resources in this section // free managed resources try { if (this.serialPort != null) { //serialPort.DataReceived -= this.serialPort_DataReceived; serialPort.ErrorReceived -= this.serialPort_ErrorReceived; if (serialPort.IsOpen) ClosePort(); if ((this.serialPort as IDisposable) != null) (this.serialPort as IDisposable).Dispose(); this.serialPort = null; } if (this.m_Workflow != null) { if ((this.m_Workflow as IDisposable) != null) (this.m_Workflow as IDisposable).Dispose(); this.m_Workflow = null; } } catch (Exception ex) { LogSession.LogException(ex); } } // Call the appropriate methods to clean up // unmanaged resources here. // If disposing is false, // only the following code is executed. } disposed = true; /*------------------------------------*/ } catch (Exception ex) { LogSession.LogException(ex); throw ex; } finally { LogSession.LeaveMethod(this, "Dispose"); } }