当前位置: 首页>>代码示例>>C#>>正文


C# SendCommand.AddArgument方法代码示例

本文整理汇总了C#中CommandMessenger.SendCommand.AddArgument方法的典型用法代码示例。如果您正苦于以下问题:C# SendCommand.AddArgument方法的具体用法?C# SendCommand.AddArgument怎么用?C# SendCommand.AddArgument使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CommandMessenger.SendCommand的用法示例。


在下文中一共展示了SendCommand.AddArgument方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Loop

        // Loop function
        public void Loop()
        {
            // Create command FloatAddition, which will wait for a return command FloatAdditionResult
            var command = new SendCommand((int)Command.FloatAddition, (int)Command.FloatAdditionResult, 1000);

            // Add 2 float command arguments
            var a = 3.14F;
            var b = 2.71F;
            command.AddArgument(a);
            command.AddArgument(b);

            // Send command
            var floatAdditionResultCommand = _cmdMessenger.SendCommand(command);

            // Check if received a (valid) response
            if (floatAdditionResultCommand.Ok)
            {
                // Read returned argument
                var sum = floatAdditionResultCommand.ReadFloatArg();
                var diff = floatAdditionResultCommand.ReadFloatArg();

                // Compare with sum of sent values
                var errorSum  = sum  - (a + b);
                var errorDiff = diff - (a - b);

                Console.WriteLine("Received sum {0}, difference of {1}", sum, diff);
                Console.WriteLine("with errors {0} and {1}, respectively", errorSum, errorDiff);
            }
            else
                Console.WriteLine("No response!");

            // Stop running loop
            RunLoop = false;
        }
开发者ID:vikramt,项目名称:Arduino,代码行数:35,代码来源:SendAndReceiveArguments.cs

示例2: 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) { }
        }
开发者ID:jgrizou,项目名称:robot_2WD,代码行数:45,代码来源:SendAndReceiveBinaryArguments.cs

示例3: ReadDPinState

		/// <summary>
		/// Reads DPin state.
		/// </summary>
		/// <returns>The pin.</returns>
		/// <param name="nr">Nr.</param>
		public static DPinState ReadDPinState (uint nr)
		{
			var command = new SendCommand ((int)Command.ReadPin, (int)Command.ReadPin, 500);
			command.AddArgument (nr);
			var result = _cmdMessenger.SendCommand (command);
			if (result.Ok)
			{
				LastCommunication = DateTime.Now;
				return (result.ReadBinInt16Arg () == (int)DPinState.HIGH) ? DPinState.HIGH : DPinState.LOW;
			}
			return DPinState.LOW;
		}
开发者ID:Onkeliroh,项目名称:DSA,代码行数:17,代码来源:ArduinoController.cs

示例4: sendSamsung

        public bool sendSamsung(String value)
        {
            if (!setupDone) {
                return false;
            }

            var command = new SendCommand((int)Command.SendSamsung, (int)Command.SendSamsungResponse, Globals.arguments().timeout);
            command.AddArgument (value);

            _cmdMessenger.SendCommand(command);
            var responseCommand = _cmdMessenger.SendCommand(command);

            // Check if received a (valid) response
            if (responseCommand.Ok) {
                OnSendSamsungResponse(responseCommand, value);
                return true;
            } else {
                listener.errorTimedOut();
                return false;
            }
        }
开发者ID:KyleTheHack3r,项目名称:infrared-tv-control,代码行数:21,代码来源:ArduinoManager.cs

示例5: sendLEDBlink

        public bool sendLEDBlink(int ledIndex, int blinkMillis, int repetitions)
        {
            if (!setupDone) {
                return false;
            }

            var command = new SendCommand((int)Command.LEDBlink, (int)Command.LEDBlinkResponse, Globals.arguments().timeout);
            command.AddArgument (ledIndex);
            command.AddArgument (blinkMillis);
            command.AddArgument (repetitions);

            _cmdMessenger.SendCommand(command);
            var responseCommand = _cmdMessenger.SendCommand(command);

            // Check if received a (valid) response
            if (responseCommand.Ok) {
                OnLEDBlinkResponse(responseCommand);
                return true;
            } else {
                listener.errorTimedOut();
                return false;
            }
        }
开发者ID:KyleTheHack3r,项目名称:infrared-tv-control,代码行数:23,代码来源:ArduinoManager.cs

示例6: 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);
            }
        }
开发者ID:DiLRandI,项目名称:Arduino-CmdMessenger,代码行数:66,代码来源:SendAndReceiveBinaryArguments.cs

示例7: sendLEDOnRange

        public bool sendLEDOnRange(int ledStartIndex, int ledEndIndex, int millisToKeepOn)
        {
            if (!setupDone) {
                return false;
            }

            var command = new SendCommand((int)Command.LEDOnRange, (int)Command.LEDOnRangeResponse, Globals.arguments().timeout);
            command.AddArgument(ledStartIndex);
            command.AddArgument(ledEndIndex);
            command.AddArgument(millisToKeepOn);

            _cmdMessenger.SendCommand(command);
            var responseCommand = _cmdMessenger.SendCommand(command);

            // Check if received a (valid) response
            if (responseCommand.Ok) {
                OnLEDOnRangeResponse(responseCommand);
                return true;
            } else {
                listener.errorTimedOut();
                return false;
            }
        }
开发者ID:KyleTheHack3r,项目名称:infrared-tv-control,代码行数:23,代码来源:ArduinoManager.cs

示例8: ValuePingPongDoubleSci

        private void ValuePingPongDoubleSci(double value, double accuracy)
        {
            var pingCommand = new SendCommand(_command["ValuePing"], _command["ValuePong"], 1000);
            pingCommand.AddArgument((Int16)DataType.DoubleSci);
            pingCommand.AddArgument(value);
            var pongCommand = _cmdMessenger.SendCommand(pingCommand);

            if (!pongCommand.Ok)
            {
                Common.TestNotOk("No response on ValuePing command");
                return;
            }

            var result = pongCommand.ReadDoubleArg();

            var difference = RelativeError(value, result);
            
            if (difference <= accuracy)
                Common.TestOk("Value as expected");
            else
                Common.TestNotOk("unexpected value received: " + result + " instead of " + value);
        }
开发者ID:DiLRandI,项目名称:Arduino-CmdMessenger,代码行数:22,代码来源:ClearTextData.cs

示例9: SetupQueuedSendSeries

        // *** Benchmark 2 ***
        // Setup queued send series
        private void SetupQueuedSendSeries()
        {
            Common.StartTest("Calculating speed in sending queued series of float data");
            WaitAndClear();

            _minimalBps = _systemSettings.MinSendSpeed;
            _sendSeriesFinished = false;
            var prepareSendSeries = new SendCommand(_command["PrepareSendSeries"]);
            prepareSendSeries.AddArgument(SeriesLength);
            _cmdMessenger.SendCommand(prepareSendSeries, SendQueue.WaitForEmptyQueue, ReceiveQueue.WaitForEmptyQueue);

            // Prepare
            _receivedBytesCount = 0;
            _cmdMessenger.PrintLfCr = true;
            _beginTime = Millis;

            // Now queue all commands
            for (var sendItemsCount = 0; sendItemsCount < SeriesLength; sendItemsCount++)
            {
                var sendSeries = new SendCommand(_command["SendSeries"]);
                sendSeries.AddArgument(sendItemsCount * SeriesBase);

                _receivedBytesCount += CountBytesInCommand(sendSeries, _cmdMessenger.PrintLfCr);

                _cmdMessenger.QueueCommand(sendSeries);
                if (sendItemsCount % (SeriesLength / 10) == 0)
                    Common.WriteLine("Send value: " + sendItemsCount * SeriesBase);
            }

            // Now wait until receiving party acknowledges that values have arrived
            while (!_sendSeriesFinished)
            {
                Thread.Sleep(10);
            }
        }
开发者ID:nkiest,项目名称:Arduino-Libraries,代码行数:37,代码来源:TransferSpeed.cs

示例10: MoveMotor

        public bool MoveMotor(short Channel, short Speed)
        {
            if (!Initialized)
                throw new Exception("Not yet initialized");

            var command = new SendCommand((int)Command.MotorCommand, (int)Command.Acknowledge, 1000);
            command.AddArgument(Channel);
            command.AddArgument(Speed);
            var response = _cmdMessenger.SendCommand(command);
            if (response.Ok)
            {
                var cn = response.ReadInt16Arg();
                var cs = response.ReadInt16Arg();
                Debug.WriteLine(String.Format("Command response - channel={0}; speed={1}", cn, cs));
                if (Channel == cn && Speed == cs)
                {
                    Debug.WriteLine("Alles gut");
                    //OnChannelStateConfirmation(new ChannelStatus(cn, cs));
                    return true;
                }

            }
            return false;
        }
开发者ID:zigorrom,项目名称:MeasurementChannelSwitch,代码行数:24,代码来源:ChannelSwitch.cs

示例11: ValuePingPongBool

        private void ValuePingPongBool(bool value)
        {
            var pingCommand = new SendCommand(_command["ValuePing"], _command["ValuePong"], 1000);
            pingCommand.AddArgument((Int16)DataType.Bool);
            pingCommand.AddArgument(value);
            var pongCommand = _cmdMessenger.SendCommand(pingCommand);

            if (!pongCommand.Ok)
            {
                Common.TestNotOk("No response on ValuePing command");
                return;
            }

            var result = pongCommand.ReadBoolArg();

            if (result == value)
                Common.TestOk("Value as expected");
            else
                Common.TestNotOk("unexpected value received: " + result + " instead of " + value);
        }
开发者ID:DiLRandI,项目名称:Arduino-CmdMessenger,代码行数:20,代码来源:ClearTextData.cs

示例12: SetAnalogPin

		/// <summary>
		/// Sets the analog pin.
		/// </summary>
		/// <param name="Pin">Pin.</param>
		/// <param name="Val">Value.</param>
		public static void SetAnalogPin (int Pin, int Val)
		{
			var command = new SendCommand ((int)Command.SetAnalogPin, Pin);
			command.AddArgument (Val);
			_cmdMessenger.SendCommand (command);
		}
开发者ID:Onkeliroh,项目名称:DSA,代码行数:11,代码来源:ArduinoController.cs

示例13: ReadAnalogPin

		/// <summary>
		/// Reads analog pins.
		/// </summary>
		/// <returns>The analog pin.</returns>
		/// <param name="nr">Nr.</param>
		public static double[] ReadAnalogPin (uint[] nr)
		{
			var command = new SendCommand ((int)Command.ReadAnalogPin, (int)Command.ReadAnalogPin, 100);
			command.AddArgument (nr.Length);
			foreach (int i in nr)
			{
				command.AddArgument (i);
			}
			double[] results = new double[nr.Length];
			var result = _cmdMessenger.SendCommand (command);
			if (result.Ok)
			{
				try
				{
					for (int i = 0; i < nr.Length; i++)
					{
						results [i] = Board.RAWToVolt (result.ReadFloatArg ());
					}
				} catch (Exception ex)
				{
					Console.Error.WriteLine (ex);
				}
				LastCommunication = DateTime.Now;
				return results;
			} else
			{
				for (int i = 0; i < results.Length; i++)
				{
					results [i] = double.NaN;
				}
				return results;
			}
		}
开发者ID:Onkeliroh,项目名称:DSA,代码行数:38,代码来源:ArduinoController.cs

示例14: SetAnalogReference

		/// <summary>
		/// Sets the analog reference voltage.
		/// </summary>
		/// <param name="AnalogReference">Analog reference.</param>
		public static void SetAnalogReference (int AnalogReference)
		{
			_board.AnalogReferenceVoltage = AnalogReference;
			var command = new SendCommand ((int)Command.SetAnalogReference);
			command.AddArgument (AnalogReference);
			_cmdMessenger.SendCommand (command);
		}
开发者ID:Onkeliroh,项目名称:DSA,代码行数:11,代码来源:ArduinoController.cs

示例15: SetPin

		/// <summary>
		/// Sets the pin.
		/// </summary>
		/// <param name="nr">Nr.</param>
		/// <param name="mode">Mode.</param>
		/// <param name="state">State.</param>
		public static void SetPin (uint nr, PinMode mode, DPinState state)
		{
			#if !FAKESERIAL
			var command = new SendCommand ((int)Command.SetPin, (int)Command.SetPin, 100);
			command.AddArgument ((UInt16)nr);
			command.AddArgument ((Int16)mode);
			command.AddArgument ((Int16)state);
			var ret = _cmdMessenger.SendCommand (command);
			if (ret.Ok)
			{
				if (!(nr == (uint)ret.ReadInt32Arg () && (Int16)mode == ret.ReadInt16Arg () && (Int16)state == ret.ReadInt16Arg ()))
				{
					Console.Error.WriteLine (DateTime.Now.ToString ("HH:mm:ss tt zz") + "\t" + nr + "\t" + mode + "\t" + state);
				}
				LastCommunication = DateTime.Now;
			}
			#endif
		}
开发者ID:Onkeliroh,项目名称:DSA,代码行数:24,代码来源:ArduinoController.cs


注:本文中的CommandMessenger.SendCommand.AddArgument方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。