genielabs / HomeGenie

HomeGenie, the programmable automation intelligence
https://homegenie.it
GNU General Public License v3.0
389 stars 155 forks source link

SerialPortHelper.cs Fix #314

Closed JimFx closed 7 years ago

JimFx commented 7 years ago

Hi,i have a fix for the SerialPortHelper.cs in the fonction SerialPort_MessageReceived the textmessage is droped if the textMessage not contain the textEndOfLine

private void SerialPort_MessageReceived(object sender, MessageReceivedEventArgs args) { if (dataReceived != null) { dataReceived(args.Data); } if (stringReceived != null) { string textMessage = textBuffer + Encoding.UTF8.GetString(args.Data); if (String.IsNullOrEmpty(textEndOfLine[0])) { // raw string receive try { stringReceived(textMessage); } catch { } } else { // text line based string receive textBuffer = ""; if (textMessage.Contains(textEndOfLine[0])) { string[] lines = textMessage.Split(textEndOfLine, StringSplitOptions.RemoveEmptyEntries); for (int l = 0; l < lines.Length - (textMessage.EndsWith(textEndOfLine[0]) ? 0 : 1); l++) { try { stringReceived(lines[l]); } catch { } } if (!textMessage.EndsWith(textEndOfLine[0])) { textBuffer = lines[lines.Length - 1]; } } else { textBuffer = textMessage; } } } }

genemars commented 7 years ago

Fix applied. Thanks.