コード例 #1
0
        public void SetRed(double red)
        {
            // Create command to start sending data
            var command = new SendCommand((int)Command.SetRed, red);

            // Put the command on the queue and wrap it in a collapse command strategy
            // This strategy will avoid duplicates of this certain command on the queue: if a SetLedFrequency 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 send a new blink frequency, the
            // embedded controller will not start lagging.
            _cmdMessenger.QueueCommand(new CollapseCommandStrategy(command));
        }
コード例 #2
0
        // *** 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);
            }
        }
コード例 #3
0
ファイル: TemperatureControl.cs プロジェクト: pzxz/robot_2WD
        // 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);

            // 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
0
        public void TestSendCommandWithAcknowledgementAfterQueued()
        {
            Common.StartTest("Test sending command and receiving acknowledgment after larger queue");

            // Quickly sent a bunch of commands, that will be combined in a command string
            for (var i = 0; i < 100; i++)
            {
                _cmdMessenger.QueueCommand(new SendCommand(_command["AreYouReady"]));
            }

            // Now wait for an acknowledge, terminating the command string
            var receivedCommand = _cmdMessenger.SendCommand(new SendCommand(_command["AreYouReady"], _command["Ack"], 1000), SendQueue.Default, ReceiveQueue.WaitForEmptyQueue);

            if (receivedCommand.Ok)
            {
                Common.TestOk("Acknowledgment for command AreYouReady");
            }
            else
            {
                Common.TestNotOk("No acknowledgment for command AreYouReady");
            }
            Common.EndTest();
        }