public Vc0706(IIODevice device, SerialPortName portName, int baud) { serialPort = device.CreateSerialPort(portName, baud); /*serialPort = device.CreateSerialMessagePort( * portName: portName, * suffixDelimiter: Encoding.ASCII.GetBytes("\r\n"), * baudRate: baud, * preserveDelimiter: true, * readBufferSize: 512);*/ serialPort.Open(); switch (baud) { case 9600: default: SetBaud9600(); break; case 19200: SetBaud19200(); break; case 38400: SetBaud38400(); break; case 57600: SetBaud57600(); break; } }
/// <summary> /// Create a new SerialTextFile and attach the instance to the specfied serial port. /// </summary> /// <param name="port">Serial port name.</param> /// <param name="baudRate">Baud rate.</param> /// <param name="parity">Parity.</param> /// <param name="dataBits">Data bits.</param> /// <param name="stopBits">Stop bits.</param> /// <param name="endOfLine">Text indicating the end of a line of text.</param> public SerialTextFile(IIODevice device, SerialPortName port, int baudRate, Parity parity, int dataBits, StopBits stopBits, string endOfLine) { serialPort = device.CreateSerialPort(port, baudRate, dataBits, parity, stopBits); LINE_END = endOfLine; serialPort.DataReceived += SerialPortDataReceived; }
/// <summary> /// Create a new SerialLcd object. /// </summary> /// <param name="config">TextDisplayConfig object defining the Lcd dimension (null will default to 16x2).</param> /// <param name="baudRate">Baud rate to use (default = 9600).</param> /// <param name="parity">Parity to use (default is None).</param> /// <param name="dataBits">Number of data bits (default is 8 data bits).</param> /// <param name="stopBits">Number of stop bits (default is one stop bit).</param> public SerialLcd(IIODevice device, SerialPortName port, TextDisplayConfig config = null, int baudRate = 9600, Parity parity = Parity.None, int dataBits = 8, StopBits stopBits = StopBits.One) { if (config == null) { // assume a 16x2 Lcd. DisplayConfig = new TextDisplayConfig() { Height = 2, Width = 16 }; } else { DisplayConfig = config; } comPort = device.CreateSerialPort(port, baudRate, dataBits, parity, stopBits); comPort.Open(); // configure the Lcd controller for the appropriate screen size byte lines = 0; byte characters = 0; switch (DisplayConfig.Width) { case 16: characters = (byte)LcdDimensions.Characters16Wide; break; case 20: characters = (byte)LcdDimensions.Characters20Wide; break; default: throw new ArgumentOutOfRangeException(nameof(config.Width), "Display width should be 16 or 20."); } switch (DisplayConfig.Height) { case 2: lines = (byte)LcdDimensions.Lines2; break; case 4: lines = (byte)LcdDimensions.Lines4; break; default: throw new ArgumentOutOfRangeException(nameof(config.Height), "Display height should be 2 or 4 lines."); } Send(new[] { ConfigurationCommandCharacter, characters, ConfigurationCommandCharacter, lines }); Thread.Sleep(10); }
public Hc06(IIODevice device, SerialPortName port, int baudRate = 921600) { _signal = new AutoResetEvent(false); _port = device.CreateSerialPort(port, baudRate, 8, Parity.None, StopBits.One); _port.DataReceived += (s, e) => { //Console.WriteLine("DataReceived - {0}!", _port.BytesToRead); if (_internalOp) { _signal.Set(); _internalOp = false; } else { DataReceived?.Invoke(this, new EventArgs()); } }; _internalOp = false; }
public Yx5300(IIODevice device, SerialPortName serialPortName) : this(device.CreateSerialPort( serialPortName)) { }
public Mb10x0(IIODevice device, SerialPortName portName) { serialPort = device.CreateSerialPort(portName, Baud); serialPort.Open(); }
public Vc0706(IIODevice device, SerialPortName serialPortName, int baudRate) { serialPort = device.CreateSerialPort(serialPortName, baudRate); _vc0706 = new Vc0706Core(); }