/// <summary> /// Converts a command object into a string that can /// be then sent across the serial. /// </summary> /// <param name="cmd"></param> private static string BuildString(Clide.Command cmd) { string cmdLineString; // Add the command name to the start of the string cmdLineString = cmd.Name; // Add parameters for (int x = 0; x < cmd.ParamList.Count; x++) { cmdLineString += ' ' + cmd.ParamList[x].Value; } // Add options for (int x = 0; x < cmd.OptionList.Count; x++) { // Make sure it is wanted to be sent if (cmd.OptionList[x].ToSend) { cmdLineString += " -" + cmd.OptionList[x].Name; // Add value also, but only if one exists if (cmd.OptionList[x].HasValue) { cmdLineString += ' ' + cmd.OptionList[x].Value; } } } return(cmdLineString); }
/// <summary> /// Sends a command over the serial port /// </summary> /// <param name="cmd">Command to send over serial port.</param> public void SendCommand(Clide.Command cmd) { string cmdString = BuildString(cmd) + "\r\n"; _port.serialPort.Write(cmdString); if (DebugPrint != null) { // Need to do this because called from another thread DebugPrint("Sending message. Message: " + BuildString(cmd)); } // Increment TX packet count _packetCount++; }
/// <summary> /// Registers a command with the RX decoding engine. Commands must be registered with the engine /// before they will be recognised in the receiving character buffer. /// </summary> /// <param name="cmd">The command to register.</param> public void RegisterCommand(Clide.Command cmd) { // Add command to object _registeredCmds.Add(cmd); }