private static int ConvertLcdBaudRateToInt(LcdBaudRate baudRate) { if (!Enum.IsDefined(typeof(LcdBaudRate), baudRate)) { throw new ArgumentException($"Invalid baud rate specified, {(int)baudRate}", nameof(baudRate)); } return((int)baudRate); }
/// <summary> /// Set a new baud rate for communications with the LCD device. /// </summary> /// <remarks> /// Calling this method basically results in a reconnect of the serial port. The command /// is acknowledged and then the connection is reopened with the new baud rate. /// </remarks> /// <param name="baudRate">Only 19200 and 115200 are supported</param> public void SetBaudRate(LcdBaudRate baudRate) { ThrowIfNotConnected(); _baudRate = ConvertLcdBaudRateToInt(baudRate); var command = new CommandPacket(CommandType.SetBaudRate, 1, new[] { (byte)(baudRate == LcdBaudRate.Baud19200 ? 0 : 1) }); var response = _deviceConnection?.SendReceive(command); VerifyResponsePacket(response, CommandType.SetBaudRate); Disconnect(); Connect(); }
/// <summary> /// Change the baud rate of the display using the command interface. /// </summary> public void SetBaudRate(LcdBaudRate baudRate) { Send(new[] { ConfigurationCommandCharacter, (byte)baudRate }); }
public LcdDevice(string serialPortName, LcdBaudRate baudRate) { _serialPortName = serialPortName; _baudRate = ConvertLcdBaudRateToInt(baudRate); }