Пример #1
0
        private static async Task <List <Aparelho> > CallDeviceInfo(String[] sp)
        {
            try
            {
                List <Aparelho> aps = new List <Aparelho>();

                AtCommand atc = new AtCommand();

                await sp.ToList().ForEachAsync(async x =>
                {
                    Console.Clear();
                    //String valor1 = await atc.ExecuteCommand("ATZ\r\n", x);
                    String valor2 = await atc.ExecuteCommand("AT+DEVCONINFO\r\n", x);
                    //String valor3 = await atc.ExecuteCommand("AT+SVCIFPGM=1,1", x);

                    Aparelho ap = AparelhoService.DataInfoParser(valor2, x);
                    if (ap.Modelo == null)
                    {
                        return;
                    }

                    aps.Add(ap);
                });

                return(aps);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return(null);
            }
        }
Пример #2
0
        /// <summary>
        /// Send an AT command to a node and wait for a response.
        /// </summary>
        /// <typeparam name="TResponseData">The expected response data type</typeparam>
        /// <param name="command">The command to send</param>
        /// <param name="address">The address of the node.  If this is null the command will be sent to the local node.</param>
        /// <returns>The response data</returns>
        public async Task <TResponseData> ExecuteAtQueryAsync <TResponseData>(AtCommand command,
                                                                              NodeAddress address = null)
            where TResponseData : AtCommandResponseFrameData
        {
            AtCommandResponseFrameContent responseContent;

            if (address == null)
            {
                var atCommandFrame = new AtCommandFrameContent(command);
                AtCommandResponseFrame response = await ExecuteQueryAsync <AtCommandResponseFrame>(atCommandFrame, DefaultLocalQueryTimeout);

                responseContent = response.Content;
            }
            else
            {
                address.ShortAddress = address.LongAddress.IsBroadcast ? ShortAddress.Broadcast : ShortAddress.Disabled;

                var remoteCommand = new RemoteAtCommandFrameContent(address, command);
                RemoteAtCommandResponseFrame response =
                    await ExecuteQueryAsync <RemoteAtCommandResponseFrame>(remoteCommand, DefaultRemoteQueryTimeout);

                responseContent = response.Content;
            }

            if (responseContent.Status != AtCommandStatus.Success)
            {
                throw new AtCommandException(responseContent.Status);
            }

            return(responseContent.Data as TResponseData);
        }
Пример #3
0
        /// <summary>
        ///     Send an AT command to a node and wait for a response.
        /// </summary>
        /// <typeparam name="TResponseData">The expected response data type</typeparam>
        /// <param name="command">The command to send</param>
        /// <param name="address">The address of the node.  If this is null the command will be sent to the local node.</param>
        /// <param name="timeout"></param>
        /// <param name="queueLocal">Queue this command for deferred execution if issued to a local controller.</param>
        /// <returns>The response data</returns>
        internal async Task <TResponseData> ExecuteAtQueryAsync <TResponseData>(AtCommand command,
                                                                                NodeAddress address, TimeSpan timeout, bool queueLocal = false)
            where TResponseData : AtCommandResponseFrameData
        {
            AtCommandResponseFrameContent responseContent;

            if (address == null)
            {
                var atCommandFrame = queueLocal ? new AtQueuedCommandFrameContent(command) : new AtCommandFrameContent(command);
                var response       = await ExecuteQueryAsync <AtCommandResponseFrame>(atCommandFrame, timeout);

                responseContent = response.Content;
            }
            else
            {
                address.ShortAddress = address.LongAddress.IsBroadcast ? ShortAddress.Broadcast : ShortAddress.Disabled;

                var remoteCommand = new RemoteAtCommandFrameContent(address, command);
                var response      = await ExecuteQueryAsync <RemoteAtCommandResponseFrame>(remoteCommand, timeout);

                responseContent = response.Content;
            }

            if (responseContent.Status != AtCommandStatus.Success)
            {
                throw new AtCommandException(responseContent.Status);
            }

            return(responseContent.Data as TResponseData);
        }
Пример #4
0
        /// <summary>
        ///     Send an AT command to a node and wait for a response.
        /// </summary>
        /// <typeparam name="TResponseData">The expected response data type</typeparam>
        /// <param name="command">The command to send</param>
        /// <param name="address">The address of the node.  If this is null the command will be sent to the local node.</param>
        /// <param name="queueLocal">Queue this command for deferred execution if issued to a local controller.</param>
        /// <returns>The response data</returns>
        internal async Task <TResponseData> ExecuteAtQueryAsync <TResponseData>(AtCommand command,
                                                                                NodeAddress address = null, bool queueLocal = false)
            where TResponseData : AtCommandResponseFrameData
        {
            var timeout = address == null ? DefaultLocalQueryTimeout : DefaultRemoteQueryTimeout;

            return(await ExecuteAtQueryAsync <TResponseData>(command, address, timeout, queueLocal));
        }
Пример #5
0
 /// <summary>
 /// Send an AT command to this node.
 /// </summary>
 /// <param name="command"></param>
 /// <param name="address"></param>
 /// <returns></returns>
 public async Task ExecuteAtCommand(AtCommand command, NodeAddress address = null)
 {
     if (address == null)
     {
         var atCommandFrame = new AtCommandFrameContent(command);
         await ExecuteAsync(atCommandFrame);
     }
     else
     {
         var remoteCommand = new RemoteAtCommandFrameContent(address, command);
         await ExecuteAsync(remoteCommand);
     }
 }
Пример #6
0
        /// <summary>
        ///     Send an AT command to this node.
        /// </summary>
        /// <param name="command"></param>
        /// <param name="address"></param>
        /// <param name="queueLocal"></param>
        /// <returns></returns>
        internal async Task ExecuteAtCommand(AtCommand command, NodeAddress address = null, bool queueLocal = false)
        {
            if (address == null)
            {
                var atCommandFrame = queueLocal
                    ? new AtQueuedCommandFrameContent(command)
                    : new AtCommandFrameContent(command);

                await ExecuteAsync(atCommandFrame);
            }
            else
            {
                var remoteCommand = new RemoteAtCommandFrameContent(address, command);
                await ExecuteAsync(remoteCommand);
            }
        }
Пример #7
0
        sealed public override void RetrieveCommands()
        {
            // Add all command and responses needed for configuring the BLE module.
            Command command = new AtCommand("AT");

            _commands.Add(command);

            //command = new NotificationCommand("AT+NOTI1");
            //_commands.Add(command);

            command = new AddressCommand("AT+ADDR?");
            _commands.Add(command);

            command = new NameCommand("AT+NAME?");
            _commands.Add(command);

            command = new FilterCommand("AT+FILT1");
            _commands.Add(command);

            command = new ShowCommand("AT+SHOW1");
            _commands.Add(command);


            command = new RoleCommand("AT+ROLE1");
            _commands.Add(command);

            command = new IMMECommand("AT+IMME1");
            _commands.Add(command);

            command = new DiscoveryCommand("AT+DISC?");
            _commands.Add(command);

            command = new ConnectCommand("AT+CON{0}");
            _commands.Add(command);

            command = new StartCommand("AT+START");
            _commands.Add(command);
        }
Пример #8
0
 /// <summary>
 /// Execute an AT command on a node without waiting for a response.
 /// </summary>
 /// <param name="command">The AT command to execute</param>
 /// <param name="address">The address of the node.  If this is null the command will be execute on the local node.</param>
 /// <returns></returns>
 public async Task ExecuteAtCommandAsync(AtCommand command, NodeAddress address = null)
 {
     await ExecuteAtQueryAsync <AtCommandResponseFrameData>(command, address);
 }
Пример #9
0
 internal Task <TResponseData> ExecuteAtQueryAsync <TResponseData>(AtCommand command)
     where TResponseData : AtCommandResponseFrameData
 {
     return(Controller.ExecuteAtQueryAsync <TResponseData>(command, GetAddressInternal()));
 }
Пример #10
0
 /// <summary>
 ///   TODO: Update Comments
 ///     
 /// </summary>
 /// <param name="atRequest" type="NETMF.OpenSource.XBee.Api.AtCommand">
 ///     <para>
 ///         
 ///     </para>
 /// </param>
 public AtResponseFilter(AtCommand atRequest)
     : this(atRequest.Command, atRequest.FrameId)
 {
 }
Пример #11
0
 protected virtual async Task ExecuteAtCommandAsync(AtCommand command, bool queueLocal = false)
 {
     await Controller.ExecuteAtCommandAsync(command, Address, queueLocal);
 }
Пример #12
0
 protected async Task <TResponseData> ExecuteAtQueryAsync <TResponseData>(AtCommand command)
     where TResponseData : AtCommandResponseFrameData
 {
     return(await Controller.ExecuteAtQueryAsync <TResponseData>(command, Address));
 }
Пример #13
0
 protected virtual async Task ExecuteAtCommandAsync(AtCommand command)
 {
     await Controller.ExecuteAtCommandAsync(command, Address);
 }
Пример #14
0
 protected async Task ExecuteAtCommand(AtCommand command)
 {
     await Controller.ExecuteAtCommand(command);
 }
Пример #15
0
 public AtCommandFrameContent(AtCommand command)
 {
     Command = command;
 }
Пример #16
0
 internal virtual Task ExecuteAtCommandAsync(AtCommand command, bool queueLocal = false)
 {
     return(Controller.ExecuteAtCommandAsync(command, GetAddressInternal(), queueLocal));
 }
Пример #17
0
 public AtQueuedCommandFrameContent(AtCommand command) : base(command)
 {
 }
Пример #18
0
 /// <summary>
 ///   TODO: Update Comments
 ///
 /// </summary>
 /// <param name="atRequest" type="NETMF.OpenSource.XBee.Api.AtCommand">
 ///     <para>
 ///
 ///     </para>
 /// </param>
 public AtResponseFilter(AtCommand atRequest)
     : this(atRequest.Command, atRequest.FrameId)
 {
 }
Пример #19
0
 public void Send(AtCommand command)
 {
     _commandQueue.Enqueue(command);
 }
Пример #20
0
 /// <summary>
 ///     Execute an AT command on a node without waiting for a response.
 /// </summary>
 /// <param name="command">The AT command to execute</param>
 /// <param name="address">The address of the node.  If this is null the command will be execute on the local node.</param>
 /// <param name="queueLocal">Queue this command for deferred execution if issued to a local controller.</param>
 /// <returns></returns>
 internal async Task ExecuteAtCommandAsync(AtCommand command, NodeAddress address = null, bool queueLocal = false)
 {
     await ExecuteAtQueryAsync <AtCommandResponseFrameData>(command, address, queueLocal);
 }