Пример #1
0
        public XBeeResponse[] CollectResponses(int timeout = -1, IPacketFilter filter = null)
        {
            var listener = new PacketListener(filter);

            try
            {
                AddPacketListener(listener);
                return(listener.GetPackets(timeout));
            }
            finally
            {
                RemovePacketListener(listener);
            }
        }
Пример #2
0
        public XBeeResponse Receive(Type expectedType = null, int timeout = PacketParser.DefaultParseTimeout)
        {
            var listener = new PacketListener(new PacketTypeFilter(expectedType ?? typeof(XBeeResponse)));

            try
            {
                AddPacketListener(listener);
                var responses = listener.GetPackets(timeout);

                if (responses.Length == 0)
                {
                    throw new XBeeTimeoutException();
                }

                return(responses[0]);
            }
            finally
            {
                _parser.RemovePacketListener(listener);
            }
        }