private void OpenAsyncCallback(IAcquisitionSession sender, IAcqAsyncResult result) { if (this.m_PlcComms != null) { if (this.m_PlcComms.IsOpen) { CreateHandshake(); } } }
private void CreateAcquisitionSession() { try { LogSession.EnterMethod(this, "CreateAcquisitionSession"); /*--------- Your code goes here-------*/ if (this.m_PlcComms == null) { IFactory<IAcquisitionSession> factory = FactoryProvider.Instance.CreateFactory<IAcquisitionSession>(typeof(IAcquisitionSession).FullName); this.m_PlcComms = factory.Create(); this.m_PlcComms.StateChanged += new StateChangedHandler(m_PlcComms_StateChanged); } /*------------------------------------*/ } catch (Exception ex) { LogSession.LogException(ex); throw ex; } finally { LogSession.LeaveMethod(this, "CreateAcquisitionSession"); } }
void m_PlcComms_StateChanged(IAcquisitionSession sender, StateChangedEventArgs args) { switch (args.State) { case SessionState.Closed: break; case SessionState.Closing: break; case SessionState.Open: break; case SessionState.Opening: break; case SessionState.ServerNotRunning: break; default: break; } }
// 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.HandshakeMgr != null) { UnhookFromHandshake(); if ((this.HandshakeMgr as IDisposable) != null) (this.HandshakeMgr as IDisposable).Dispose(); this.HandshakeMgr = null; } if (this.m_ReaJetComms != null) { if ((this.m_ReaJetComms as IDisposable) != null) (this.m_ReaJetComms as IDisposable).Dispose(); this.m_ReaJetComms = null; } if (this.m_PlcComms != null) { this.m_PlcComms.StateChanged -= this.m_PlcComms_StateChanged; if (this.m_PlcComms.IsOpen) this.m_PlcComms.Close(); if ((this.m_PlcComms as IDisposable) != null) (this.m_PlcComms as IDisposable).Dispose(); this.m_PlcComms = 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"); } }