private void Receive() { try { while (_isWorking) { if (_serialPort.IsOpen) { var data = _serialPort.ReadLine(); if (OnDataReceivedEvent != null) { OnDataReceivedEvent.Invoke(data); } } else { _isWorking = false; } } _serialPort.Close(); } catch (Exception exception) { if (OnPortErrorEvent != null) { OnPortErrorEvent.Invoke(exception); } } finally { _serialPort.Close(); } }
public void Start() { try { _serialPort.Open(); } catch (Exception exception) { if (OnPortErrorEvent != null) { OnPortErrorEvent.Invoke(exception); } } if (OnPortOpenEvent != null) { OnPortOpenEvent.Invoke(); } _serialPortReaderThread.Start(); }