Esempio n. 1
0
 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);
 }
Esempio n. 2
0
        /// <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();
        }
Esempio n. 3
0
 /// <summary>
 ///     Change the baud rate of the display using the command interface.
 /// </summary>
 public void SetBaudRate(LcdBaudRate baudRate)
 {
     Send(new[] { ConfigurationCommandCharacter, (byte)baudRate });
 }
Esempio n. 4
0
 public LcdDevice(string serialPortName, LcdBaudRate baudRate)
 {
     _serialPortName = serialPortName;
     _baudRate       = ConvertLcdBaudRateToInt(baudRate);
 }