• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# CommandMessenger.SendCommand类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



SendCommand类属于CommandMessenger命名空间,在下文中一共展示了SendCommand类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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

        // Setup function
        public void Setup()
        {
            _transport = new SerialTransport {CurrentSerialSettings = {DtrEnable = false}};
            // some boards (e.g. Sparkfun Pro Micro) DtrEnable may need to be true.                        
            // We do not need to set serial port and baud rate: it will be found by the connection manager                                                           

            // 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(_transport, BoardType.Bit16)
            {
                PrintLfCr = false // Do not print newLine at end of command, to reduce data being sent
            };

            // The Connection manager is capable or storing connection settings, in order to reconnect more quickly  
            // the next time the application is run. You can determine yourself where and how to store the settings
            // by supplying a class, that implements ISerialConnectionStorer. For convenience, CmdMessenger provides
            //  simple binary file storage functionality
            var serialConnectionStorer = new SerialConnectionStorer("SerialConnectionManagerSettings.cfg");

            // We don't need to provide a handler for the Identify command - this is a job for Connection Manager.
            _connectionManager = new SerialConnectionManager(
                _transport as SerialTransport, 
                _cmdMessenger,
                (int) Command.Identify, 
                CommunicationIdentifier,
                serialConnectionStorer)
            {
                // Enable watchdog functionality.
                WatchdogEnabled = true,

                // Instead of scanning for the connected port, you can disable scanning and only try the port set in CurrentSerialSettings
                //DeviceScanEnabled = false
            };

            // Show all connection progress on command line             
            _connectionManager.Progress += (sender, eventArgs) =>
            {
                // If you want to reduce verbosity, you can only show events of level <=2 or ==1
                if (eventArgs.Level <= 3) Console.WriteLine(eventArgs.Description);
            };

            // If connection found, tell the arduino to turn the (internal) led on
            _connectionManager.ConnectionFound += (sender, eventArgs) =>
            {
                // Create command
                var command = new SendCommand((int)Command.TurnLedOn);
                // Send command
                _cmdMessenger.SendCommand(command);
            };

            //You can also do something when the connection is lost
            _connectionManager.ConnectionTimeout += (sender, eventArgs) =>
            {
                //Do something
            };

            // Finally - activate connection manager
            _connectionManager.StartConnectionManager();
        }
开发者ID:DiLRandI,项目名称:Arduino-CmdMessenger,代码行数:60,代码来源:SimpleWatchdog.cs


示例3: SetLedState

        // Sent command to change led on/of state
        public void SetLedState(bool ledState)
        {
            // Create command to start sending data
            var command = new SendCommand((int)Command.SetLed, ledState);

            // Send command
            _cmdMessenger.SendCommand(new SendCommand((int)Command.SetLed, ledState));
        }
开发者ID:vikramt,项目名称:Arduino,代码行数:9,代码来源:ArduinoController.cs


示例4: SetLedFrequency

        public void SetLedFrequency(double ledFrequency)
        {
            // Send command to start sending data
            var command = new SendCommand((int)Command.SetLedFrequency,ledFrequency);

            // Send command
            _cmdMessenger.SendCommand(command);
        }
开发者ID:c37-cae,项目名称:T-Bone,代码行数:8,代码来源:ArduinoController.cs


示例5: Loop

        // Loop function
        public void Loop()
        {
            // Create command
            var command = new SendCommand((int)Command.SetLed,_ledState);               

            // Send command
            _cmdMessenger.SendCommand(command);

            // Wait for 1 second and repeat
            Thread.Sleep(1000);
            _ledState = !_ledState;                                        // Toggle led state            
        }
开发者ID:jgrizou,项目名称:robot_2WD,代码行数:13,代码来源:Receive.cs


示例6: Send

 public override void Send(string message)
 {
     try
     {
         var cmd = new SendCommand((int)SerialCommand.SetLed, message);
         var recieve = cmdMessenger.SendCommand(cmd);
         OnSendSuccess(new MessageEventArgs(string.Format("Message Send Success: Id={0}, Message={1}", recieve.RawString, message)));
     }
     catch (Exception e)
     {
         OnSendFailure(new MessageEventArgs("Message Send Failure: " + e.ToString()));
     }
 }
开发者ID:robeat101,项目名称:beakn,代码行数:13,代码来源:Serial.cs


示例7: SetLedFrequency

        // Sent command to change led blinking frequency
        public void SetLedFrequency(double ledFrequency)
        {
            // Create command to start sending data
            var command = new SendCommand((int)Command.SetLedFrequency,ledFrequency);

            // 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));
        }
开发者ID:vikramt,项目名称:Arduino,代码行数:15,代码来源:ArduinoController.cs


示例8: Loop

        // Loop function
        public void Loop()
        {
            // Create command
            var command = new SendCommand((int)Command.SetLed,_ledState);               

            // Send command
            _cmdMessenger.SendCommand(command);

            Console.Write("Turning led ");
            Console.WriteLine(_ledState?"on":"off");

            // Wait for 1 second and repeat
            Thread.Sleep(1000);
            _ledState = !_ledState;   // Toggle led state            
        }
开发者ID:DiLRandI,项目名称:Arduino-CmdMessenger,代码行数:16,代码来源:Receive.cs


示例9: ExecuteSendCommand

        /// <summary> Directly executes the send command operation. </summary>
        /// <param name="sendCommand">    The command to sent. </param>
        /// <param name="sendQueueState"> Property to optionally clear the send and receive queues. </param>
        /// <returns> A received command. The received command will only be valid if the ReqAc of the command is true. </returns>
        public ReceivedCommand ExecuteSendCommand(SendCommand sendCommand, SendQueue sendQueueState)
        {
            // Disable listening, all callbacks are disabled until after command was sent

            ReceivedCommand ackCommand;
            lock (_sendCommandDataLock)
            {

                if (PrintLfCr)
                    _communicationManager.WriteLine(sendCommand.CommandString());
                else
                    _communicationManager.Write(sendCommand.CommandString());
                ackCommand = sendCommand.ReqAc ? BlockedTillReply(sendCommand.AckCmdId, sendCommand.Timeout, sendQueueState) : new ReceivedCommand();
                }
                return ackCommand;
        }
开发者ID:KyleTheHack3r,项目名称:infrared-tv-control,代码行数:20,代码来源:Sender.cs


示例10: Loop

        // Loop function
        public void Loop()
        {
            _count++;

            // Create command
            var command = new SendCommand((int)Command.SetLed,_ledState);               

            // Send command
            _cmdMessenger.SendCommand(command);

            // Wait for 1 second and repeat
            Thread.Sleep(1000);
            _ledState = !_ledState;                                        // Toggle led state  

            if (_count > 100) RunLoop = false;                             // Stop loop after 100 rounds
        }
开发者ID:DiLRandI,项目名称:Arduino-CmdMessenger,代码行数:17,代码来源:SendAndReceive.cs


示例11: Setup

        // ------------------ MAIN  ----------------------

        // Setup function
        public void Setup(ChartForm chartForm)
        {
           
            // getting the chart control on top of the chart form.
            _chartForm = chartForm;
            
            // Set up chart
            _chartForm.SetupChart();

            // Create Serial Port object
            // Note that for some boards (e.g. Sparkfun Pro Micro) DtrEnable may need to be true.
            _serialTransport = new SerialTransport
            {
                CurrentSerialSettings = { PortName = "COM6", BaudRate = 115200, DtrEnable = false } // 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);

            // Tell CmdMessenger to "Invoke" commands on the thread running the WinForms UI
            _cmdMessenger.ControlToInvokeOn = chartForm;

            // Set Received command strategy that removes commands that are older than 1 sec
            _cmdMessenger.AddReceiveCommandStrategy(new StaleGeneralStrategy(1000));

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

            // Attach to NewLinesReceived for logging purposes
            _cmdMessenger.NewLineReceived += NewLineReceived;

            // Attach to NewLineSent for logging purposes
            _cmdMessenger.NewLineSent += NewLineSent;                       

            // Start listening
            _cmdMessenger.Connect();

            // Send command to start sending data
            var command = new SendCommand((int)Command.StartLogging);

            // Send command
            _cmdMessenger.SendCommand(command);
        }
开发者ID:DiLRandI,项目名称:Arduino-CmdMessenger,代码行数:47,代码来源:DataLogging.cs


示例12: Setup

        // ------------------ MAIN  ----------------------

        // Setup function
        public void Setup(ChartForm chartForm)
        {
           
            // getting the chart control on top of the chart form.
            _chartForm = chartForm;
            
            // Set up chart
            _chartForm.SetupChart();

            // 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);

            // Tell CmdMessenger to "Invoke" commands on the thread running the WinForms UI
            _cmdMessenger.SetControlToInvokeOn(chartForm);

            // Set Received command strategy that removes commands that are older than 1 sec
            _cmdMessenger.AddReceiveCommandStrategy(new StaleGeneralStrategy(1000));

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

            // Attach to NewLinesReceived for logging purposes
            _cmdMessenger.NewLineReceived += NewLineReceived;

            // Attach to NewLineSent for logging purposes
            _cmdMessenger.NewLineSent += NewLineSent;                       

            // Start listening
            _cmdMessenger.StartListening();

            // Send command to start sending data
            var command = new SendCommand((int)Command.StartLogging);

            // Send command
            _cmdMessenger.SendCommand(command);
        }
开发者ID:jgrizou,项目名称:robot_2WD,代码行数:45,代码来源:DataLogging.cs


示例13: 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


示例14: 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


示例15: DirectSendSeries

        // *** Benchmark 3 ***
        private void DirectSendSeries()
        {
            Common.StartTest("Calculating speed in individually sending a series of float data");
            WaitAndClear();

            _minimalBps = _systemSettings.MinDirectSendSpeed;
            _sendSeriesFinished = false;

            var prepareSendSeries = new SendCommand(_command["PrepareSendSeries"]);
            prepareSendSeries.AddArgument(SeriesLength);
            // We need to to send the prepareSendSeries by bypassing the queue or it might be sent after the directly send commands later on
            _cmdMessenger.SendCommand(prepareSendSeries, SendQueue.WaitForEmptyQueue, ReceiveQueue.WaitForEmptyQueue,UseQueue.BypassQueue);

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

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

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

                _cmdMessenger.SendCommand(sendSeries, SendQueue.Default, ReceiveQueue.Default, UseQueue.BypassQueue);

                if (sendItemsCount%(SeriesLength/10) == 0)
                {
                    Common.WriteLine("Send value: " + sendItemsCount*SeriesBase);
                }
            }
            _endTime = Millis;
            // Now wait until receiving party acknowledges that values have arrived
            while (!_sendSeriesFinished)
            {
                Thread.Sleep(10);
            }
        }
开发者ID:nkiest,项目名称:Arduino-Libraries,代码行数:41,代码来源:TransferSpeed.cs


示例16: SendCommand

 /// <summary> Sends a command. </summary>
 /// <param name="sendCommand"> The command to sent. </param>
 /// <returns> . </returns>
 public ReceivedCommand SendCommand(SendCommand sendCommand)
 {
     return SendCommand(sendCommand.CmdId, sendCommand.Arguments, sendCommand.ReqAc, sendCommand.AckCmdId,
                        sendCommand.Timeout);
 }
开发者ID:nuclearcanary,项目名称:Arduino-Libraries,代码行数:8,代码来源:CmdMessenger.cs


示例17: QueueCommand

 /// <summary> Put the command at the back of the sent queue.</summary>
 /// <param name="sendCommand"> The command to sent. </param>
 public void QueueCommand(SendCommand sendCommand)
 {
     _sendCommandQueue.QueueCommand(sendCommand);
 }
开发者ID:DiLRandI,项目名称:Arduino-CmdMessenger,代码行数:6,代码来源:CmdMessenger.cs


示例18: SendCommandSync

 /// <summary> Synchronized send a command. </summary>
 /// <param name="sendCommand">    The command to sent. </param>
 /// <param name="sendQueueState"> Property to optionally clear/wait the send queue. </param>
 /// <returns> . </returns>
 public ReceivedCommand SendCommandSync(SendCommand sendCommand, SendQueue sendQueueState)
 {
     // Directly call execute command
     var resultSendCommand = _communicationManager.ExecuteSendCommand(sendCommand, sendQueueState);
     InvokeNewLineEvent(NewLineSent, new CommandEventArgs(sendCommand));
     return resultSendCommand;            
 }
开发者ID:DiLRandI,项目名称:Arduino-CmdMessenger,代码行数:11,代码来源:CmdMessenger.cs


示例19: SendCommand

        /// <summary> Sends a command. 
        /// 		  If no command acknowledge is requested, the command will be send asynchronously: it will be put on the top of the send queue
        ///  		  If a  command acknowledge is requested, the command will be send synchronously:  the program will block until the acknowledge command 
        ///  		  has been received or the timeout has expired.
        ///  		  Based on ClearQueueState, the send- and receive-queues are left intact or are cleared</summary>
        /// <param name="sendCommand"> The command to sent. </param>
        /// <param name="clearQueueState"> Property to optionally clear the send and receive queues</param>
        /// <returns> A received command. The received command will only be valid if the ReqAc of the command is true. </returns>
        public ReceivedCommand SendCommand(SendCommand sendCommand, ClearQueue clearQueueState)
        {
            //_sendCommandLogger.LogLine(CommandToString(sendCommand) + _commandSeparator);

            if (clearQueueState == ClearQueue.ClearReceivedQueue ||
                clearQueueState == ClearQueue.ClearSendAndReceivedQueue)
            {
                // Clear receive queue
                _receiveCommandQueue.Clear();
            }

            if (clearQueueState == ClearQueue.ClearSendQueue ||
                clearQueueState == ClearQueue.ClearSendAndReceivedQueue)
            {
                // Clear send queue
                _sendCommandQueue.Clear();
            }

            if (sendCommand.ReqAc)
            {
                // Directly call execute command
                return ExecuteSendCommand(sendCommand, clearQueueState);
            }

            // Put command at top of command queue
            _sendCommandQueue.SendCommand(sendCommand);
            return new ReceivedCommand();
        }
开发者ID:vikramt,项目名称:Arduino,代码行数:36,代码来源:CmdMessenger.cs


示例20: 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



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Constants.Sql类代码示例发布时间:2022-05-24
下一篇:
C# CommandMessenger.ReceivedCommand类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap