virtual protected void ExecuteCommand(ArduinoCommand command, ExecutionArguments xargs)
        {
            switch (command.CommandAlias.ToLower())
            {
            case "enable":
                bool enable = xargs != null && xargs.Arguments.Count > 0 ? Utilities.Convert.ToBoolean(xargs.Arguments[0]) : true;
                Enable(enable);
                break;

            case "disable":
                Enable(false);
                break;

            default:
                if (command.Commands.Count > 0)
                {
                    for (int i = 0; i < command.Repeat; i++)
                    {
                        foreach (var ccommand in command.Commands)
                        {
                            ExecuteCommand(ccommand, xargs != null && xargs.Deep ? xargs : null);
                            if (command.Delay > 0)
                            {
                                System.Threading.Thread.Sleep(command.Delay);
                            }
                        }
                    }     //end command repeat
                }
                else
                {
                    SendCommand(command, xargs);
                }
                break;
            }
        }
        virtual public byte ThreadExecuteCommand(String command, int repeat, int delay, List <Object> args)
        {
            //check has command
            ArduinoCommand acmd = GetCommand(command);

            if (acmd == null)
            {
                throw new Exception(String.Format("Device {0} does not have command {1}", ID, command));
            }

            //pass an empty array rather than null ... safety measure here just for the ThreadExecution Manager
            if (args == null)
            {
                args = new List <Object>();
            }

            byte tag = acmd.ExpectsResponse ? Mgr.MessageTags.CreateTag() : (byte)0;
            ExecutionArguments xargs = new ExecutionArguments(args, tag);

            //Use ThreadExecutionManager to allow for multi-threading by device
            int prevSize = ThreadExecutionManager.MaxQueueSize;

            ThreadExecutionManager.MaxQueueSize = acmd.IsCompound ? 1 : 256;
            ThreadExecutionState xs = ThreadExecutionManager.Execute <ExecutionArguments>(ID, repeat, delay, ExecuteCommand, command, xargs);

            ThreadExecutionManager.MaxQueueSize = prevSize;
            if (xs == null)
            {
                Mgr.MessageTags.Release(tag);
                tag = 0;
            }

            return(tag);
        }
        virtual public void ExecuteCommand(String commandAlias, ExecutionArguments xargs)
        {
            var command = GetCommand(commandAlias);

            if (command == null)
            {
                throw new Exception("Command with alias " + commandAlias + " does not exist");
            }

            ExecuteCommand(command, xargs);
        }
 //messaging
 virtual protected void SendCommand(ArduinoCommand command, ExecutionArguments xargs = null)
 {
     if (Mgr == null)
     {
         throw new Exception(String.Format("Device {0} has not yet been added to a device manager", ToString()));
     }
     if (!IsConnected)
     {
         throw new Exception(String.Format("Device {0} is not 'connected' to board", ToString()));
     }
     if (xargs == null)
     {
         Mgr.SendCommand(BoardID, command);
     }
     else
     {
         Mgr.SendCommand(BoardID, command, xargs.Arguments, xargs.Tag);
     }
     LastCommandSent   = command;
     LastCommandSentOn = DateTime.Now.Ticks;
 }
        public void ExecuteCommand(String command, params Object[] args)
        {
            ExecutionArguments xargs = new ExecutionArguments(new List <Object>(args));

            ExecuteCommand(command, xargs);
        }