/// <summary> /// Sends a command followed by command arguments to robot. /// </summary> /// <param name="command">A command to send.</param> /// <param name="args">An array of bytes specifying the arguments for the command.</param> /// <returns>An instance of SerialResponse containing the response data received from the robot.</returns> /// <exception cref="ApplicationException">Thrown if the serial response does not match serial command.</exception> private SerialResponse SendCommand(SerialCommands command, params byte[] args) { lock (this._lockCommand) { // Clear the port and response buffer. this._responseBufferLength = 0; if (Port.BytesToRead > 0) { Port.ReadExisting(); } // Send command followed by any arguments. Port.Write(new byte[] { (byte)command }, 0, 1); if (args != null && args.Length > 0) { Port.Write(args, 0, args.Length); } // Wait to receive a complete response or until timeout. SerialResponse serialResponse = this.ReadResponse(); if (serialResponse.SerialCommand != command) { throw new ApplicationException("Serial response did not match serial command."); } return(serialResponse); } }
public override void SendCommand(SerialCommands command, object data) { if (command == SerialCommands.GetStatus) { GetStatus(); } }
public override void SendCommand(SerialCommands command, object data) { if (command == SerialCommands.Start) { SendStart(); } }
public override void SendCommand(SerialCommands command, object data) { if (command == SerialCommands.GetSettings) { Send(SerialCodeCommand.GetSettings); WaitingForResponse(); } }
public override void SendCommand(SerialCommands command, object data) { if (command == SerialCommands.SetSettings) { (uint, double)tuple = ((uint, double))data; ChangeParameters(tuple.Item1, tuple.Item2); } }
public async Task <IActionResult> SendCommand(int id, [FromBody] SerialCommands commands) { var port = GetPort(id); if (port == null || commands == null || commands.Commands == null) { return(NotFound()); } var ret = await port.Serial.SendCommandsAsync(commands.Commands, commands.TimeOut); return(Ok(ret)); }
private bool IsSingleByteCommand(SerialCommands command) { switch (command) { case SerialCommands.MotorControl: case SerialCommands.LocateBeaconModeOn: case SerialCommands.SwarmModeCommand: return(false); default: return(true); } }
public async Task<IEnumerable<SerialCommand>> QueueCommandsAsync(IEnumerable<string> lines) { if (PortId >= 0) { using (var scope = CreateScope()) { var cmds = new SerialCommands() { Commands = lines.ToArray() }; var response = scope.Instance.PostAsJsonAsync($@"{_api}/{PortId}/queue", cmds).Result; if (response.IsSuccessStatusCode) { var value = await response.Content.ReadAsAsync<IEnumerable<SerialCommand>>(); return value; } } } throw new Exception("Queue to SerialPort failed"); }
public async Task<IEnumerable<SerialCommand>> SendCommandsAsync(IEnumerable<string> lines, int waitForMilliseconds) { if (PortId >= 0) { using (var scope = CreateScope()) { scope.Instance.Timeout = new TimeSpan(10000L * (((long)waitForMilliseconds) + 5000)); var cmds = new SerialCommands() { Commands = lines.ToArray(), TimeOut = waitForMilliseconds }; var response = await scope.Instance.PostAsJsonAsync($@"{_api}/{PortId}/send", cmds); if (response.IsSuccessStatusCode) { var value = await response.Content.ReadAsAsync<IEnumerable<SerialCommand>>(); return value; } } } throw new Exception("Send to SerialPort failed"); }
public async Task <IEnumerable <SerialCommand> > QueueCommandsAsync(IEnumerable <string> lines) { if (PortId != 0) { using (HttpClient client = CreateHttpClient()) { var cmds = new SerialCommands() { Commands = lines.ToArray() }; HttpResponseMessage response = client.PostAsJsonAsync($@"{_api}/{PortId}/queue", cmds).Result; if (response.IsSuccessStatusCode) { var value = await response.Content.ReadAsAsync <IEnumerable <SerialCommand> >(); return(value); } } } throw new Exception("Queue to SerialPort failed"); }
protected override void SetupCommands() { // add a single command to the root commands rootCommands.AddCommand(new ExampleMonoBehaviourCommand().Init(monoBehaviourObject, null, "Command 21")); // added parallel commands to the root ParallelCommands parallelCommands = new ParallelCommands(); parallelCommands.AddCommand(new ExampleMonoBehaviourCommand().Init(monoBehaviourObject, null, "Command 22")); parallelCommands.AddCommand(new ExampleMonoBehaviourCommand().Init(monoBehaviourObject, null, "Command 23")); parallelCommands.AddCommand(new ExampleMonoBehaviourCommand().Init(monoBehaviourObject, null, "Command 24")); rootCommands.AddCommand(parallelCommands); parallelCommands = new ParallelCommands(); // add serial commmands to parallel commands then add to root SerialCommands serialCommands = new SerialCommands(); serialCommands.AddCommand(new ExampleMonoBehaviourCommand().Init(monoBehaviourObject, null, "Command 25")); serialCommands.AddCommand(new ExampleMonoBehaviourCommand().Init(monoBehaviourObject, null, "Command 26")); serialCommands.AddCommand(new ExampleMonoBehaviourCommand().Init(monoBehaviourObject, null, "Command 27")); parallelCommands.AddCommand(serialCommands); // add serial commmands to parallel commands then add to root serialCommands = new SerialCommands(); serialCommands.AddCommand(new ExampleMonoBehaviourCommand().Init(monoBehaviourObject, null, "Command 28")); serialCommands.AddCommand(new ExampleMonoBehaviourCommand().Init(monoBehaviourObject, null, "Command 29")); serialCommands.AddCommand(new ExampleMonoBehaviourCommand().Init(monoBehaviourObject, null, "Command 30")); parallelCommands.AddCommand(serialCommands); // add serial commmands to parallel commands then add to root rootCommands.AddCommand(parallelCommands); serialCommands = new SerialCommands(); // Add parallel commands to serial commands then add to root parallelCommands = new ParallelCommands(); parallelCommands.AddCommand(new ExampleMonoBehaviourCommand().Init(monoBehaviourObject, null, "Command 31")); parallelCommands.AddCommand(new ExampleMonoBehaviourCommand().Init(monoBehaviourObject, null, "Command 32")); parallelCommands.AddCommand(new ExampleMonoBehaviourCommand().Init(monoBehaviourObject, null, "Command 33")); serialCommands.AddCommand(parallelCommands); // Add parallel commands to serial commands then add to root parallelCommands = new ParallelCommands(); parallelCommands.AddCommand(new ExampleMonoBehaviourCommand().Init(monoBehaviourObject, null, "Command 34")); parallelCommands.AddCommand(new ExampleMonoBehaviourCommand().Init(monoBehaviourObject, null, "Command 35")); parallelCommands.AddCommand(new ExampleMonoBehaviourCommand().Init(monoBehaviourObject, null, "Command 36")); serialCommands.AddCommand(parallelCommands); // Add parallel commands to serial commands then add to root rootCommands.AddCommand(serialCommands); // add parallel commands to the root parallelCommands = new ParallelCommands(); parallelCommands.AddCommand(new ExampleMonoBehaviourCommand().Init(monoBehaviourObject, null, "Command 37")); parallelCommands.AddCommand(new ExampleMonoBehaviourCommand().Init(monoBehaviourObject, null, "Command 38")); parallelCommands.AddCommand(new ExampleMonoBehaviourCommand().Init(monoBehaviourObject, null, "Command 39")); rootCommands.AddCommand(parallelCommands); // add the lighter commands that don't have the built in reference to a MonoBehaviour Object rootCommands.AddCommand(new ExampleCommand().Init(null, "Command 40")); // This shows a basic concrete command using other commands. rootCommands.AddCommand(new ExampleWrapperCommand().Init()); // This shows a basic concrete command using a Serial Command. It's probably best to not create child classes of SerialCommands and ParrellelComands to avoid too much polymorphing. // Instead try encapsulating them in a child of a basic Command, look at the above ExampleWrapperCommand example. rootCommands.AddCommand(new ExampleSerialCommand().Init()); }
public void SendCommand(SerialCommands command, object data) { senders.ForEach(x => x.SendCommand(command, data)); }
public async Task <ActionResult <IEnumerable <SerialCommand> > > SendWhileOkCommand(int id, [FromBody] SerialCommands commands) { var port = await GetPort(id); if (port == null || commands == null || commands.Commands == null) { return(NotFound()); } var ret = new List <SerialCommand>(); foreach (var c in commands.Commands) { var result = await port.Serial.SendCommandsAsync(new[] { c }, commands.TimeOut); ret.AddRange(result); if (result.Any() && result.LastOrDefault().ReplyType != EReplyType.ReplyOK) { break; } } return(Ok(ret)); }
public SerialResponse(SerialCommands serialCommand, object data) { this._serialCommand = serialCommand; this._data = data; }
public SerialResponse(SerialCommands serialCommand) : this(serialCommand, null) { }
public ExampleSerialCommand() { serialCommands = new SerialCommands(); }
public async Task <ActionResult <IEnumerable <SerialCommand> > > QueueCommand(int id, [FromBody] SerialCommands commands) { var port = await GetPort(id); if (port == null || commands == null || commands.Commands == null) { return(NotFound()); } var ret = await port.Serial.QueueCommandsAsync(commands.Commands); return(Ok(ret)); }
public async Task <ActionResult <IEnumerable <SerialCommand> > > SendCommand(int id, [FromBody] SerialCommands commands) { var port = await SerialPortList.GetPortAndRescan(id); if (port == null || commands == null || commands.Commands == null) { return(NotFound()); } var ret = await port.Serial.SendCommandsAsync(commands.Commands, commands.TimeOut); return(Ok(ret)); }
protected override void SetupCommands() { // add a single command to the root commands rootCommands.AddCommand(new ExampleMonoBehaviourCommand().Init(monoBehaviourObject, null, "Command 1")); // added parallel commands to the root ParallelCommands parallelCommands = new ParallelCommands(); parallelCommands.AddCommand(new ExampleMonoBehaviourCommand().Init(monoBehaviourObject, null, "Command 2")); parallelCommands.AddCommand(new ExampleMonoBehaviourCommand().Init(monoBehaviourObject, null, "Command 3")); parallelCommands.AddCommand(new ExampleMonoBehaviourCommand().Init(monoBehaviourObject, null, "Command 4")); rootCommands.AddCommand(parallelCommands); parallelCommands = new ParallelCommands(); // add serial commmands to parallel commands then add to root SerialCommands serialCommands = new SerialCommands(); serialCommands.AddCommand(new ExampleMonoBehaviourCommand().Init(monoBehaviourObject, null, "Command 5")); serialCommands.AddCommand(new ExampleMonoBehaviourCommand().Init(monoBehaviourObject, null, "Command 6")); serialCommands.AddCommand(new ExampleMonoBehaviourCommand().Init(monoBehaviourObject, null, "Command 7")); parallelCommands.AddCommand(serialCommands); // add serial commmands to parallel commands then add to root serialCommands = new SerialCommands(); serialCommands.AddCommand(new ExampleMonoBehaviourCommand().Init(monoBehaviourObject, null, "Command 8")); serialCommands.AddCommand(new ExampleMonoBehaviourCommand().Init(monoBehaviourObject, null, "Command 9")); serialCommands.AddCommand(new ExampleMonoBehaviourCommand().Init(monoBehaviourObject, null, "Command 10")); parallelCommands.AddCommand(serialCommands); // add serial commmands to parallel commands then add to root rootCommands.AddCommand(parallelCommands); serialCommands = new SerialCommands(); // Add parallel commands to serial commands then add to root parallelCommands = new ParallelCommands(); parallelCommands.AddCommand(new ExampleMonoBehaviourCommand().Init(monoBehaviourObject, null, "Command 11")); parallelCommands.AddCommand(new ExampleMonoBehaviourCommand().Init(monoBehaviourObject, null, "Command 12")); parallelCommands.AddCommand(new ExampleMonoBehaviourCommand().Init(monoBehaviourObject, null, "Command 13")); serialCommands.AddCommand(parallelCommands); // Add parallel commands to serial commands then add to root parallelCommands = new ParallelCommands(); parallelCommands.AddCommand(new ExampleMonoBehaviourCommand().Init(monoBehaviourObject, null, "Command 14")); parallelCommands.AddCommand(new ExampleMonoBehaviourCommand().Init(monoBehaviourObject, null, "Command 15")); parallelCommands.AddCommand(new ExampleMonoBehaviourCommand().Init(monoBehaviourObject, null, "Command 16")); serialCommands.AddCommand(parallelCommands); // Add parallel commands to serial commands then add to root rootCommands.AddCommand(serialCommands); // add parallel commands to the root parallelCommands = new ParallelCommands(); parallelCommands.AddCommand(new ExampleMonoBehaviourCommand().Init(monoBehaviourObject, null, "Command 17")); parallelCommands.AddCommand(new ExampleMonoBehaviourCommand().Init(monoBehaviourObject, null, "Command 18")); parallelCommands.AddCommand(new ExampleMonoBehaviourCommand().Init(monoBehaviourObject, null, "Command 19")); rootCommands.AddCommand(parallelCommands); // add the lighter commands that don't have the built in reference to a MonoBehaviour Object rootCommands.AddCommand(new ExampleCommand().Init(null, "Command 20")); }
public abstract void SendCommand(SerialCommands command, object data);