public BreweryCommands() { arduino = new ArduinoCommands(device = new LSPProtocol(new SimplePacketProtocolPacketEncoder())); hardwareSettings = new HardwareSettings(); brewery = new Brewery(); ProcessSettings = new Process.settings(); Messenger.Default.Register<AnalogReturn>(this, "VolumeUpdate", VolumeUpdate_MessageReceived); Messenger.Default.Register<DigitalReturn>(this, DigitalReturn_MessageReceived); Messenger.Default.Register<HardwareSettings>(this, "HardwareSettingsUpdate", UpdateHardwareSettings); Messenger.Default.Register<Probes>(this, "TemperatureUpdate", TemperatureUpdate_MessageReceived); Messenger.Default.Register <bool>(this, "DesignMode", DesignMode_MessageReceived); }
private void WriteDataToArduino(ArduinoCommands command) { if (_serialPort != null && _serialPort.IsOpen) { switch (command) { case ArduinoCommands.Up: _serialPort.WriteLine("100"); break; case ArduinoCommands.Down: _serialPort.WriteLine("0"); break; case ArduinoCommands.Angle: _serialPort.WriteLine("angle"); break; } } }
public void SendCommand(ArduinoCommands.CommandTypes cmd, string text) { StringBuilder sendCmd = new StringBuilder(); sendCmd.Append((int)cmd); if (!string.IsNullOrEmpty(text)) sendCmd.Append("," + text + ";"); else sendCmd.Append(";"); if (sendCmd != null && !String.IsNullOrEmpty(sendCmd.ToString())) { //if (!IsOpen) Open(); // FIXTHIS there was a problem with the serial not being open WriteLine(sendCmd.ToString()); } }
public Dictionary<string, string> SendCommandWithResponse(ArduinoCommands.CommandTypes cmd, string text) { //if (!IsOpen) Open(); SendCommand(cmd, text); StringBuilder response = new StringBuilder(); while (true) { try { response.Append(ReadLine()); } catch { //Close(); return new Dictionary<string, string>(); } if (response.ToString().Contains(";")) break; } //Close(); return parseVaribles(response.ToString()); }
public string SendCommandWithDebugResponse(ArduinoCommands.CommandTypes cmd, string text) { //if (!IsOpen) Open(); SendCommand(cmd, text); StringBuilder response = new StringBuilder(); while (true) { try { response.Append(ReadLine()); } catch { //Close(); return string.Empty; } if (response.ToString().Contains(";")) break; } return response.ToString(); }
private void SendData(ArduinoCommands command, byte value) { sp.Write(new byte[] { (byte)command, value }, 0, 2); }