本文整理汇总了C#中CommandMessenger.SendCommand.AddBinArgument方法的典型用法代码示例。如果您正苦于以下问题:C# SendCommand.AddBinArgument方法的具体用法?C# SendCommand.AddBinArgument怎么用?C# SendCommand.AddBinArgument使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CommandMessenger.SendCommand
的用法示例。
在下文中一共展示了SendCommand.AddBinArgument方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Setup
private const float SeriesBase = 1111111.111111F; // Base of values to return: SeriesBase * (0..SeriesLength-1)
// ------------------ M A I N ----------------------
// Setup function
public void Setup()
{
// Create Serial Port object
_serialTransport = new SerialTransport
{
CurrentSerialSettings = { PortName = "COM6", BaudRate = 115200 } // object initializer
};
// Initialize the command messenger with the Serial Port transport layer
_cmdMessenger = new CmdMessenger(_serialTransport);
// Attach the callbacks to the Command Messenger
AttachCommandCallBacks();
// Start listening
_cmdMessenger.StartListening();
_receivedPlainTextCount = 0;
// Send command requesting a series of 100 float values send in plain text
var commandPlainText = new SendCommand((int)Command.RequestPlainTextFloatSeries);
commandPlainText.AddArgument(SeriesLength);
commandPlainText.AddArgument(SeriesBase);
// Send command
_cmdMessenger.SendCommand(commandPlainText);
// Now wait until all values have arrived
while (!_receivePlainTextFloatSeriesFinished) {}
// Send command requesting a series of 100 float values send in plain text
var commandBinary = new SendCommand((int)Command.RequestBinaryFloatSeries);
commandBinary.AddBinArgument((UInt16)SeriesLength);
commandBinary.AddBinArgument((Single)SeriesBase);
// Send command
_cmdMessenger.SendCommand(commandBinary);
// Now wait until all values have arrived
while (!_receiveBinaryFloatSeriesFinished) { }
}
示例2: ValuePingPongBinInt16Int32Double
private void ValuePingPongBinInt16Int32Double(Int16 int16Value, Int32 int32Value, double doubleValue)
{
var pingCommand = new SendCommand(_command["MultiValuePing"], _command["MultiValuePong"], 1000);
pingCommand.AddBinArgument(int16Value);
pingCommand.AddBinArgument(int32Value);
pingCommand.AddBinArgument(doubleValue);
var pongCommand = _cmdMessenger.SendCommand(pingCommand);
if (!pongCommand.Ok)
{
Common.TestNotOk("No response on ValuePing command");
return;
}
var int16Result = pongCommand.ReadBinInt16Arg();
var int32Result = pongCommand.ReadBinInt32Arg();
var doubleResult = pongCommand.ReadBinDoubleArg();
if (int16Result == int16Value)
Common.TestOk("1st parameter value, Int16, as expected: " + int16Result);
else
Common.TestNotOk("unexpected 1st parameter value received: " + int16Result + " instead of " + int16Value);
if (int32Result == int32Value)
Common.TestOk("2nd parameter value, Int32, as expected: " + int32Result);
else
Common.TestNotOk("unexpected 2nd parameter value, Int32, received: " + int32Result + " instead of " + int32Value);
// For 16bit, because of double-float-float-double casting a small error is introduced
var accuracy = (_systemSettings.BoardType == BoardType.Bit32) ? double.Epsilon : Math.Abs(doubleValue * 1e-6);
var difference = Math.Abs(doubleResult - doubleValue);
if (difference <= accuracy)
Common.TestOk("3rd parameter value, Double, as expected: " + doubleResult);
else
Common.TestNotOk("unexpected 3rd parameter value, Double, received: " + doubleResult + " instead of " + doubleValue);
}
示例3: SetGoalTemperature
// Set the goal temperature on the embedded controller
public void SetGoalTemperature(double goalTemperature)
{
_goalTemperature = goalTemperature;
// Create command to start sending data
//var command = new SendCommand((int)Command.SetGoalTemperature, _goalTemperature);
var command = new SendCommand((int)Command.SetGoalTemperature);
command.AddBinArgument(_goalTemperature);
// Collapse this command if needed using CollapseCommandStrategy
// This strategy will avoid duplicates of this command on the queue: if a SetGoalTemperature command is
// already on the queue when a new one is added, it will be replaced at its current queue-position.
// Otherwise the command will be added to the back of the queue.
//
// This will make sure that when the slider raises a lot of events that each set a new goal temperature, the
// controller will not start lagging.
_cmdMessenger.QueueCommand(new CollapseCommandStrategy(command));
}
示例4: SetStartTime
// Set the start time on the embedded controller
public void SetStartTime(float startTime)
{
var command = new SendCommand((int)Command.SetStartTime, (int)Command.Acknowledge,500);
command.AddBinArgument((float)startTime);
// We place this command at the front of the queue in order to receive correctly timestamped data as soon as possible
// Meanwhile, the data in the receivedQueue is cleared as these will contain the wrong timestamp
_cmdMessenger.SendCommand(command,SendQueue.ClearQueue, ReceiveQueue.ClearQueue, UseQueue.BypassQueue);
}
示例5: ValuePingPongEscString
private void ValuePingPongEscString(string value)
{
var pingCommand = new SendCommand(_command["ValuePing"], _command["ValuePong"], 1000);
pingCommand.AddArgument((int)DataType.EscString);
pingCommand.AddBinArgument(value); // Adding a string as binary command will escape it
var pongCommand = _cmdMessenger.SendCommand(pingCommand);
if (!pongCommand.Ok)
{
Common.TestNotOk("No response on ValuePing command");
return;
}
var result = pongCommand.ReadBinStringArg();
if (value == result)
{
Common.TestOk("Value as expected");
}
else
{
Common.TestNotOk("unexpected value received: " + result + " instead of " + value);
}
}
示例6: ValuePingPongBinDouble
private void ValuePingPongBinDouble(double value)
{
var pingCommand = new SendCommand(_command["ValuePing"], _command["ValuePong"], 1000);
pingCommand.AddArgument((Int16)DataType.BDouble);
pingCommand.AddBinArgument(value);
var pongCommand = _cmdMessenger.SendCommand(pingCommand);
if (!pongCommand.Ok)
{
Common.TestNotOk("No response on ValuePing command");
return;
}
var result = pongCommand.ReadBinDoubleArg();
var difference = Math.Abs(result - value);
//
// For 16bit, because of double-float-float-double casting a small error is introduced
var accuracy = (_systemSettings.BoardType == BoardType.Bit32) ? double.Epsilon : Math.Abs(value * 1e-6);
if (difference <= accuracy)
Common.TestOk("Value as expected");
else
Common.TestNotOk("unexpected value received: " + result + " instead of " + value);
}
示例7: ValuePingPongBinFloat
private void ValuePingPongBinFloat(float value)
{
const float accuracy = float.Epsilon;
var pingCommand = new SendCommand(_command["ValuePing"], _command["ValuePong"], 1000);
pingCommand.AddArgument((Int16)DataType.BFloat);
pingCommand.AddBinArgument(value);
var pongCommand = _cmdMessenger.SendCommand(pingCommand);
if (!pongCommand.Ok)
{
Common.TestNotOk("No response on ValuePing command");
return;
}
var result = pongCommand.ReadBinFloatArg();
var difference = Math.Abs(result - value);
if (difference <= accuracy)
Common.TestOk("Value as expected");
else
Common.TestNotOk("unexpected value received: " + result + " instead of " + value);
}
示例8: ValuePingPongBinBool
private void ValuePingPongBinBool(bool value)
{
var pingCommand = new SendCommand(_command["ValuePing"], _command["ValuePong"], 1000);
pingCommand.AddArgument((Int16)DataType.BBool);
pingCommand.AddBinArgument(value);
var pongCommand = _cmdMessenger.SendCommand(pingCommand);
if (!pongCommand.Ok)
{
Common.TestNotOk("No response on ValuePing command");
return;
}
var result = pongCommand.ReadBinBoolArg();
if (result == value)
Common.TestOk("Value as expected");
else
Common.TestNotOk("unexpected value received: " + result + " instead of " + value);
}
示例9: Setup
private const float SeriesBase = 1111111.111111F; // Base of values to return: SeriesBase * (0..SeriesLength-1)
// ------------------ M A I N ----------------------
// Setup function
public void Setup()
{
// Create Serial Port object
_serialTransport = new SerialTransport
{
CurrentSerialSettings = { PortName = "COM15", BaudRate = 115200 } // object initializer
};
// Initialize the command messenger with the Serial Port transport layer
// Set if it is communicating with a 16- or 32-bit Arduino board
_cmdMessenger = new CmdMessenger(_serialTransport, BoardType.Bit16);
// Attach the callbacks to the Command Messenger
AttachCommandCallBacks();
// Start listening
_cmdMessenger.Connect();
_receivedItemsCount = 0;
_receivedBytesCount = 0;
// Clear queues
_cmdMessenger.ClearReceiveQueue();
_cmdMessenger.ClearSendQueue();
Thread.Sleep(100);
// Send command requesting a series of 100 float values send in plain text form
var commandPlainText = new SendCommand((int)Command.RequestPlainTextFloatSeries);
commandPlainText.AddArgument((UInt16)SeriesLength);
commandPlainText.AddArgument((float)SeriesBase);
// Send command
_cmdMessenger.SendCommand(commandPlainText);
// Now wait until all values have arrived
while (!_receivePlainTextFloatSeriesFinished)
{
Thread.Sleep(100);
}
// Clear queues
_cmdMessenger.ClearReceiveQueue();
_cmdMessenger.ClearSendQueue();
_receivedItemsCount = 0;
_receivedBytesCount = 0;
// Send command requesting a series of 100 float values send in binary form
var commandBinary = new SendCommand((int)Command.RequestBinaryFloatSeries);
commandBinary.AddBinArgument((UInt16)SeriesLength);
commandBinary.AddBinArgument((float)SeriesBase);
// Send command
_cmdMessenger.SendCommand(commandBinary);
// Now wait until all values have arrived
while (!_receiveBinaryFloatSeriesFinished)
{
Thread.Sleep(100);
}
}