public void OnDataReceived(object sender, SerialReceivedEventArgs e) { if (DataReceived != null) { DataReceived(this, e); } }
private void Port_ReceivedEvent(object sender, SerialReceivedEventArgs e) { while (Port.BytesToRead > 0) { if (processCOM()) { switch (id) { case HSPid: HPacket = (HandShakePacket)ByteArrayToStructure(buffer, HPacket); Invoke("HandShake", 0); if ((HPacket.M1 == 3) && (HPacket.M2 == 1) && (HPacket.M3 == 4)) { DisplayFound = true; } else { DisplayFound = false; } break; case Cid: VesselControls(); //Invoke("VesselControls", 0); break; default: Invoke("Unimplemented", 0); break; } } } }
void serialPort_ReceivedEvent(object sender, SerialReceivedEventArgs e) { #if DEBUG logger.Debug("Serial port data received"); #endif byte[] bytes = new byte[serialPort.BytesToRead]; serialPort.Read(bytes, 0, bytes.Length); #if DEBUG logger.Debug($"Equeuing data = {bytes}"); #endif foreach (byte b in bytes) { receivedData.Enqueue(b); } ProcessData(); }
private void Serial_ReceivedEvent(object sender, SerialReceivedEventArgs e) { int b; while ((b = Serial.ReadByte()) != -1) { LastBytes.Enqueue((byte)b); } while (ParsePacket()) { ; } bool ParsePacket() { if (LastBytes.Count < 3) { return(false); } var bs = new byte[3]; for (int i = 0; i < 3; i++) { bs[i] = LastBytes.Dequeue(); } if (bs[3] == 255) { OnPacketReceived(new Packet(bs[0], bs[1])); return(true); } return(false); } }