public NMEASerialPort(SerialPortSettings portSettings) : base() { #region serialPort initialization if (portSettings == null) { throw new ArgumentNullException("portSettings"); } PortSettings = portSettings; serialPort = new SerialPort( PortSettings.PortName, (int)PortSettings.PortBaudRate, PortSettings.PortParity, (int)PortSettings.PortDataBits, PortSettings.PortStopBits); serialPort.Handshake = portSettings.PortHandshake; serialPort.Encoding = Encoding.ASCII; serialPort.WriteTimeout = 1000; serialPort.ReadTimeout = 1000; serialPort.ReceivedBytesThreshold = 1; serialErrorReceivedHandler = new SerialErrorReceivedEventHandler(serialPort_ErrorReceived); serialDataReceivedHandler = new SerialDataReceivedEventHandler(serialPort_DataReceived); #endregion }
internal void OnErrorReceived(SerialErrorReceivedEventArgs args) { SerialErrorReceivedEventHandler handler = (SerialErrorReceivedEventHandler)Events [error_received]; handler?.Invoke(this, args); }
private Boolean connectToPort(string port, int baudRate, Parity parity, int databits, StopBits stopbits, SerialDataReceivedEventHandler sport_DataReceived, SerialErrorReceivedEventHandler sport_ErrorReceived, out string messageResponse) { Boolean response = false; CnnPort cnnPort = new CnnPort(port, baudRate, parity, databits, stopbits, new SerialDataReceivedEventHandler(sport_DataReceived), new SerialErrorReceivedEventHandler(sport_ErrorReceived)); if (cnnPort.Open(out messageResponse)) { cnnPortList.Add(port, cnnPort); response = true; } return(response); }
public SerialPort(string portname = "COM1", int baudrate = 9600, Parity parity = Parity.None, int databits = 8, StopBits stopbits = StopBits.One, Handshake handshake = Handshake.None, int readtimeout = System.IO.Ports.SerialPort.InfiniteTimeout, int writetimeout = System.IO.Ports.SerialPort.InfiniteTimeout, string newline = "\n", bool isevent = false) { serialport = new System.IO.Ports.SerialPort(portname, baudrate, parity, databits, stopbits) { Handshake = handshake, ReadTimeout = readtimeout, WriteTimeout = writetimeout, NewLine = newline }; if (handshake != Handshake.None) { serialport.DtrEnable = true; if (handshake != Handshake.XOnXOff) { serialport.RtsEnable = true; } } if (isevent) { DataReceivedEventHandler = new SerialDataReceivedEventHandler(DataReceived); ErrorReceivedEventHandler = new SerialErrorReceivedEventHandler(ErrorReceived); PinChangedEventHandler = new SerialPinChangedEventHandler(PinChanged); serialport.DataReceived += DataReceivedEventHandler; serialport.ErrorReceived += ErrorReceivedEventHandler; serialport.PinChanged += PinChangedEventHandler; } }
private void Dispose(bool fDisposing) { if (!m_fDisposed) { try { if (fDisposing) { if (m_callbacksErrorEvent != null) { m_evtErrorEvent.OnInterrupt -= new NativeEventHandler(ErrorEventHandler); m_callbacksErrorEvent = null; m_evtErrorEvent.Dispose(); } if (m_callbacksDataEvent != null) { m_evtDataEvent.OnInterrupt -= new NativeEventHandler(DataEventHandler); m_callbacksDataEvent = null; m_evtDataEvent.Dispose(); } } if (m_fOpened) { Close(); } } finally { m_fDisposed = true; m_fOpened = false; } } }
/// <summary> /// Gets an event handler (delegate) that handles the SerialErrorReceived event from a serial port /// and passes the error on to an observer by calling the OnError method on the observer. /// </summary> /// <param name="observer">The observer.</param> /// <returns>delegate of type <see cref="SerialErrorReceivedEventHandler" />.</returns> private static SerialErrorReceivedEventHandler ReactiveErrorReceivedEventHandler(IObserver <char> observer) { var errorEventHandler = new SerialErrorReceivedEventHandler( (sender, e) => observer.OnError(new Exception(e.EventType.ToString()))); return(errorEventHandler); }
/// <summary> /// Init, need to OpenCOM() /// </summary> public SLCOM() { FindCOM(); Port = new SerialPort(); DataReceivedEventHandler = new SerialDataReceivedEventHandler(DataReceived); ErrorReceivedEventHandler = new SerialErrorReceivedEventHandler(ErrorReceived); PinChangedEventHandler = new SerialPinChangedEventHandler(PinChanged); }
/// <summary> /// Extends BeginInvoke so that when a state object is not needed, null does not need to be passed. /// <example> /// serialerrorreceivedeventhandler.BeginInvoke(sender, e, callback); /// </example> /// </summary> public static IAsyncResult BeginInvoke(this SerialErrorReceivedEventHandler serialerrorreceivedeventhandler, Object sender, SerialErrorReceivedEventArgs e, AsyncCallback callback) { if (serialerrorreceivedeventhandler == null) { throw new ArgumentNullException("serialerrorreceivedeventhandler"); } return(serialerrorreceivedeventhandler.BeginInvoke(sender, e, callback, null)); }
private SerialErrorReceivedEventHandler CreateErrorObservable(IObserver <byte[]> obs) { var err = new SerialErrorReceivedEventHandler((sender, e) => { obs.OnError(new Exception(e.EventType.ToString())); }); return(err); }
public void OnErrorReceived(SerialErrorReceivedEventArgs e) { SerialErrorReceivedEventHandler handler = ErrorReceived; if (handler != null) { handler(this, e); } }
internal void OnErrorReceived(SerialErrorReceivedEventArgs args) { SerialErrorReceivedEventHandler handler = (SerialErrorReceivedEventHandler)Events [error_received]; if (handler != null) { handler(this, args); } }
public SerialComPort() { m_selectedPort = new SerialPort(); m_SerialUtilities = new SerialUtilities(); dataReceivedHandler = new SerialDataReceivedEventHandler(SerialDataReceived); m_selectedPort.DataReceived += dataReceivedHandler; errorReceivedHandler = new SerialErrorReceivedEventHandler(ErrorReceivedHandler); m_selectedPort.ErrorReceived += errorReceivedHandler; }
private void OpenSerialPort() { try { StopSerialPorts(); inputSerial = new SerialPort(); inputSerial.BaudRate = Properties.Settings.Default.InputBaudRate; inputSerial.DataBits = Properties.Settings.Default.InputDataBits; inputSerial.StopBits = Properties.Settings.Default.InputStopBits; inputSerial.Parity = Properties.Settings.Default.InputParity; inputSerial.PortName = Properties.Settings.Default.InputPortName; try { inputSerial.Open(); statusKoneksiInput.Text = "Input connected to Port : " + inputSerial.PortName; inputDataReceivedEventHandler = new SerialDataReceivedEventHandler(InputSerialDataReceived); inputSerial.DataReceived += inputDataReceivedEventHandler; inputErrorReceivedEventHandler = new SerialErrorReceivedEventHandler(InputSerialErrorReceived); inputSerial.ErrorReceived += inputErrorReceivedEventHandler; } catch (Exception ex) { statusKoneksiInput.ForeColor = Color.Red; statusKoneksiInput.Text = "Gagal Koneksi Ke Input"; } gateSerial = new SerialPort(); gateSerial.BaudRate = Properties.Settings.Default.GateBaudRate; gateSerial.DataBits = Properties.Settings.Default.GateDataBits; gateSerial.StopBits = Properties.Settings.Default.GateStopBits; gateSerial.Parity = Properties.Settings.Default.GateParity; gateSerial.PortName = Properties.Settings.Default.GatePortName; try { gateSerial.Open(); statusKoneksiPortal.Text = "Gate connected to Port :" + gateSerial.PortName; gateDataReceivedEventHandler = new SerialDataReceivedEventHandler(GateSerialDataReceived); gateSerial.DataReceived += gateDataReceivedEventHandler; gateErrorReceivedEventHandler = new SerialErrorReceivedEventHandler(GateErrorReceived); gateSerial.ErrorReceived += gateErrorReceivedEventHandler; } catch (Exception ex) { statusKoneksiPortal.ForeColor = Color.Red; statusKoneksiPortal.Text = "Gagal Koneksi ke Portal"; } } catch (Exception ex) { MessageBox.Show(ex.Message + ex.StackTrace); } }
public InsituSession(string portName, int userId, string userName, string password, int?sendAckResponseThershold, int?baudRate, bool?dtrEnabled, int?receivedBytesThershold, NegotiationSetting negotiationSetting = null, TimingSetting timingSetting = null) : base(userId, userName, password, sendAckResponseThershold, receivedBytesThershold, negotiationSetting, timingSetting) { PortName = portName; BaudRate = baudRate; DtrEnabled = dtrEnabled; serialDataReceivedEventHandler = new SerialDataReceivedEventHandler(OnSerialDataReceived); serialErrorReceivedEventHandler = new SerialErrorReceivedEventHandler(OnSerialErrorReceived); serialPinChangedEventHandler = new SerialPinChangedEventHandler(OnSerialPinChanged); }
/// <summary> /// Default constructor /// </summary> public ComPort() { //Create the new port and report that it's closed. serialPort = new SerialPort(); serialDataReceivedEventHandler1 = new SerialDataReceivedEventHandler(DataReceived); serialErrorReceivedEventHandler1 = new SerialErrorReceivedEventHandler(ErrorReceived); serialPort.DataReceived += serialDataReceivedEventHandler1; serialPort.ErrorReceived += serialErrorReceivedEventHandler1; ReportStatus("Port Closed"); }
// Optionally adds rx and error handlers public void initHandlers(SerialDataReceivedEventHandler rxHandler, SerialErrorReceivedEventHandler errorHandler) { if (com != null) { if (rxHandler != null) { com.DataReceived += rxHandler; } if (errorHandler != null) { com.ErrorReceived += errorHandler; } } }
public BpsMng() { uartMngObj = UartMng.GetUartMngInstance(); // bpsRecvHandler = BPSRecvIdleHandler; bpsErrorHandler = BPSErrorIdleHandler; bpsSendDebugHandler = null; bpsRecvDebugHandler = null; serialDataReceivedEvent = new SerialDataReceivedEventHandler(UartDataeceivedCallback); uartMngObj.ReadCallbackAdd(serialDataReceivedEvent); serialErrorEvent = new SerialErrorReceivedEventHandler(UartErrorCallback); uartMngObj.ErrorCallbackAdd(serialErrorEvent); RecvBuffer = new List <byte>(); BpsHeaderClear(); enBPSParseStep = EnBPSParseStep.EN_BPS_PARSE_HEADER; remainLength = 0; }
private void CatchErrorEvents(object src, SerialErrorReceivedEventArgs e) { SerialErrorReceivedEventHandler errorReceived = this.ErrorReceived; SerialStream internalSerialStream = this.internalSerialStream; if ((errorReceived != null) && (internalSerialStream != null)) { lock (internalSerialStream) { if (internalSerialStream.IsOpen) { errorReceived(this, e); } } } }
public CnnPort(string port, int baudRate, Parity parity, int databits, StopBits stopbits, SerialDataReceivedEventHandler sport_DataReceived, SerialErrorReceivedEventHandler sport_ErrorReceived) { sport = new SerialPort (port, baudRate, parity, databits, stopbits); try { sport.Close (); } catch (Exception) {} sport.DataReceived += sport_DataReceived; sport.ErrorReceived += sport_ErrorReceived; }
public CnnPort(string port, int baudRate, Parity parity, int databits, StopBits stopbits, SerialDataReceivedEventHandler sport_DataReceived, SerialErrorReceivedEventHandler sport_ErrorReceived) { sport = new SerialPort(port, baudRate, parity, databits, stopbits); try { sport.Close(); } catch (Exception) {} sport.DataReceived += sport_DataReceived; sport.ErrorReceived += sport_ErrorReceived; }
public Boolean Close(SerialDataReceivedEventHandler sport_DataReceived, SerialErrorReceivedEventHandler sport_ErrorReceived) { Boolean result = false; try { sport.Close(); sport.DataReceived -= sport_DataReceived; sport.ErrorReceived -= sport_ErrorReceived; result = true; } catch (Exception ex) { Logger logger = LogManager.GetCurrentClassLogger(); logger.Error(ex,ex.Message); } return result; }
public SerialPortsPool(SerialPortSettings[] portSettings) { ports = new Dictionary <string, SerialPort>(); pendingClose = new Dictionary <string, bool>(); dataReceivedHandler = new SerialDataReceivedEventHandler(port_DataReceived); errorReceivedHandler = new SerialErrorReceivedEventHandler(port_ErrorReceived); foreach (var item in portSettings) { if (!ports.ContainsKey(item.PortName)) { var port = new SerialPort(item.PortName, (int)item.PortBaudRate, item.PortParity, (int)item.PortDataBits, item.PortStopBits); port.ReadTimeout = 1000; ports.Add(port.PortName, port); pendingClose.Add(port.PortName, false); } } }
public Boolean Close(SerialDataReceivedEventHandler sport_DataReceived, SerialErrorReceivedEventHandler sport_ErrorReceived) { Boolean result = false; try { sport.Close(); sport.DataReceived -= sport_DataReceived; sport.ErrorReceived -= sport_ErrorReceived; result = true; } catch (Exception ex) { Logger logger = LogManager.GetCurrentClassLogger(); logger.Error(ex, ex.Message); } return(result); }
static IObservable<byte> CreatePortObservable(SerialPort port) { return Observable.Create<byte>(obs => { // Alternative Rx-driven approach on the inside // // var rcv = Observable.FromEvent<SerialDataReceivedEventArgs>(port, "DataReceived"); // var err = Observable.FromEvent<SerialErrorReceivedEventArgs>(port, "ErrorReceived"); var rcv = new SerialDataReceivedEventHandler((sender, e) => { if (e.EventType == SerialData.Eof) { obs.OnCompleted(); } else { var buf = new byte[port.BytesToRead]; for (int i = 0; i < port.Read(buf, 0, buf.Length); i++) obs.OnNext(buf[i]); } }); port.DataReceived += rcv; var err = new SerialErrorReceivedEventHandler((sender, e) => { obs.OnError(new Exception(e.EventType.ToString())); }); port.ErrorReceived += err; return () => { port.DataReceived -= rcv; port.ErrorReceived -= err; // depending on ownership of port, you could Dispose it here too }; }); }
private bool CallEvents(SerialPort com) { bool retValue = true; SerialErrorReceivedEventHandler serialErrorReceivedEventHandler = SerialErrorReceivedEventHandler; SerialPinChangedEventHandler serialPinChangedEventHandler = SerialPinChangedEventHandler; SerialDataReceivedEventHandler serialDataReceivedEventHandler = SerialDataReceivedEventHandler; //[] ErrorReceived Add try { com.ErrorReceived += serialErrorReceivedEventHandler; } catch (Exception e) { Console.WriteLine("ErrorReceived Add threw the following unexpected exception:"); Console.WriteLine(e); retValue = false; } //[] ErrorReceived Remove try { com.ErrorReceived -= serialErrorReceivedEventHandler; } catch (Exception e) { Console.WriteLine("ErrorReceived Remove threw the following unexpected exception:"); Console.WriteLine(e); retValue = false; } //[] PinChanged Add try { com.PinChanged += serialPinChangedEventHandler; } catch (Exception e) { Console.WriteLine("PinChanged Add threw the following unexpected exception:"); Console.WriteLine(e); retValue = false; } //[] PinChanged Remove try { com.PinChanged -= serialPinChangedEventHandler; } catch (Exception e) { Console.WriteLine("PinChanged Remove threw the following unexpected exception:"); Console.WriteLine(e); retValue = false; } //[] DataReceived Add try { com.DataReceived += serialDataReceivedEventHandler; } catch (Exception e) { Console.WriteLine("DataReceived Add threw the following unexpected exception:"); Console.WriteLine(e); retValue = false; } //[] DataReceived Remove try { com.DataReceived -= serialDataReceivedEventHandler; } catch (Exception e) { Console.WriteLine("DataReceived Remove threw the following unexpected exception:"); Console.WriteLine(e); retValue = false; } return(retValue); }
private Boolean connectToPort( string port, int baudRate, Parity parity, int databits, StopBits stopbits, SerialDataReceivedEventHandler sport_DataReceived, SerialErrorReceivedEventHandler sport_ErrorReceived, out string messageResponse) { Boolean response = false; CnnPort cnnPort = new CnnPort ( port, baudRate, parity, databits, stopbits, new SerialDataReceivedEventHandler(sport_DataReceived), new SerialErrorReceivedEventHandler(sport_ErrorReceived)); if (cnnPort.Open (out messageResponse)) { cnnPortList.Add (port, cnnPort); response = true; } return response; }
/// <summary> /// Dettach SerialDataReceived and SerialErrorReceived event handlers /// </summary> /// <param name="data_received">SerialDataReceivedEventHandler</param> /// <param name="error_recieved">SerialErrorReceivedEventHandler</param> public void DettachEvents(SerialDataReceivedEventHandler data_received, SerialErrorReceivedEventHandler error_recieved) { this.port.DataReceived -= data_received; this.port.ErrorReceived -= error_recieved; }
/// <summary> /// Open the SerialPort object selectedPort. /// If open, close the SerialPort object previousPort. /// </summary> internal bool OpenComPort() { var success = false; _serialDataReceivedEventHandler1 = DataReceived; _serialErrorReceivedEventHandler1 = ErrorReceived; try { if ( ComPortExists ) { // The system has at least one COM port. // If the previously selected port is still open, close it. if ( PreviousPort.IsOpen ) { CloseComPort( PreviousPort ); } if ( ( !( ( SelectedPort.IsOpen ) ) | PortChanged ) ) { SelectedPort.Open(); if ( SelectedPort.IsOpen ) { // The port is open. Set additional parameters. // Timeouts are in milliseconds. SelectedPort.ReadTimeout = 5000; SelectedPort.WriteTimeout = 5000; System.Text.Encoding iso_8859_1 = System.Text.Encoding.GetEncoding("iso-8859-1"); SelectedPort.Encoding = System.Text.Encoding.GetEncoding(28591); //SelectedPort.Encoding = Encoding.GetEncoding("Windows-1252"); // Specify the routines that run when a DataReceived or ErrorReceived event occurs. SelectedPort.DataReceived += _serialDataReceivedEventHandler1; SelectedPort.ErrorReceived += _serialErrorReceivedEventHandler1; // Send data to other modules. if ( null != UserInterfaceData ) UserInterfaceData( "DisplayCurrentSettings", new DataModel() ); if ( null != UserInterfaceData ) UserInterfaceData( "DisplayStatus",new DataModel()); success = true; // The port is open with the current parameters. PortChanged = false; } } } } catch ( InvalidOperationException ex ) { ParameterChanged = true; PortChanged = true; DisplayException( ModuleName, ex ); } catch ( UnauthorizedAccessException ex ) { ParameterChanged = true; PortChanged = true; DisplayException( ModuleName, ex ); } catch ( System.IO.IOException ex ) { ParameterChanged = true; PortChanged = true; DisplayException( ModuleName, ex ); } return success; }
/// <summary> /// Open the SerialPort object selectedPort. /// If open, close the SerialPort object previousPort. /// </summary> internal bool OpenComPort() { bool success = false; SerialDataReceivedEventHandler1 = new SerialDataReceivedEventHandler(DataReceived); SerialErrorReceivedEventHandler1 = new SerialErrorReceivedEventHandler(ErrorReceived); try { if ( comPortExists ) { // The system has at least one COM port. // If the previously selected port is still open, close it. if ( PreviousPort.IsOpen ) { CloseComPort( PreviousPort ); } if ( ( !( ( SelectedPort.IsOpen ) ) | PortChanged ) ) { SelectedPort.Open(); if ( SelectedPort.IsOpen ) { // The port is open. Set additional parameters. // Timeouts are in milliseconds. SelectedPort.ReadTimeout = 5000; SelectedPort.WriteTimeout = 5000; // Specify the routines that run when a DataReceived or ErrorReceived event occurs. SelectedPort.DataReceived += SerialDataReceivedEventHandler1; SelectedPort.ErrorReceived += SerialErrorReceivedEventHandler1; // Send data to other modules. if ( null != UserInterfaceData ) UserInterfaceData( "DisplayCurrentSettings", "", Color.Black ); if ( null != UserInterfaceData ) UserInterfaceData( "DisplayStatus", "", Color.Black ); success = true; // The port is open with the current parameters. PortChanged = false; } } } } catch ( InvalidOperationException ex ) { ParameterChanged = true; PortChanged = true; DisplayException( ModuleName, ex ); } catch ( UnauthorizedAccessException ex ) { ParameterChanged = true; PortChanged = true; DisplayException( ModuleName, ex ); } catch ( System.IO.IOException ex ) { ParameterChanged = true; PortChanged = true; DisplayException( ModuleName, ex ); } return success; }
/// <summary> /// Abrir con el SerialPort el objeto de PuertoSeleccionado. /// Si está abierto, cierra con el SerialPort el objeto de PuertoAnterior /// </summary> /// <returns></returns> public bool AbrirPuertoCom() { success = false; DatoRecibidoSerialEventHandler = new SerialDataReceivedEventHandler(DatoRecibido); ErrorRecibidoSerialEventHandler = new SerialErrorReceivedEventHandler(ErrorRecibido); try { if (PuertoComExiste) { if (PuertoAnterior.IsOpen) CerrarPuertoCom(PuertoAnterior); if (!(PuertoSeleccionado.IsOpen) | PuertoCambiado) { PuertoSeleccionado.Open(); if (PuertoSeleccionado.IsOpen) { //El puerto está abierto. Setear los parametros adicionales. //Timeouts son en milisegundos. PuertoSeleccionado.ReadTimeout = Convert.ToInt32(TiemposEnum.CincoSegundos); PuertoSeleccionado.WriteTimeout = Convert.ToInt32(TiemposEnum.CincoSegundos); //Especificar las rutinas que se ejecutan cuando un evento de DatoRecibido o ErrorRecibido ocurre. PuertoSeleccionado.DataReceived += DatoRecibidoSerialEventHandler; PuertoSeleccionado.ErrorReceived += ErrorRecibidoSerialEventHandler; //Enviar dato a otro modulo. if (InterfazUsuarioDatoVista != null) { InterfazUsuarioDatoVista("AjustesActualesDisplay", string.Empty, Color.Black); InterfazUsuarioDatoVista("EstadoDisplay", string.Empty, Color.Black); } success = true; //El puerto está abierto con los parametros actuales. PuertoCambiado = false; } } } } catch (InvalidOperationException ex) { ParametroCambiado = true; PuertoCambiado = true; DisplayException(NombreModulo, ex); } catch (UnauthorizedAccessException ex) { ParametroCambiado = true; PuertoCambiado = true; DisplayException(NombreModulo, ex); } catch (System.IO.IOException ex) { ParametroCambiado = true; PuertoCambiado = true; DisplayException(NombreModulo, ex); } return success; }
/// <summary> /// Open the SerialPort object selectedPort. /// If open, close the SerialPort object previousPort. /// </summary> internal bool OpenComPort() { bool success = false; SerialDataReceivedEventHandler1 = new SerialDataReceivedEventHandler(DataReceived); SerialErrorReceivedEventHandler1 = new SerialErrorReceivedEventHandler(ErrorReceived); try { if (comPortExists) { // The system has at least one COM port. // If the previously selected port is still open, close it. if (PreviousPort.IsOpen) { CloseComPort(PreviousPort); } if ((!((SelectedPort.IsOpen)) | PortChanged)) { SelectedPort.Open(); if (SelectedPort.IsOpen) { // The port is open. Set additional parameters. // Timeouts are in milliseconds. SelectedPort.ReadTimeout = 5000; SelectedPort.WriteTimeout = 5000; // SelectedPort.ReceivedBytesThreshold = PACKETSIZE; // $$$$ // Specify the routines that run when a DataReceived or ErrorReceived event occurs. SelectedPort.DataReceived += SerialDataReceivedEventHandler1; SelectedPort.ErrorReceived += SerialErrorReceivedEventHandler1; // Send data to other modules. if (null != UserInterfaceData) { UserInterfaceData("DisplayCurrentSettings", "", Color.Black); } if (null != UserInterfaceData) { UserInterfaceData("DisplayStatus", "", Color.Black); } success = true; // The port is open with the current parameters. PortChanged = false; } } } } catch (InvalidOperationException ex) { ParameterChanged = true; PortChanged = true; DisplayException(ModuleName, ex); } catch (UnauthorizedAccessException ex) { ParameterChanged = true; PortChanged = true; DisplayException(ModuleName, ex); } catch (System.IO.IOException ex) { ParameterChanged = true; PortChanged = true; DisplayException(ModuleName, ex); } return(success); }
protected void portError( object sender, SerialErrorReceivedEventHandler args) { // Do whatever with the error, maybe need to reopen the socket. }
protected override void Dispose(bool disposing) { if (!m_fDisposed) { try { if (disposing) { if (m_callbacksErrorEvent != null) { m_evtErrorEvent.OnInterrupt -= new NativeEventHandler(ErrorEventHandler); m_callbacksErrorEvent = null; m_evtErrorEvent.Dispose(); } if (m_callbacksDataEvent != null) { m_evtDataEvent.OnInterrupt -= new NativeEventHandler(DataEventHandler); m_callbacksDataEvent = null; m_evtDataEvent.Dispose(); } } if (m_fOpened) { Close(); } } finally { m_fDisposed = true; m_fOpened = false; } } base.Dispose(disposing); }