public override void SendMessage(CNCMessage message, bool logging = true) { if (AutoPoll) { MessageBuffer.Add(message); OnMessageSent(this, message); } else { try { SerialInterface.WriteLine(message.Message); } catch (InvalidOperationException ex) { AddToSendReceiveBuffer(ex.Message); return; } } if (logging) { AddToSendReceiveBuffer(message.Message); } }
public void ParseMessage(string message) { MessageType messageType = ClassifyMessage(message); if (messageType == MessageType.Spot) { //If add spot //1. Process it. //2. Delete any Matching Call and Band //3. Add it. //Notes: In the case that another contact that shares multipliers is made, you get an Add which is really an update, with the reduced mult status //Notes: When you Spot s = new Spot(message); LogAction("Del/Add", s); DeleteSpot(s); AddSpot(s); } else if (messageType == MessageType.SpotDelete || messageType == MessageType.SpotDupe) { //If delete, or dupe, then parse the Spot delete it. Spot s = new Spot(message, true); LogAction("Del", s); DeleteSpot(s); } else if (messageType == MessageType.Contact) { //If Contact, then parse the Contact and delete it. Contact c = new Contact(message); LogAction("Contact", c); DeleteSpot(c); } MessageBuffer.Add($"{DateTime.Now.ToString("yyyy-dd-mm HH:mm:ss.ffffff")} | {Regex.Replace(message, @"\t|\n|\r", "")}"); BufferUpdate?.Invoke(this, new SpotAnalysisUpdatedEventArgs()); }
private void SerialPort_DataReceived(object sender, SerialDataReceivedEventArgs e) { try { while (byteBuf != -1) { if ((byteBuf = (sender as SerialPort).ReadByte()) == 0x10) { byteBuf = (sender as SerialPort).ReadByte(); if (byteBuf == 0x02) { MessageStarted = true; } else if (byteBuf == 0x03) { MessageEnded = true; } else if (byteBuf == 0x08) { MessageStarted = false; MessageEnded = true; } } if (MessageStarted) { MessageBuffer.Add((byte)byteBuf); } if (MessageStarted && MessageEnded) { MessageStarted = false; MessageEnded = false; Message msg = new Message(MessageBuffer.ToArray()); if (LogRawIncomingCompleteMessage != null) { LogRawIncomingCompleteMessage(this, new RawBytesEventArgs(MessageBuffer.ToArray())); } if (LogIncomingMessage != null) { LogIncomingMessage(this, new MessageEventArgs(msg)); } if (ReceivedMessage != null) { ReceivedMessage(this, new MessageEventArgs(msg)); } MessageBuffer = new List <byte>(); } else if (!MessageStarted && MessageEnded) { if (LogRawIncomingIncompleteMessage != null) { LogRawIncomingIncompleteMessage(this, new RawBytesEventArgs(MessageBuffer.ToArray())); } MessageEnded = false; MessageBuffer = new List <byte>(); } } } catch (Exception ex) { if (OnError != null) { OnError(this, new System.IO.ErrorEventArgs(ex)); } else { throw ex; } } }