digidotcom / xbee-java

Set of Java APIs to interact with Digi International's XBee radio frequency modules.
Mozilla Public License 2.0
80 stars 56 forks source link

DataListener not working but PacketListener does #147

Closed dotKokott closed 4 years ago

dotKokott commented 4 years ago

I am sending unicast data from one device to another (Hardware: XB8X).

I am using sendData(...) to send the data & the DataListener interface to receive it.

The DataListener is not getting called, however if I add a PacketListener I do get all the packets, including the successful Receive Packet.

device.addDataListener(this);      //not receiving anything

device.addPacketListener(this);   //works

Same behaviour when I use XCTU to send the Transmit Request.

Any idea how this could be? Thanks!

dotKokott commented 4 years ago

Update:

I looked up how the DataReader notifies these listeners (https://github.com/digidotcom/xbee-java/blob/master/library/src/main/java/com/digi/xbee/api/DataReader.java#L784) & when I copy that behaviour I can successfully retrieve the ReceivePacket:

    @Override
    public void packetReceived(XBeePacket xbp) {
        if ((xbp instanceof XBeeAPIPacket)) {
                XBeeAPIPacket apiPacket = (XBeeAPIPacket)xbp;
        APIFrameType apiType = apiPacket.getFrameType();            
                if(apiType == APIFrameType.RECEIVE_PACKET) {
                    ReceivePacket packet = (ReceivePacket)apiPacket;
                    String msg = new String(packet.getRFData());
                    System.out.println(msg);
                }            
        }                    
    }

So I am not sure why it does not work by itself.

dotKokott commented 4 years ago

Nevermind. I just did not notice that my code was throwing an Exception inside of the received because the Exception was swallowed by the calling thread.