Пример #1
0
        public void SetGain(int address, int wiper)
        {
            var command = new SendCommand((int)Command.SetGain);

            command.AddBinArgument((UInt16)address);
            command.AddBinArgument((Int16)wiper);
            _cmdMessenger.SendCommand(command);
        }
        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)
            {
                BoardType = BoardType.Bit16 // Set if it is communicating with a 16- or 32-bit Arduino board
            };

            // Attach the callbacks to the Command Messenger
            AttachCommandCallBacks();

            // Start listening
            _cmdMessenger.Connect();

            _receivedItemsCount = 0;
            _receivedBytesCount = 0;

            // Send command requesting a series of 100 float values send in plain text form
            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)
            {
            }

            _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)
            {
            }
        }
Пример #3
0
        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);
            }
        }
Пример #4
0
        public void SetSamplingRate(int samplingRate)
        {
            var command = new SendCommand((int)Command.SetSamplingRate);

            command.AddBinArgument((UInt16)samplingRate);
            _cmdMessenger.SendCommand(command);
        }
Пример #5
0
        public void SetNumOfSample(int npts)
        {
            var command = new SendCommand((int)Command.SetNumOfSample);

            command.AddBinArgument((UInt16)npts);
            _cmdMessenger.SendCommand(command);
        }
Пример #6
0
        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);
            }
        }
Пример #7
0
        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);
            }
        }
Пример #8
0
        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);
            }
        }
Пример #9
0
        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);
            }
        }
        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)
            {
            }
        }
Пример #11
0
        public void SetTriggerSensitivity(int sensitivity)
        {
            var threshold = 100 - sensitivity;
            var command   = new SendCommand((int)Command.SetTriggerSensitivity);

            command.AddBinArgument((UInt16)threshold);
            _cmdMessenger.SendCommand(command);
        }
        // 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);
        }
Пример #13
0
 public void SendMotorSpeed(int speed)
 {
     try
     {
         SendCommand cmd = new SendCommand((int)Command.MotorValue);
         cmd.AddBinArgument(speed);
         _cmdMessenger.SendCommand(cmd);
     }
     catch
     {
         Console.WriteLine("Error sending");
     }
 }
        // 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);

            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.
            _chartForm.LogMessage(@"Queue command - SetGoalTemperature");
            _cmdMessenger.QueueCommand(new CollapseCommandStrategy(command));
        }