public ArduinoControl(AutoResetEvent autoEvent, CancellationTokenSource cancellation) { m_autoEvent = autoEvent; port = new SerialPort(); arduinoSettings = new ArduinoSettings(); Cancellation = cancellation; }
public ArduinoButton(ArduinoSettings settings, ILogger logger) { this._settings = settings ?? throw new ArgumentNullException(nameof(settings)); _logger = logger ?? throw new ArgumentNullException(nameof(logger)); if (string.IsNullOrEmpty(settings.PortName)) { throw new ArgumentNullException(nameof(settings.PortName)); } if (settings.BaudRate == default) { throw new ArgumentNullException(nameof(settings.BaudRate)); } _lazyPort = new Lazy <SerialPort>(() => { var port = new SerialPort { PortName = settings.PortName, BaudRate = settings.BaudRate, }; port.DataReceived += RecieveMessage; //port.Open(); return(port); }); }
public MuteButton Create(ArduinoSettings settings) { if (settings == null || string.IsNullOrEmpty(settings.PortName) || settings.BaudRate == default) { _logger.LogInformation("Creating null mute button."); return(new NullMuteButton()); } _logger.LogInformation("Creating arduino button."); return(new ArduinoButton(settings, _logger)); }
protected void InitSerial(ArduinoSettings settings = null) { if (settings == null) this._serialSettings = settings; Debug.Log("[ArduinoBase] Got settings: " + this._serialSettings.SerialPort + " " + this._serialSettings.ReadTimeout); // Create a new SerialPort object. _serialPort = new SerialPort (this._serialSettings.SerialPort, 115200); _serialPort.ReadTimeout = this._serialSettings.ReadTimeout; _serialPort.Open (); // Spawn thread to read from Arduino _serialThread = new Thread(_readSerial); _serialThread.Start(); }
protected void InitSerial(ArduinoSettings settings = null) { if (settings == null) { this._serialSettings = settings; } Debug.Log("[ArduinoBase] Got settings: " + this._serialSettings.SerialPort + " " + this._serialSettings.ReadTimeout); // Create a new SerialPort object. _serialPort = new SerialPort(this._serialSettings.SerialPort, 115200); _serialPort.ReadTimeout = this._serialSettings.ReadTimeout; _serialPort.Open(); // Spawn thread to read from Arduino _serialThread = new Thread(_readSerial); _serialThread.Start(); }