Exemple #1
0
 /**
  * Adds the given packet receive listener to the list of listeners that will
  * be notified when an XBee packet with the given frame ID is received.
  *
  * <p>If the listener has been already added, this method does nothing.</p>
  *
  * @param listener Listener to be notified when an XBee packet with the
  *                 provided frame ID is received.
  * @param frameID Frame ID for which this listener should be notified and
  *                removed after.
  *                Using {@link #ALL_FRAME_IDS} this listener will be
  *                notified always and will be removed only by user request.
  *
  * @see #addPacketReceiveListener(IPacketReceiveListener)
  * @see #removePacketReceiveListener(IPacketReceiveListener)
  * @see com.digi.xbee.api.listeners.IPacketReceiveListener
  */
 public void AddPacketReceiveListener(IPacketReceiveListener listener, int frameID)
 {
     packetReceiveListeners.TryAdd(listener, frameID);
 }
Exemple #2
0
        /**
         * Removes the given packet receive listener from the list of XBee packet
         * receive listeners.
         *
         * <p>If the listener is not included in the list, this method does nothing.
         * </p>
         *
         * @param listener Packet receive listener to remove from the list.
         *
         * @see #addPacketReceiveListener(IPacketReceiveListener)
         * @see #addPacketReceiveListener(IPacketReceiveListener, int)
         * @see com.digi.xbee.api.listeners.IPacketReceiveListener
         */
        public void RemovePacketReceiveListener(IPacketReceiveListener listener)
        {
            int value;

            packetReceiveListeners.TryRemove(listener, out value);
        }
 /*throws XBeeException */
 /**
  * Sends the given XBee packet and registers the given packet listener
  * (if not {@code null}) to be notified when the answers is received.
  *
  * <p>This is a non-blocking operation. To wait for the answer use
  * {@code sendPacket(XBeePacket)}.</p>
  *
  * @param packet XBee packet to be sent.
  * @param packetReceiveListener Listener for the operation, {@code null}
  *                              not to be notified when the answer arrives.
  *
  * @throws InterfaceNotOpenException if this device connection is not open.
  * @throws ArgumentNullException if {@code packet == null}.
  * @throws XBeeException if there is any other XBee related exception.
  *
  * @see #sendPacket(XBeePacket)
  * @see #sendPacketAsync(XBeePacket)
  * @see com.digi.xbee.api.listeners.IPacketReceiveListener
  * @see com.digi.xbee.api.packet.XBeePacket
  */
 public void SendPacket(XBeePacket packet, IPacketReceiveListener packetReceiveListener)
 {
     try
     {
         SendXBeePacket(packet, packetReceiveListener);
     }
     catch (IOException e)
     {
         throw new XBeeException("Error writing in the communication interface.", e);
     }
 }
Exemple #4
0
 /**
  * Adds the given packet receive listener to the list of listeners that will
  * be notified when any XBee packet is received.
  *
  * <p>If the listener has been already added, this method does nothing.</p>
  *
  * @param listener Listener to be notified when any XBee packet is received.
  *
  * @see #addPacketReceiveListener(IPacketReceiveListener, int)
  * @see #removePacketReceiveListener(IPacketReceiveListener)
  * @see com.digi.xbee.api.listeners.IPacketReceiveListener
  */
 public void AddPacketReceiveListener(IPacketReceiveListener listener)
 {
     AddPacketReceiveListener(listener, ALL_FRAME_IDS);
 }
 /*
  * (non-Javadoc)
  * @see com.digi.xbee.api.AbstractXBeeDevice#addPacketListener(com.digi.xbee.api.listeners.IPacketReceiveListener)
  */
 //@Override
 public new void AddPacketListener(IPacketReceiveListener listener)
 {
     base.AddPacketListener(listener);
 }
 /*
  * (non-Javadoc)
  * @see com.digi.xbee.api.AbstractXBeeDevice#removePacketListener(com.digi.xbee.api.listeners.IPacketReceiveListener)
  */
 //@Override
 public new void RemovePacketListener(IPacketReceiveListener listener)
 {
     base.RemovePacketListener(listener);
 }
		/**
		 * Sends the given XBee packet asynchronously and registers the given 
		 * packet listener (if not {@code null}) to wait for an answer.
		 * 
		 * <p>The method will not wait for an answer for the packet, but the given 
		 * listener will be notified when the answer arrives.</p>
		 * 
		 * @param packet XBee packet to be sent.
		 * @param packetReceiveListener Listener for the operation, {@code null} 
		 *                              not to be notified when the answer arrives.
		 * 
		 * @throws InterfaceNotOpenException if this device connection is not open.
		 * @throws InvalidOperatingModeException if the operating mode is different 
		 *                                       than {@link OperatingMode#API} and 
		 *                                       {@link OperatingMode#API_ESCAPE}.
		 * @throws IOException if an I/O error occurs while sending the XBee packet.
		 * @throws ArgumentNullException if {@code packet == null}.
		 * 
		 * @see #sendXBeePacket(XBeePacket)
		 * @see #sendXBeePacket(XBeePacket, IPacketReceiveListener)
		 * @see #sendXBeePacketAsync(XBeePacket)
		 * @see com.digi.xbee.api.listeners.IPacketReceiveListener
		 * @see com.digi.xbee.api.packet.XBeePacket
		 */
		protected void SendXBeePacket(XBeePacket packet, IPacketReceiveListener packetReceiveListener)
		/*throws InvalidOperatingModeException, IOException*/ {
			// Check if the packet to send is null.
			if (packet == null)
				throw new ArgumentNullException("XBee packet cannot be null.");
			// Check connection.
			if (!connectionInterface.SerialPort.IsOpen)
				throw new InterfaceNotOpenException();

			OperatingMode operatingMode = GetOperatingMode();
			switch (operatingMode)
			{
				case OperatingMode.AT:
				case OperatingMode.UNKNOWN:
				default:
					throw new InvalidOperatingModeException(operatingMode);
				case OperatingMode.API:
				case OperatingMode.API_ESCAPE:
					// Add the required frame ID and subscribe listener if given.
					if (packet is XBeeAPIPacket)
					{
						if (((XBeeAPIPacket)packet).NeedsAPIFrameID)
						{
							if (((XBeeAPIPacket)packet).FrameID == XBeeAPIPacket.NO_FRAME_ID)
								((XBeeAPIPacket)packet).FrameID = GetNextFrameID();
							if (packetReceiveListener != null)
								dataReader.AddPacketReceiveListener(packetReceiveListener, ((XBeeAPIPacket)packet).FrameID);
						}
						else if (packetReceiveListener != null)
							dataReader.AddPacketReceiveListener(packetReceiveListener);
					}

					// Write packet data.
					WritePacket(packet);
					break;
			}
		}
		/**
		 * Removes the provided listener from the list of packets listeners. 
		 * 
		 * <p>If the listener was not in the list this method does nothing.</p>
		 * 
		 * @param listener Listener to be removed from the list of listeners.
		 * 
		 * @throws ArgumentNullException if {@code listener == null}
		 * 
		 * @see #addPacketListener(IPacketReceiveListener)
		 * @see com.digi.xbee.api.listeners.IPacketReceiveListener
		 */
		protected void RemovePacketListener(IPacketReceiveListener listener)
		{
			if (listener == null)
				throw new ArgumentNullException("Listener cannot be null.");

			if (dataReader == null)
				return;
			dataReader.RemovePacketReceiveListener(listener);
		}
 /**
  * Removes the given packet receive listener from the list of XBee packet
  * receive listeners.
  *
  * <p>If the listener is not included in the list, this method does nothing.
  * </p>
  *
  * @param listener Packet receive listener to remove from the list.
  *
  * @see #addPacketReceiveListener(IPacketReceiveListener)
  * @see #addPacketReceiveListener(IPacketReceiveListener, int)
  * @see com.digi.xbee.api.listeners.IPacketReceiveListener
  */
 public void RemovePacketReceiveListener(IPacketReceiveListener listener)
 {
     int value;
     packetReceiveListeners.TryRemove(listener, out value);
 }
 /**
  * Adds the given packet receive listener to the list of listeners that will
  * be notified when an XBee packet with the given frame ID is received.
  *
  * <p>If the listener has been already added, this method does nothing.</p>
  *
  * @param listener Listener to be notified when an XBee packet with the
  *                 provided frame ID is received.
  * @param frameID Frame ID for which this listener should be notified and
  *                removed after.
  *                Using {@link #ALL_FRAME_IDS} this listener will be
  *                notified always and will be removed only by user request.
  *
  * @see #addPacketReceiveListener(IPacketReceiveListener)
  * @see #removePacketReceiveListener(IPacketReceiveListener)
  * @see com.digi.xbee.api.listeners.IPacketReceiveListener
  */
 public void AddPacketReceiveListener(IPacketReceiveListener listener, int frameID)
 {
     packetReceiveListeners.TryAdd(listener, frameID);
 }
 /**
  * Adds the given packet receive listener to the list of listeners that will
  * be notified when any XBee packet is received.
  *
  * <p>If the listener has been already added, this method does nothing.</p>
  *
  * @param listener Listener to be notified when any XBee packet is received.
  *
  * @see #addPacketReceiveListener(IPacketReceiveListener, int)
  * @see #removePacketReceiveListener(IPacketReceiveListener)
  * @see com.digi.xbee.api.listeners.IPacketReceiveListener
  */
 public void AddPacketReceiveListener(IPacketReceiveListener listener)
 {
     AddPacketReceiveListener(listener, ALL_FRAME_IDS);
 }