private static void ExecuteAutoBootStrap(ArduinoModel arduinoModel, string portName) { logger.Info("Executing AutoBootStrap!"); logger.Info("Deploying protocol version {0}.{1}.", CurrentProtocolMajorVersion, CurrentProtocolMinorVersion); logger.Debug("Reading internal resource stream with Arduino Listener HEX file..."); var assembly = Assembly.GetExecutingAssembly(); var textStream = assembly.GetManifestResourceStream( string.Format(ArduinoListenerHexResourceFileName, arduinoModel)); if (textStream == null) { throw new IOException("Unable to configure auto bootstrap, embedded resource missing!"); } var hexFileContents = new List <string>(); using (var reader = new StreamReader(textStream)) while (reader.Peek() >= 0) { hexFileContents.Add(reader.ReadLine()); } logger.Debug("Uploading HEX file..."); var uploader = new ArduinoSketchUploader(new ArduinoSketchUploaderOptions { PortName = portName, ArduinoModel = arduinoModel }); uploader.UploadSketch(hexFileContents); }
/// <summary> /// Creates a new ArduinoDriver instance. The relevant portname will be autodetected if possible. /// </summary> /// <param name="arduinoModel"></param> /// <param name="autoBootstrap"></param> public static async Task <ArduinoDriver> CreateAsync(ArduinoModel arduinoModel, bool autoBootstrap = false) { logger.Info( "Instantiating ArduinoDriver (model {0}) with autoconfiguration of port name...", arduinoModel); var possiblePortNames = SerialPortStream.GetPortNames().Distinct(); string unambiguousPortName = null; try { unambiguousPortName = possiblePortNames.SingleOrDefault(); } catch (InvalidOperationException) { // More than one posible hit. } if (unambiguousPortName == null) { throw new IOException( "Unable to autoconfigure ArduinoDriver port name, since there is not exactly a single " + "COM port available. Please use the ArduinoDriver with the named port constructor!"); } var arduinoDriver = new ArduinoDriver(); await arduinoDriver.InitializeAsync(new ArduinoDriverConfiguration { ArduinoModel = arduinoModel, PortName = unambiguousPortName, AutoBootstrap = autoBootstrap }); return(arduinoDriver); }
private static void ExecuteAutoBootStrap(ArduinoModel arduinoModel, string portName) { Assembly assembly = Assembly.GetExecutingAssembly(); Stream textStream = assembly.GetManifestResourceStream(string.Format(arduinoListenerHexResourceFileName, arduinoModel)); if (textStream == null) { throw new IOException("Unable to configure auto bootstrap, embedded resource missing!"); } var hexFileContents = new List <string>(); using (var reader = new StreamReader(textStream)) { while (reader.Peek() >= 0) { hexFileContents.Add(reader.ReadLine()); } } var uploader = new ArduinoSketchUploader( new ArduinoSketchUploaderOptions { PortName = portName, ArduinoModel = arduinoModel } ); uploader.UploadSketch(hexFileContents); }
private async Task Connect() { ArduinoModel model = SelectedModel; String port = SelectedPort; _driver = await ArduinoDriver.ArduinoDriver.CreateAsync(model, port); }
/// <summary> /// Creates a new ArduinoDriver instance. The relevant port name will be auto-detected if possible. /// </summary> /// <param name="arduinoModel"></param> /// <param name="autoBootstrap"></param> public ArduinoDriver(ArduinoModel arduinoModel, bool autoBootstrap = false) { IEnumerable <string> possiblePortNames = SerialPortStream.GetPortNames().Distinct(); string unambiguousPortName = null; try { unambiguousPortName = possiblePortNames.SingleOrDefault(); } catch (InvalidOperationException) { // More than one possible hit. } if (unambiguousPortName == null) { throw new IOException( "Unable to autoconfigure ArduinoDriver port name, since there is not exactly a single " + "COM port available. Please use the ArduinoDriver with the named port constructor!" ); } Initialize( new ArduinoDriverConfiguration { ArduinoModel = arduinoModel, PortName = unambiguousPortName, AutoBootstrap = autoBootstrap } ); }
private void InitializeWithAutoBootstrap() { bool alwaysReDeployListener = alwaysRedeployListeners.Count > 500; HandShakeResponse handshakeResponse; var handShakeAckReceived = false; var handShakeIndicatesOutdatedProtocol = false; if (!alwaysReDeployListener) { InitializePort(); handshakeResponse = ExecuteHandshake(); handShakeAckReceived = handshakeResponse != null; if (handShakeAckReceived) { const int currentVersion = currentProtocolMajorVersion * 10 + currentProtocolMinorVersion; int listenerVersion = handshakeResponse.ProtocolMajorVersion * 10 + handshakeResponse.ProtocolMinorVersion; handShakeIndicatesOutdatedProtocol = currentVersion > listenerVersion; if (handShakeIndicatesOutdatedProtocol) { port.Close(); port.Dispose(); } } else { port.Close(); port.Dispose(); } } // If we have received a handshake ack, and we have no need to upgrade, simply return. if (handShakeAckReceived && !handShakeIndicatesOutdatedProtocol) { return; } ArduinoModel arduinoModel = config.ArduinoModel; // At this point we will have to redeploy our listener var stopwatch = new Stopwatch(); stopwatch.Start(); ExecuteAutoBootStrap(arduinoModel, config.PortName); stopwatch.Stop(); // Now wait a bit, since the bootstrapped Arduino might still be restarting ! int graceTime = rebootGraceTimes.ContainsKey(arduinoModel) ? rebootGraceTimes[arduinoModel] : defaultRebootGraceTime; Thread.Sleep(graceTime); // Listener should now (always) be deployed, handshake should yield success. InitializePort(); handshakeResponse = ExecuteHandshake(); if (handshakeResponse == null) { throw new IOException("Unable to get a handshake ACK after executing auto bootstrap on the Arduino!"); } }
/// <summary> /// Creates a new ArduinoDriver instance for a specified portName. /// </summary> /// <param name="arduinoModel"></param> /// <param name="portName">The COM portname to create the ArduinoDriver instance for.</param> /// <param name="autoBootStrap">Determines if an listener is automatically deployed to the Arduino if required.</param> public ArduinoDriver(ArduinoModel arduinoModel, string portName) { Initialize(new ArduinoDriverConfiguration { ArduinoModel = arduinoModel, PortName = portName }); }
/// <summary> /// Creates a new ArduinoDriver instance for a specified portName. /// </summary> /// <param name="arduinoModel"></param> /// <param name="portName">The COM portname to create the ArduinoDriver instance for.</param> /// <param name="autoBootStrap">Determines if an listener is automatically deployed to the Arduino if required.</param> public ArduinoDriver(ArduinoModel arduinoModel, string portName, bool autoBootstrap = false) { Initialize(new ArduinoDriverConfiguration { ArduinoModel = arduinoModel, PortName = portName, AutoBootstrap = autoBootstrap }); }
private ArduinoModel createArduinoModelFromDB(MyDBModels.Arduino arduino) { ArduinoModel model = new ArduinoModel(); model.ArduinoId = arduino.ArduinoId; model.Name = arduino.Name; model.Mac = arduino.Mac; return(model); }
/// <summary> /// Creates a new ArduinoDriver instance for a specified portName. /// </summary> /// <param name="arduinoModel"></param> /// <param name="portName">The COM portname to create the ArduinoDriver instance for.</param> /// <param name="autoBootstrap">Determines if an listener is automatically deployed to the Arduino if required.</param> public static async Task <ArduinoDriver> CreateAsync(ArduinoModel arduinoModel, string portName, bool autoBootstrap = false) { var arduinoDriver = new ArduinoDriver(); await arduinoDriver.InitializeAsync(new ArduinoDriverConfiguration { ArduinoModel = arduinoModel, PortName = portName, AutoBootstrap = autoBootstrap }); return(arduinoDriver); }
private void ExecuteAutoBootStrap(ArduinoModel arduinoModel) { logger.Info("Executing AutoBootStrap!"); logger.Info("Deploying protocol version {0}.{1}.", CurrentProtocolMajorVersion, CurrentProtocolMinorVersion); var portName = port.PortName; logger.Debug("Closing port {0}...", portName); port.Close(); logger.Debug("Reading internal resource stream with Arduino Listener HEX file..."); var assembly = Assembly.GetExecutingAssembly(); var textStream = assembly.GetManifestResourceStream( string.Format(ArduinoListenerHexResourceFileName, arduinoModel)); if (textStream == null) { throw new IOException("Unable to configure auto bootstrap, embedded resource missing!"); } var hexFileContents = new List <string>(); using (var reader = new StreamReader(textStream)) while (reader.Peek() >= 0) { hexFileContents.Add(reader.ReadLine()); } logger.Debug("Uploading HEX file..."); var uploader = new ArduinoSketchUploader(new ArduinoSketchUploaderOptions { PortName = portName, ArduinoModel = arduinoModel }); uploader.UploadSketch(hexFileContents); logger.Debug("Reopening port {0}...", portName); port.Open(); // Now wait a bit, the Arduino might still be restarting! Thread.Sleep(GraceTimeAfterArduinoAutoBootStrap); // After bootstrapping, check if we can succesfully handshake ... var response = port.Send(new HandShakeRequest()); var handshakeResponse = response as HandShakeResponse; if (handshakeResponse == null) { throw new IOException("Unable to get a handshake ACK after executing auto bootstrap on the Arduino!"); } logger.Info("Arduino (auto)bootstrapped succesfully!"); }
public void uploadSketch(string Filename, ArduinoModel model, string port, int baudrate) { _uploaderClass = new uploaderClass(Filename, port, model); ArduinoSketchUploader uploader = new ArduinoSketchUploader( new ArduinoSketchUploaderOptions() { FileName = Filename, PortName = port, ArduinoModel = model }); uploader.UploadSketch(); }
public void uploadCheckSketch(string port, ArduinoModel model, int baudrate) { string filePath = "checkSktech.ino.eightanaloginputs.hex"; ArduinoSketchUploader uploader = new ArduinoSketchUploader( new ArduinoSketchUploaderOptions() { FileName = filePath, PortName = port, ArduinoModel = model }); uploader.UploadSketch(); }
public void addArduino(int userId, ArduinoModel model) { var db = new MyDBModels.DB(); MyDBModels.Arduino arduinoModel = new MyDBModels.Arduino(); arduinoModel.Name = model.Name; arduinoModel.Mac = model.Mac; db.arduino.Add(arduinoModel); db.SaveChanges(); var arduinoArrayId = db.user.Where(u => u.UserId == userId).First().ArduinoIdArray.ToList(); arduinoArrayId.Add(db.arduino.OrderByDescending(a => a.ArduinoId).FirstOrDefault().ArduinoId); db.user.Where(u => u.UserId == userId).First().ArduinoIdArray = arduinoArrayId.ToArray(); db.SaveChanges(); }
private void setEkran(ArduinoModel model) { lbl_derece.Text = model.Derece + "°"; int kapıMesafe = int.Parse(model.Mesafe); if (kapıMesafe < 0) { kapıMesafe = 100; } if (kapıMesafe < 4) { lbl_kapıState.Text = "Kapalı"; } else { lbl_kapıState.Text = "Açık"; } lbl_uyariDerece.Text = model.UyariDerece + "°"; try { var ortalamaList = db.OLCUM.Where(x => x.TARIH >= DateTime.Today).ToList(); List <float> listim = new List <float>(); foreach (var item in ortalamaList) { if (!item.DERECE.Contains("-") && item.DERECE != "" && item.DERECE != null) { if (item.DERECE.Contains(".")) { listim.Add(float.Parse(item.DERECE.Replace(".", ","))); } else { listim.Add(float.Parse(item.DERECE)); } } } var ortalama = System.Math.Round(listim.Average(), 2);; lbl_Ortalama.Text = ortalama + "°"; } catch (Exception) { } }
public static string GetWiringDiagram(ArduinoModel model, MotorShieldType type) { string wiringDiagram = "pack://application:,,,/Resources/dcc-ex-logo.png"; switch (model) { case ArduinoModel.Mega2560: switch (type) { case MotorShieldType.Arduino: wiringDiagram = "pack://application:,,,/Resources/mega-arduino.png"; break; case MotorShieldType.Pololu: wiringDiagram = "pack://application:,,,/Resources/mega-pololu.png"; break; case MotorShieldType.BTS7960B: wiringDiagram = "pack://application:,,,/Resources/dcc-ex-logo.png"; break; } break; case ArduinoModel.UnoR3: switch (type) { case MotorShieldType.Arduino: wiringDiagram = "pack://application:,,,/Resources/uno-arduino.png"; break; case MotorShieldType.Pololu: wiringDiagram = "pack://application:,,,/Resources/uno-pololu.png"; break; case MotorShieldType.BTS7960B: wiringDiagram = "pack://application:,,,/Resources/dcc-ex-logo.png"; break; } break; } return(wiringDiagram); }
private static void UploadSketch(ArduinoModel arduinoModel, string hexFilePath, string comPortName) { if (!File.Exists(hexFilePath)) { Plugin.HostInstance.triggerEvent( "Serial.Upload.Error", new List <string> { ".hex sketch file doesn't exists." } ); return; } // upload sketch try { new ArduinoSketchUploader( new ArduinoSketchUploaderOptions { ArduinoModel = arduinoModel, FileName = hexFilePath, PortName = comPortName } ).UploadSketch(); } catch (Exception ex) { Plugin.HostInstance.triggerEvent( "Serial.Upload.Error", new List <string> { ex.ToString() } ); return; } Plugin.HostInstance.triggerEvent( "Serial.Upload.Success", new List <string>() ); }
private void Initialize(ArduinoModel arduinoModel, 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(arduinoModel); } 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(arduinoModel); } } }
/// <summary> /// Creates a new ArduinoDriver instance. The relevant portname will be autodetected if possible. /// </summary> /// <param name="arduinoModel"></param> /// <param name="autoBootstrap"></param> public ArduinoDriver(ArduinoModel arduinoModel, bool autoBootstrap = false) { logger.Info( "Instantiating ArduinoDriver (model {0}) with autoconfiguration of port name...", arduinoModel); var possiblePortNames = SerialPort.GetPortNames().Distinct(); string unambiguousPortName = null; try { unambiguousPortName = possiblePortNames.SingleOrDefault(); } catch (InvalidOperationException) { // More than one posible hit. } if (unambiguousPortName == null) { throw new IOException("Unable to autoconfigure ArduinoDriver port name, since there is not exactly a single COM port available. Please use the " + "ArduinoDriver with the named port constructor!"); } Initialize(arduinoModel, unambiguousPortName, autoBootstrap); }
public uploaderClass(string filename, string portname, ArduinoModel model) { this.filename = filename; this.portname = portname; this.model = model; }
public Board(string name, ArduinoModel platform, string fqbn) { Name = name; Platform = platform; FQBN = fqbn; }
private static void ExecuteAutoBootStrap(ArduinoModel arduinoModel, string portName) { throw new NotImplementedException(); }
public static Arduino GetModelOptions(ArduinoModel model) { return(ReadConfiguration().Arduinos.SingleOrDefault( x => x.Model.Equals(model.ToString(), StringComparison.OrdinalIgnoreCase))); }
public void addArduinoLogic(int userId, ArduinoModel model) { dataAccesss.addArduino(userId, model); }
public void addArduino(ArduinoModel model) { AuthorizationUtils authorization = new AuthorizationUtils(Request); logic.addArduinoLogic(authorization.getUserId(), model); }
public void Init(string Filename, ArduinoModel model, string port, int baudrate) { uploader = new uploaderClass(Filename, port, model); uploader.upload(); }
private void arduinoDevice_SelectedValueChanged(object sender, EventArgs e) { Model = (ArduinoModel)arduinoDevice.SelectedItem; }
/// <summary> /// Creates a new ArduinoDriver instance for a specified portName. /// </summary> /// <param name="arduinoModel"></param> /// <param name="portName">The COM portname to create the ArduinoDriver instance for.</param> /// <param name="autoBootStrap">Determines if an listener is automatically deployed to the Arduino if required.</param> public ArduinoDriver(ArduinoModel arduinoModel, string portName, bool autoBootStrap = false) { Initialize(arduinoModel, portName, autoBootStrap); }