private void InitializePort() { var serialEngine = serialFunc(); var portName = serialEngine.PortName; var baudRate = serialEngine.BaudRate; logger.Debug("Initializing port {0} - {1}...", portName, baudRate); serialEngine.WriteTimeout = 200; serialEngine.ReadTimeout = 500; port = new ArduinoDriverSerialPort(serialEngine); port.Open(); }
private void InitializePort() { var engine = engineFunc(); var portName = engine.PortName; var baudRate = engine.BaudRate; logger.Debug("Initializing port {0} - {1}...", portName, baudRate); engine.WriteTimeout = 100; engine.ReadTimeout = 100; port = new ArduinoDriverSerialPort(engine); port.Open(); System.Threading.Thread.Sleep(1000); }
private void Initialize(string portName, bool autoBootStrap) { logger.Info("Instantiating ArduinoDriver for port {0}...", portName); port = new ArduinoDriverSerialPort(portName, 115200); port.Open(); logger.Info("Initiating handshake..."); var response = port.Send(new HandShakeRequest()); var handshakeResponse = response as HandShakeResponse; if (handshakeResponse == null) { logger.Info("Received null for handshake (timeout?)."); if (!autoBootStrap) { throw new IOException( string.Format( "Unable to get a handshake ACK when sending a handshake request to the Arduino on port {0}. " + "Pass 'true' for optional parameter autoBootStrap in one of the ArduinoDriver constructors to automatically configure the Arduino (please " + "note: this will overwrite the existing sketch on the Arduino).", portName)); } ExecuteAutoBootStrap(); } else { logger.Info("Handshake ACK Received ... checking if we need to upgrade!"); const float currentVersion = (float)CurrentProtocolMajorVersion + (float)CurrentProtocolMinorVersion / 10; var listenerVersion = handshakeResponse.ProtocolMajorVersion + (float)handshakeResponse.ProtocolMinorVersion / 10; logger.Info("Current ArduinoDriver C# Protocol: {0}.", currentVersion); logger.Info("Arduino Listener Protocol Version: {0}.", listenerVersion); var upgradeNeeded = currentVersion > listenerVersion; logger.Info("Upgrade neede: {0}", upgradeNeeded); if (upgradeNeeded) { ExecuteAutoBootStrap(); } } }