コード例 #1
0
 /**
  * Class constructor. Instantiates a new {@code RemoteDigiPointDevice} object
  * with the given local {@code XBeeDevice} which contains the connection
  * interface to be used.
  *
  * @param localXBeeDevice The local XBee device that will behave as
  *                        connection interface to communicate with this
  *                        remote point-to-multipoint device.
  * @param addr64 The 64-bit address to identify this remote point-to-multipoint
  *               device.
  * @param id The node identifier of this remote point-to-multipoint device.
  *           It might be {@code null}.
  *
  * @throws ArgumentException if {@code localXBeeDevice.isRemote() == true} or
  *                                  if {@code localXBeeDevice.getXBeeProtocol() != XBeeProtocol.DIGI_POINT}.
  * @throws ArgumentNullException if {@code localXBeeDevice == null} or
  *                              if {@code addr64 == null}.
  *
  * @see com.digi.xbee.api.models.XBee64BitAddress
  */
 public RemoteDigiPointDevice(XBeeDevice localXBeeDevice, XBee64BitAddress addr64, string id)
     : base(localXBeeDevice, addr64, null, id)
 {
     // Verify the local device has point-to-multipoint protocol.
     if (localXBeeDevice.XBeeProtocol != XBeeProtocol.DIGI_POINT)
     {
         throw new ArgumentException("The protocol of the local XBee device is not " + XBeeProtocol.DIGI_POINT.GetDescription() + ".");
     }
 }
コード例 #2
0
 /**
  * Class constructor. Instantiates a new {@code RemoteDigiMeshDevice} object
  * with the given local {@code XBeeDevice} which contains the connection
  * interface to be used.
  *
  * @param localXBeeDevice The local XBee device that will behave as
  *                        connection interface to communicate with this
  *                        remote DigiMesh device.
  * @param addr64 The 64-bit address to identify this remote DigiMesh device.
  * @param id The node identifier of this remote DigiMesh device. It might
  *           be {@code null}.
  *
  * @throws ArgumentException if {@code localXBeeDevice.isRemote() == true} or
  *                                  if {@code localXBeeDevice.getXBeeProtocol() != XBeeProtocol.DIGI_MESH}.
  * @throws ArgumentNullException if {@code localXBeeDevice == null} or
  *                              if {@code addr64 == null}.
  *
  * @see com.digi.xbee.api.models.XBee64BitAddress
  */
 public RemoteDigiMeshDevice(XBeeDevice localXBeeDevice, XBee64BitAddress addr64, string id)
     : base(localXBeeDevice, addr64, null, id)
 {
     // Verify the local device has DigiMesh protocol.
     if (localXBeeDevice.XBeeProtocol != Models.XBeeProtocol.DIGI_MESH)
     {
         throw new ArgumentException("The protocol of the local XBee device is not " + XBeeProtocol.DIGI_MESH.GetDescription() + ".");
     }
 }
コード例 #3
0
 /**
  * Class constructor. Instantiates a new {@code RemoteZigBeeDevice} object
  * with the given local {@code XBeeDevice} which contains the connection
  * interface to be used.
  *
  * @param localXBeeDevice The local XBee device that will behave as
  *                        connection interface to communicate with this
  *                        remote ZigBee device.
  * @param addr64 The 64-bit address to identify this remote ZigBee device.
  *
  * @throws ArgumentException if {@code localXBeeDevice.isRemote() == true} or
  *                                  if {@code localXBeeDevice.getXBeeProtocol() != XBeeProtocol.ZIGBEE}.
  * @throws ArgumentNullException if {@code localXBeeDevice == null} or
  *                              if {@code addr64 == null}.
  *
  * @see com.digi.xbee.api.models.XBee64BitAddress
  */
 public RemoteZigBeeDevice(XBeeDevice localXBeeDevice, XBee64BitAddress addr64)
     : base(localXBeeDevice, addr64)
 {
     // Verify the local device has ZigBee protocol.
     if (localXBeeDevice.XBeeProtocol != XBeeProtocol.ZIGBEE)
     {
         throw new ArgumentException("The protocol of the local XBee device is not " + XBeeProtocol.ZIGBEE.GetDescription() + ".");
     }
 }
コード例 #4
0
 /**
  * Class constructor. Instantiates a new {@code RemoteRaw802Device} object
  * with the given local {@code XBeeDevice} which contains the connection
  * interface to be used.
  *
  * @param localXBeeDevice The local XBee device that will behave as
  *                        connection interface to communicate with this
  *                        remote 802.15.4 device.
  * @param addr64 The 64-bit address to identify this remote 802.15.4 device.
  * @param addr16 The 16-bit address to identify this remote 802.15.4 device.
  *               It might be {@code null}.
  * @param id The node identifier of this remote 802.15.4 device. It might be
  *           {@code null}.
  *
  * @throws ArgumentException if {@code localXBeeDevice.isRemote() == true} or
  *                                  if {@code localXBeeDevice.getXBeeProtocol() != XBeeProtocol.RAW_802_15_4}
  * @throws ArgumentNullException if {@code localXBeeDevice == null} or
  *                              if {@code addr64 == null}.
  *
  * @see com.digi.xbee.api.models.XBee16BitAddress
  * @see com.digi.xbee.api.models.XBee64BitAddress
  */
 public RemoteRaw802Device(XBeeDevice localXBeeDevice, XBee64BitAddress addr64,
                           XBee16BitAddress addr16, string id)
     : base(localXBeeDevice, addr64, addr16, id)
 {
     // Verify the local device has 802.15.4 protocol.
     if (localXBeeDevice.XBeeProtocol != XBeeProtocol.RAW_802_15_4)
     {
         throw new ArgumentException("The protocol of the local XBee device is not " + XBeeProtocol.RAW_802_15_4.GetDescription() + ".");
     }
 }
コード例 #5
0
        public async Task Discover()
        {
            var devices = await XBeeDevice.Discover();

            Assert.IsTrue(devices.Count > 0);
            foreach (var device in devices)
            {
                device.Dispose();
            }
        }
コード例 #6
0
        /**
         * Class constructor. Instantiates a new {@code RemoteRaw802Device} object
         * interface to be used.
         *
         * @param localXBeeDevice The local 802.15.4 device that will behave as
         *                        connection interface to communicate with this
         *                        remote 802.15.4 device.
         * @param addr16 The 16-bit address to identify this remote 802.15.4
         *               device.
         *
         * @throws ArgumentException if {@code localXBeeDevice.getXBeeProtocol() != XBeeProtocol.RAW_802_15_4}.
         * @throws ArgumentNullException if {@code localXBeeDevice == null} or
         *                              if {@code addr16 == null}.
         *
         * @see com.digi.xbee.api.models.XBee16BitAddress
         */
        public RemoteRaw802Device(XBeeDevice localXBeeDevice, XBee16BitAddress addr16)
            : base(localXBeeDevice, XBee64BitAddress.UNKNOWN_ADDRESS)
        {
            // Verify the local device has 802.15.4 protocol.
            if (localXBeeDevice.XBeeProtocol != XBeeProtocol.RAW_802_15_4)
            {
                throw new ArgumentException("The protocol of the local XBee device is not " + XBeeProtocol.RAW_802_15_4.GetDescription() + ".");
            }

            this.xbee16BitAddress = addr16;
        }
コード例 #7
0
        /**
         * Class constructor. Instantiates a new {@code DataReader} object for the
         * given connection interface using the given XBee operating mode and XBee
         * device.
         *
         * @param connectionInterface Connection interface to read data from.
         * @param mode XBee operating mode.
         * @param xbeeDevice Reference to the XBee device containing this
         *                   {@code DataReader} object.
         *
         * @throws ArgumentNullException if {@code connectionInterface == null} or
         *                                 {@code mode == null}.
         *
         * @see IConnectionInterface
         * @see com.digi.xbee.api.XBeeDevice
         * @see com.digi.xbee.api.models.OperatingMode
         */
        public DataReader(IConnectionInterface connectionInterface, OperatingMode mode, XBeeDevice xbeeDevice)
        {
            if (connectionInterface == null)
                throw new ArgumentNullException("Connection interface cannot be null.");
            if (mode == null)
                throw new ArgumentNullException("Operating mode cannot be null.");

            this.connectionInterface = connectionInterface;
            this.mode = mode;
            this.xbeeDevice = xbeeDevice;
            this.logger = LogManager.GetLogger<DataReader>();
            parser = new XBeePacketParser();
            xbeePacketsQueue = new XBeePacketsQueue();
        }
コード例 #8
0
        /// <summary>
        /// Initializes a new instance of <see cref="XBeeNetwork"/>.
        /// </summary>
        /// <param name="device">A local XBee device to get the network from.</param>
        public XBeeNetwork(XBeeDevice device)
        {
            if (device == null)
            {
                throw new ArgumentNullException("Local XBee device cannot be null.");
            }

            localDevice        = device;
            remotesBy64BitAddr = new ConcurrentDictionary <XBee64BitAddress, RemoteXBeeDevice>();
            remotesBy16BitAddr = new ConcurrentDictionary <XBee16BitAddress, RemoteXBeeDevice>();
            nodeDiscovery      = new NodeDiscovery(localDevice);

            logger = LogManager.GetLogger(this.GetType());
        }
コード例 #9
0
ファイル: Reader.cs プロジェクト: orenbell-nidec/csharp-xbee
 public PacketListener(SerialPort serialPort, XBeeDevice xbeeDevice, int queueMaxSize = -1)
 {
     foreach (Reader.PacketReceivedHandler handler in xbeeDevice.GetXBeeDeviceCallbacks())
     {
         // Get list of internal callbacks from device, and subscribe them all to PacketReceivedAPI
         PacketReceivedAPI += handler;
     }
     this.xbeeDevice   = xbeeDevice;
     this.comPort      = serialPort;
     this.stop         = true;
     this.queueMaxSize = (queueMaxSize < 0) ? DEFAULT_QUEUE_MAX_SIZE : queueMaxSize;
     XBeeQueue         = new XBeeQueue(this.queueMaxSize);
     DataXBeeQueue     = new XBeeQueue(this.queueMaxSize);
     ExplicitXBeeQueue = new XBeeQueue(this.queueMaxSize);
     IPXBeeQueue       = new XBeeQueue(this.queueMaxSize);
 }
コード例 #10
0
        /**
         * Class constructor. Instantiates a new {@code DataReader} object for the
         * given connection interface using the given XBee operating mode and XBee
         * device.
         *
         * @param connectionInterface Connection interface to read data from.
         * @param mode XBee operating mode.
         * @param xbeeDevice Reference to the XBee device containing this
         *                   {@code DataReader} object.
         *
         * @throws ArgumentNullException if {@code connectionInterface == null} or
         *                                 {@code mode == null}.
         *
         * @see IConnectionInterface
         * @see com.digi.xbee.api.XBeeDevice
         * @see com.digi.xbee.api.models.OperatingMode
         */
        public DataReader(IConnectionInterface connectionInterface, OperatingMode mode, XBeeDevice xbeeDevice)
        {
            if (connectionInterface == null)
            {
                throw new ArgumentNullException("Connection interface cannot be null.");
            }
            if (mode == null)
            {
                throw new ArgumentNullException("Operating mode cannot be null.");
            }

            this.connectionInterface = connectionInterface;
            this.mode        = mode;
            this.xbeeDevice  = xbeeDevice;
            this.logger      = LogManager.GetLogger <DataReader>();
            parser           = new XBeePacketParser();
            xbeePacketsQueue = new XBeePacketsQueue();
        }
コード例 #11
0
        /**
         * Instantiates a new {@code NodeDiscovery} object.
         *
         * @param xbeeDevice XBee Device to perform the discovery operation.
         *
         * @throws ArgumentNullException If {@code xbeeDevice == null}.
         *
         * @see XBeeDevice
         */
        public NodeDiscovery(XBeeDevice xbeeDevice)
        {
            if (xbeeDevice == null)
            {
                throw new ArgumentNullException("Local XBee device cannot be null.");
            }

            this.xbeeDevice = xbeeDevice;

            frameID = globalFrameID;
            globalFrameID++;
            if (globalFrameID == 0xFF)
            {
                globalFrameID = 1;
            }

            logger = LogManager.GetLogger(this.GetType());
        }
コード例 #12
0
        public static void Main()
        {
            var port = new SerialPort("COM1", 9600, Parity.None, 8, StopBits.One);

            port.Open();

            var xbee = new XBeeDevice(port, (Cpu.Pin) 17, (Cpu.Pin) 45);

            Debug.Print("MAC address : " + DumpU64(xbee.GetSerialNumber()));

            Debug.Print("Waiting for association...");
            while (xbee.GetAssociationState() != XBeeDevice.AssociationIndication.Success)
            {
                Thread.Sleep(100);
            }

            Debug.Print("Associated - Sending test packet");
            xbee.Send(0UL, "Hello there coordinator");

            xbee.Dispose();
        }
コード例 #13
0
        public async Task Setup()
        {
            _devices = await XBeeDevice.Discover();

            Assert.IsTrue(_devices.Count > 1, "These tests require two or more nodes attached to the test computer!");
            int  retries = 10;
            bool success = false;

            do
            {
                int count = 0;
                foreach (var device in _devices)
                {
                    if (device.GetAssociationState() == XBeeDevice.AssociationIndication.Success)
                    {
                        ++count;
                    }
                }
                if (count == _devices.Count)
                {
                    success = true;
                    break;
                }
                else
                {
                    await Task.Delay(300);
                }
            } while (!success && --retries > 0);
            Assert.IsTrue(success, "Not all devices are associated yet.");
            if (success)
            {
                _mac[0] = _devices[0].GetSerialNumber();
                _mac[1] = _devices[1].GetSerialNumber();

                _devices[0].OnPacketReceived += SendReceiveTests_OnPacketReceived;
                _devices[1].OnPacketReceived += SendReceiveTests_OnPacketReceived;
            }
        }
コード例 #14
0
        /**
         * Parses the given node discovery API data to create and return a remote
         * XBee Device.
         *
         * @param data Byte array with the data to parse.
         * @param localDevice The local device that received the remote XBee data.
         *
         * @return Discovered XBee device.
         */
        private async Task <RemoteXBeeDevice> ParseDiscoveryAPIData(byte[] data, XBeeDevice localDevice)
        {
            if (data == null)
            {
                return(null);
            }

            RemoteXBeeDevice device = null;
            XBee16BitAddress addr16 = null;
            XBee64BitAddress addr64 = null;
            String           id     = null;
            // TODO role of the device: coordinator, router, end device or unknown.
            //XBeeDeviceType role = XBeeDeviceType.UNKNOWN;
            int signalStrength = 0;

            byte[] profileID      = null;
            byte[] manufacturerID = null;

            using (var inputStream = new MemoryStream(data))
            {
                // Read 16 bit address.
                addr16 = new XBee16BitAddress(await ByteUtils.ReadBytes(2, inputStream));
                // Read 64 bit address.
                addr64 = new XBee64BitAddress(await ByteUtils.ReadBytes(8, inputStream));


                switch (localDevice.XBeeProtocol)
                {
                case XBeeProtocol.ZIGBEE:
                case XBeeProtocol.DIGI_MESH:
                case XBeeProtocol.ZNET:
                case XBeeProtocol.DIGI_POINT:
                case XBeeProtocol.XLR:
                // TODO [XLR_DM] The next version of the XLR will add DigiMesh support.
                // For the moment only point-to-multipoint is supported in this kind of devices.
                case XBeeProtocol.XLR_DM:
                    // Read node identifier.
                    id = ByteUtils.ReadString(inputStream);
                    // Read parent address.
                    XBee16BitAddress parentAddress = new XBee16BitAddress(await ByteUtils.ReadBytes(2, inputStream));
                    // TODO Read device type.
                    //role = XBeeDeviceType.get(inputStream.read());
                    // Consume status byte, it is not used yet.
                    await ByteUtils.ReadBytes(1, inputStream);

                    // Read profile ID.
                    profileID = await ByteUtils.ReadBytes(2, inputStream);

                    // Read manufacturer ID.
                    manufacturerID = await ByteUtils.ReadBytes(2, inputStream);

                    logger.DebugFormat("{0}Discovered {1} device: 16-bit[{2}], 64-bit[{3}], id[{4}], parent[{5}], profile[{6}], manufacturer[{7}].",
                                       xbeeDevice.ToString(), localDevice.XBeeProtocol.GetDescription(), addr16,
                                       addr64, id, parentAddress, HexUtils.ByteArrayToHexString(profileID),
                                       HexUtils.ByteArrayToHexString(manufacturerID));

                    break;

                case XBeeProtocol.RAW_802_15_4:
                    // Read strength signal byte.
                    signalStrength = inputStream.ReadByte();
                    // Read node identifier.
                    id = ByteUtils.ReadString(inputStream);

                    logger.DebugFormat("{0}Discovered {1} device: 16-bit[{2}], 64-bit[{3}], id[{4}], rssi[{5}].",
                                       xbeeDevice.ToString(), localDevice.XBeeProtocol.GetDescription(), addr16, addr64, id, signalStrength);

                    break;

                case XBeeProtocol.UNKNOWN:
                default:
                    logger.DebugFormat("{0}Discovered {1} device: 16-bit[{2}], 64-bit[{3}].",
                                       xbeeDevice.ToString(), localDevice.XBeeProtocol.GetDescription(), addr16, addr64);
                    break;
                }

                // Create device and fill with parameters.
                switch (localDevice.XBeeProtocol)
                {
                case XBeeProtocol.ZIGBEE:
                    device = new RemoteZigBeeDevice(localDevice, addr64, addr16, id /*, role*/);
                    // TODO profileID and manufacturerID
                    break;

                case XBeeProtocol.DIGI_MESH:
                    device = new RemoteDigiMeshDevice(localDevice, addr64, id /*, role*/);
                    // TODO profileID and manufacturerID
                    break;

                case XBeeProtocol.DIGI_POINT:
                    device = new RemoteDigiPointDevice(localDevice, addr64, id /*, role*/);
                    // TODO profileID and manufacturerID
                    break;

                case XBeeProtocol.RAW_802_15_4:
                    device = new RemoteRaw802Device(localDevice, addr64, addr16, id /*, role*/);
                    // TODO signalStrength
                    break;

                default:
                    device = new RemoteXBeeDevice(localDevice, addr64, addr16, id /*, role*/);
                    break;
                }
            }

            return(device);
        }
コード例 #15
0
        public async Task Setup()
        {
            _devices = await XBeeDevice.Discover();

            Assert.IsTrue(_devices.Count > 0, "No devices found!");
        }
コード例 #16
0
 /**
  * Class constructor. Instantiates a new {@code RemoteXBeeDevice} object
  * with the given local {@code XBeeDevice} which contains the connection
  * interface to be used.
  *
  * @param localXBeeDevice The local XBee device that will behave as
  *                        connection interface to communicate with this
  *                        remote XBee device.
  * @param addr64 The 64-bit address to identify this remote XBee device.
  *
  * @throws ArgumentException if {@code localXBeeDevice.isRemote() == true}.
  * @throws ArgumentNullException if {@code localXBeeDevice == null} or
  *                              if {@code addr64 == null}.
  *
  * @see com.digi.xbee.api.models.XBee64BitAddress
  */
 public RemoteXBeeDevice(XBeeDevice localXBeeDevice, XBee64BitAddress addr64)
     : base(localXBeeDevice, addr64)
 {
 }
コード例 #17
0
 /**
  * Class constructor. Instantiates a new {@code RemoteXBeeDevice} object
  * with the given local {@code XBeeDevice} which contains the connection
  * interface to be used.
  *
  * @param localXBeeDevice The local XBee device that will behave as
  *                        connection interface to communicate with this
  *                        remote XBee device.
  * @param addr64 The 64-bit address to identify this remote XBee device.
  * @param addr16 The 16-bit address to identify this remote XBee device. It
  *               might be {@code null}.
  * @param ni The node identifier of this remote XBee device. It might be
  *           {@code null}.
  *
  * @throws ArgumentException if {@code localXBeeDevice.isRemote() == true}.
  * @throws ArgumentNullException if {@code localXBeeDevice == null} or
  *                              if {@code addr64 == null}.
  *
  * @see com.digi.xbee.api.models.XBee16BitAddress
  * @see com.digi.xbee.api.models.XBee64BitAddress
  */
 public RemoteXBeeDevice(XBeeDevice localXBeeDevice, XBee64BitAddress addr64,
                         XBee16BitAddress addr16, string ni)
     : base(localXBeeDevice, addr64, addr16, ni)
 {
 }
コード例 #18
0
 private async void MainPage_Loaded(object sender, RoutedEventArgs e)
 {
     var devices = await XBeeDevice.Discover();
 }
コード例 #19
0
 public XBGateway(XBeeDevice coordinator)
 {
     Coordinator = coordinator;
 }