protected bool WaitForMessage(HHSerial waitFor, int timeoutMs = Serial.DefaultReadTimeoutMs) { this.SerialPort.ReadTimeout = timeoutMs; HHSerial reply = HHSerial.UNKNOWN; try { reply = (HHSerial)this.SerialPort.ReadByte(); } catch (TimeoutException) { throw; } if (reply == waitFor) { return(true); } switch (reply) { case HHSerial.ERROR: return(false); case HHSerial.FAULT: throw new ApplicationException("The device has faulted. Cannot continue."); default: throw new InvalidOperationException($"An unexpected reply was received. Expected: 0x{waitFor:X}[{(HHSerial)waitFor}]. Actual: 0x{reply:X}[{(HHSerial)reply}]"); } }
protected void Send(HHSerial message) { Serial.WriteBuffer[0] = (byte)message; this.SerialPort.Write(Serial.WriteBuffer, 0, 1); }