private void SerialPort_DataReceived() { int pos = 0; lock (input) { input.Append(serialPort.ReadStr()); while (input.Length > 0 && (pos = input.ToString().IndexOf('\n')) > 0) { Reply = input.ToString(0, pos - 1); input.Remove(0, pos + 1); #if RESPONSELOG log.WriteLine(Reply); log.Flush(); #endif if (Reply.Length != 0 && DataReceived != null) { Dispatcher.BeginInvoke(DataReceived, Reply); } state = Reply == "ok" ? Comms.State.ACK : (Reply.StartsWith("error") ? Comms.State.NAK : Comms.State.DataReceived); } } }
private void SerialPort_DataReceived() { int pos = 0; lock (input) { input.Append(serialPort.ReadStr()); if (EventMode) { while (input.Length > 0 && (pos = gp()) > 0) { Reply = pos == 0 ? string.Empty : input.ToString(0, pos - 1); input.Remove(0, pos + 1); #if RESPONSELOG if (log != null) { log.WriteLine(Reply); log.Flush(); } #endif if (Reply.Length != 0 && DataReceived != null) { Dispatcher.BeginInvoke(DataReceived, Reply); } state = Reply == "ok" ? Comms.State.ACK : (Reply.StartsWith("error") ? Comms.State.NAK : Comms.State.DataReceived); } } else { ByteReceived?.Invoke(ReadByte()); } } }