コード例 #1
0
        /*throws TimeoutException, XBeeException */
        /**
         * Sends the provided data to the XBee device of the network corresponding
         * to the given 64-bit/16-bit address.
         *
         * <p>This method blocks till a success or error response arrives or the
         * configured receive timeout expires.</p>
         *
         * <p>The received timeout is configured using the {@code setReceiveTimeout}
         * method and can be consulted with {@code getReceiveTimeout} method.</p>
         *
         * <p>For non-blocking operations use the method
         * {@link #sendDataAsync(XBee64BitAddress, XBee16BitAddress, byte[])}.</p>
         *
         * @param address64Bit The 64-bit address of the XBee that will receive the
         *                     data.
         * @param address16bit The 16-bit address of the XBee that will receive the
         *                     data. If it is unknown the
         *                     {@code XBee16BitAddress.UNKNOWN_ADDRESS} must be
         *                     used.
         * @param data Byte array containing the data to be sent.
         *
         * @throws InterfaceNotOpenException if this device connection is not open.
         * @throws ArgumentNullException if {@code address64Bit == null} or
         *                              if {@code address16bit == null} or
         *                              if {@code data == null}.
         * @throws TimeoutException if there is a timeout sending the data.
         * @throws XBeeException if a remote device is trying to send data or
         *                       if there is any other XBee related exception.
         *
         * @see #getReceiveTimeout()
         * @see #setReceiveTimeout(int)
         * @see #sendData(RemoteXBeeDevice, byte[])
         * @see #sendData(XBee64BitAddress, byte[])
         * @see #sendDataAsync(RemoteXBeeDevice, byte[])
         * @see #sendDataAsync(XBee64BitAddress, byte[])
         * @see #sendDataAsync(XBee64BitAddress, XBee16BitAddress, byte[])
         * @see com.digi.xbee.api.models.XBee16BitAddress
         * @see com.digi.xbee.api.models.XBee64BitAddress
         */
        protected void SendData(XBee64BitAddress address64Bit, XBee16BitAddress address16bit, byte[] data)
        {
            // Verify the parameters are not null, if they are null, throw an exception.
            if (address64Bit == null)
                throw new ArgumentNullException("64-bit address cannot be null");
            if (address16bit == null)
                throw new ArgumentNullException("16-bit address cannot be null");
            if (data == null)
                throw new ArgumentNullException("Data cannot be null");

            // Check connection.
            if (!connectionInterface.SerialPort.IsOpen)
                throw new InterfaceNotOpenException();
            // Check if device is remote.
            if (IsRemote)
                throw new OperationNotSupportedException("Cannot send data to a remote device from a remote device.");

            logger.DebugFormat(ToString() + "Sending data to {0}[{1}] >> {2}.",
                    address64Bit, address16bit, HexUtils.PrettyHexString(data));

            XBeePacket xbeePacket = new TransmitPacket(GetNextFrameID(), address64Bit, address16bit, 0, (byte)XBeeTransmitOptions.NONE, data);
            SendAndCheckXBeePacket(xbeePacket, false);
        }
コード例 #2
0
        /*throws TimeoutException, XBeeException */
        /**
         * Sends the provided data to the XBee device of the network corresponding
         * to the given 64-bit address.
         *
         * <p>This method blocks till a success or error response arrives or the
         * configured receive timeout expires.</p>
         *
         * <p>The received timeout is configured using the {@code setReceiveTimeout}
         * method and can be consulted with {@code getReceiveTimeout} method.</p>
         *
         * <p>For non-blocking operations use the method
         * {@link #sendData(XBee64BitAddress, byte[])}.</p>
         *
         * @param address The 64-bit address of the XBee that will receive the data.
         * @param data Byte array containing the data to be sent.
         *
         * @throws InterfaceNotOpenException if this device connection is not open.
         * @throws ArgumentNullException if {@code address == null} or
         *                              if {@code data == null}.
         * @throws TimeoutException if there is a timeout sending the data.
         * @throws XBeeException if there is any other XBee related exception.
         *
         * @see #getReceiveTimeout()
         * @see #setReceiveTimeout(int)
         * @see #sendData(RemoteXBeeDevice, byte[])
         * @see #sendData(XBee64BitAddress, XBee16BitAddress, byte[])
         * @see #sendDataAsync(RemoteXBeeDevice, byte[])
         * @see #sendDataAsync(XBee64BitAddress, byte[])
         * @see #sendDataAsync(XBee64BitAddress, XBee16BitAddress, byte[])
         * @see com.digi.xbee.api.models.XBee64BitAddress
         */
        protected void SendData(XBee64BitAddress address, byte[] data)
        {
            // Verify the parameters are not null, if they are null, throw an exception.
            if (address == null)
                throw new ArgumentNullException("Address cannot be null");
            if (data == null)
                throw new ArgumentNullException("Data cannot be null");

            // Check connection.
            if (!connectionInterface.SerialPort.IsOpen)
                throw new InterfaceNotOpenException();
            // Check if device is remote.
            if (IsRemote)
                throw new OperationNotSupportedException("Cannot send data to a remote device from a remote device.");

            logger.DebugFormat(ToString() + "Sending data to {0} >> {1}.", address, HexUtils.PrettyHexString(data));

            XBeePacket xbeePacket;
            switch (XBeeProtocol)
            {
                case XBeeProtocol.RAW_802_15_4:
                    xbeePacket = new TX64Packet(GetNextFrameID(), address, (byte)XBeeTransmitOptions.NONE, data);
                    break;
                default:
                    xbeePacket = new TransmitPacket(GetNextFrameID(), address, XBee16BitAddress.UNKNOWN_ADDRESS, 0, (byte)XBeeTransmitOptions.NONE, data);
                    break;
            }
            SendAndCheckXBeePacket(xbeePacket, false);
        }