void _serialPort_DataReceived(object sender, SerialComPort.Events.DataEventArgs e) { //Only Receive incoming Messages //All other messages are received in MessageReceived()-Event _dataReceived += String.IsNullOrEmpty(_dataReceived) ? e.Data : " " + e.Data; var result = Emulator.HandleRequest(_dataReceived); switch (result.Type) { case Emulator.ResponseType.Empty: case Emulator.ResponseType.Incomplete: //Nothing break; case Emulator.ResponseType.ChecksumNotOk: case Emulator.ResponseType.Error: case Emulator.ResponseType.RegisterUnknown: //Respond Error case Emulator.ResponseType.Ok: _serialPort.Send(result.Value); _dataReceived = string.Empty; break; case Emulator.ResponseType.NoCommonStartChar: //Delete Overhead Data from Buffer, when containing no Start-char case Emulator.ResponseType.WrongReceiver: //Ignore _dataReceived = string.Empty; break; } }
void serial_DataReceived(object sender, SerialComPort.Events.DataEventArgs e) { _response += String.IsNullOrEmpty(_response) ? e.Data : " " + e.Data; //Assert.AreEqual(e.Data, "81 11 F1 81 04"); Console.WriteLine("{0}:\t{1}", "Incoming", e.Data); }