/// <summary> /// Send a fimrware command to the Arduino device /// </summary> /// <param name="command">Firmware command to send</param> public void SendCommand(FirmwareCommand command) { this.serialPort.DiscardInBuffer(); this.serialPort.DiscardOutBuffer(); this.serialPort.WriteLine(command.ToString()); Thread.Sleep(2000); }
/// <summary> /// Parse a base-64 string into a firmware command object /// </summary> /// <param name="text">Text to parse</param> /// <returns>Firmware command</returns> public static FirmwareCommand Parse(string text) { // get bytes from base-64 string byte[] bytes = Convert.FromBase64String(text); // create struct pointer FirmwareSettings settings = bytes; // create firmware command base on settings struct FirmwareCommand command = new FirmwareCommand(settings); return(command); }
/// <summary> /// Retrieve settings from Arduino device asynchronously /// </summary> public void RetrieveSettings() { // this.SendCommand(FirmwareCommand.ExportSettings); // string text = this.serialPort.ReadExisting().Trim(); if (string.IsNullOrWhiteSpace(text)) { throw new IOException("Failed to retrieve settings response from Arduino device"); } // FirmwareCommand command = FirmwareCommand.Parse(text); this.Settings = command.Settings; return; }
static FirmwareCommand() { FirmwareCommand.Discovery = new FirmwareCommand("ID;"); FirmwareCommand.ExportSettings = new FirmwareCommand("ES;"); return; }