private static void Main(string[] args) { var connection = new MonoSerialConnection(args[0], SerialBaudRate.Bps_57600); var session = new ArduinoSession(connection, 250); session.MessageReceived += (sender, eventArgs) => HandleMessageReceived(eventArgs); session.OneWireReplyReceived += (sender, eventArgs) => HandleOneWireReplyReceived(eventArgs); Console.WriteLine("Waiting for FirmwareResponse"); ResetEvent.WaitOne(); Console.WriteLine("Setting digital pinmode"); session.SetDigitalPinMode(2, PinMode.OneWire); Console.WriteLine("Sending 1-Wire search"); session.SendOneWireSearch(); Console.WriteLine("Waiting for OneWire search reply"); ResetEvent.WaitOne(); Console.WriteLine("Sending sensor read"); session.SensOneWireSensorRead(sensorAddress); Console.ReadLine(); connection.Close(); Console.WriteLine("Done!"); }
private static ISerialConnection FindConnection(Func <ArduinoSession, bool> isDeviceAvailable, string[] portNames, SerialBaudRate[] baudRates) { for (int x = portNames.Length - 1; x >= 0; x--) { foreach (SerialBaudRate rate in baudRates) { try { using (var connection = new EnhancedSerialConnection(portNames[x], rate)) { using (var session = new ArduinoSession(connection, 100)) { Debug.WriteLine("{0}:{1}; ", portNames[x], (int)rate); if (isDeviceAvailable(session)) { return(new EnhancedSerialConnection(portNames[x], rate)); } } } } catch (UnauthorizedAccessException) { // Port is not available. Debug.WriteLine("{0} NOT AVAILABLE; ", portNames[x]); break; } catch (TimeoutException) { // Baudrate or protocol error. } } } return(null); }
public void TestMethod1() { var x = new ArduinoSession(new MockSerialConnection()); var tracker = x.CreateAnalogStateMonitor(); }
private static ISerialConnection FindConnection(Func <ArduinoSession, bool> isDeviceAvailable, string[] portNames, SerialBaudRate[] baudRates) { bool found = false; for (int x = portNames.Length - 1; x >= 0; x--) { foreach (SerialBaudRate rate in baudRates) { try { using (var connection = new EnhancedSerialConnection(portNames[x], rate)) { using (var session = new ArduinoSession(connection, 100)) { #if TRACE Debug.WriteLine("{0}:{1}; ", portNames[x], (int)rate); #endif if (isDeviceAvailable(session)) { found = true; } } } if (found) { return(new EnhancedSerialConnection(portNames[x], rate)); } } catch (UnauthorizedAccessException) { // Port is not available. #if TRACE Debug.WriteLine("{0} NOT AVAILABLE; ", portNames[x]); #endif break; } catch (TimeoutException) { // Baudrate or protocol error. } catch (IOException ex) { #if TRACE Debug.WriteLine($"HResult 0x{ex.HResult:X} - {ex.Message}"); #endif } } } return(null); }
private static ISerialConnection FindConnection(Func<ArduinoSession, bool> isDeviceAvailable, string[] portNames, SerialBaudRate[] baudRates) { for (int x = portNames.Length - 1; x >= 0; x--) { foreach (SerialBaudRate rate in baudRates) { try { using (var connection = new EnhancedSerialConnection(portNames[x], rate)) { using (var session = new ArduinoSession(connection, 100)) { Debug.WriteLine("{0}:{1}; ", portNames[x], (int)rate); if (isDeviceAvailable(session)) return new EnhancedSerialConnection(portNames[x], rate); } } } catch (UnauthorizedAccessException) { // Port is not available. Debug.WriteLine("{0} NOT AVAILABLE; ", portNames[x]); break; } catch (TimeoutException) { // Baudrate or protocol error. } } } return null; }
private IStringProtocol CreateSerialSession(ISerialConnection connection, int timeout = -1) { var session = new ArduinoSession(connection); session.TimeOut = timeout; session.MessageReceived += (o, e) => { Assert.Fail("MessageReceived event triggered"); }; session.AnalogStateReceived += (o, e) => { Assert.Fail("AnalogStateReceived event triggered"); }; session.DigitalStateReceived += (o, e) => { Assert.Fail("DigitalStateReceived event triggered"); }; session.I2CReplyReceived += (o, e) => { Assert.Fail("I2CReplyReceived event triggered"); }; session.StringReceived += (o, e) => { Console.WriteLine("Received: '{0}'", e.Text); }; return session; }
public ArduinoOne(ArduinoSession session) { _s = session; PCCaseLEDs = new DigitalOutputPin(6, _s); MonitorLEDs = new DigitalOutputPin(7, _s); }
public Pin(int pinNumber, ArduinoSession session) { _pinNumber = pinNumber; _s = session; }