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(); } } }
/// <summary> /// Sends an ArduinoRequest to the Arduino, and returns the corresponding ArduinoResponse object. /// </summary> /// <param name="request">The ArduinoRequest request object to send.</param> /// <returns>The ArduinoResponse response object.</returns> public ArduinoResponse Send(ArduinoRequest request) { return(port.Send(request)); }
private ArduinoResponse InternalSend(ArduinoRequest request) { return(port.Send(request)); }