private void OnCOMPortDataReceived(object sender, SerialDataReceivedEventArgs e) { do { var rxChar = Convert.ToByte(COMPort.ReadByte()); RawData[DataIndex++] = rxChar; if (DataIndex >= RawData.Length) { DataIndex = 0; DataValid = false; try { RocketData.Bytes = RawData; DataLastUpdateTime = DateTime.UtcNow; DataStreamValid++; } catch (ArgumentException ex) { Console.WriteLine($@"Rocket Data Error: {ex.Message}"); DataStreamInvalid++; } } else if (rxChar == 0xFF) { if (DataIndex >= 8) { DataValid = true; } } else if (!DataValid) { DataIndex = 0; } } while (IsConnected && COMPort.BytesToRead > 0); }
private void OnCOMPortDataReceived(object sender, SerialDataReceivedEventArgs e) { do { var rxChar = Convert.ToByte(COMPort.ReadByte()); RawData[DataIndex++] = rxChar; if (DataIndex >= RawData.Length) { DataIndex = 0; } if (DataValid) { DataValid = false; try { //GSData.Bytes = _portDataRaw; DataLastUpdateTime = DateTime.UtcNow; DataStreamValid++; } catch (ArgumentException) { DataStreamInvalid++; } } else if (rxChar == 0xFF) { if (DataIndex >= 8) { DataValid = true; } } else { DataIndex = 0; } } while (COMPort.BytesToRead > 0); }