private void port_RawDataReceived(object sender, RawDataReceivedEventArgs e) { if (!IsCommandMode) { RawDataReceived.Rise(this, e); } }
private void serialPort_DataReceived(object sender, SerialDataReceivedEventArgs e) { if (!pendingClose) { while (Interlocked.CompareExchange(ref readLock, 1, 0) != 0) { Thread.SpinWait(1); } int bytesToRead = serialPort.BytesToRead; byte[] buffer = new byte[bytesToRead]; serialPort.Read(buffer, 0, bytesToRead); Interlocked.Decrement(ref readLock); RawDataReceived.Rise(this, new RawDataReceivedEventArgs(buffer)); if (!IsRawModeOnly) { //OnIncomingData(buffer); OnIncomingDataEx(Encoding.ASCII.GetString(buffer)); } } }