public void ConnectSimulator() { if (String.IsNullOrEmpty(SimulatorPort)) { throw new Exception("The 'SimulatorPort' property has not been set."); } if (SimulatorBaudRate == 0) { throw new Exception("The 'SimulatorBaudRate' property has not been set."); } Console.WriteLine("Enabling simulator hardware device..."); SimulatorClient = new ArduinoSerialDevice(SimulatorPort, SimulatorBaudRate); try { SimulatorClient.Connect(); } catch (IOException ex) { HandleConnectionIOException("simulator", SimulatorPort, SimulatorBaudRate, ex); } SimulatorIsEnabled = true; EnsureSimulatorIsNotResettingDevice(); Console.WriteLine(""); }
static void Main(string[] args) { string portName = string.Empty; foreach (string s in System.IO.Ports.SerialPort.GetPortNames()) { if (s.ToLower().Contains("com")) { portName = s; } } if (string.IsNullOrEmpty(portName)) { Console.WriteLine("Port Not exists"); return; } ArduinoSerialDevice device = new ArduinoSerialDevice(portName, 9600); device.Connect(); DataStore ds = new DataStore(); ds.ScreenMode = ScreenMode.Add; while (true) { string data = device.AnalogRead(3).ToString(); if (!string.IsNullOrEmpty(data)) { ds.DataValue = data; ds.Commit(); Console.WriteLine(data); } } }