xbee-android icon indicating copy to clipboard operation
xbee-android copied to clipboard

Xbee Device Not Found

Open shubham9436 opened this issue 5 years ago • 5 comments

I need to create an android application for communication purpose using Xbee device over USB. I have created a simple program to open the device but it throws the exception Xbee Device Not Found.

Here is the code:

package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Toast;

import com.digi.xbee.api.android.XBeeBLEDevice;
import com.digi.xbee.api.android.XBeeDevice;
import com.digi.xbee.api.exceptions.XBeeException;

public class MainActivity extends AppCompatActivity {


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
            new Thread(new Runnable() {
            @Override
            public void run() {
                XBeeDevice myXBeeDevice = new XBeeDevice(MainActivity.this, 115200);
                try {
                    myXBeeDevice.open();
                    showToastMessage("Device Opened: ");
                } catch (XBeeException e) {
                    showToastMessage("Could not open device: " + e.getMessage());
                }
            }
        }).start();
    }

    private void showToastMessage(final String message) {
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                Toast.makeText(MainActivity.this, message, Toast.LENGTH_LONG).show();
            }
        });
    }
}

shubham9436 avatar Jan 23 '20 03:01 shubham9436

Hi @shubham9436,

What XBee module do you have and how is it connected to the Android device? Are you using a Digi development board?

Best regards.

rubenmoral avatar Jan 23 '20 08:01 rubenmoral

I have XBee pro S2C. Xbee is mounted on CP2102. https://robu.in/product/xbee-usb-adaptercp/ This USB adapter is connected to my android device via OTG. No, I am not using Digi development board.

shubham9436 avatar Jan 23 '20 10:01 shubham9436

Alright, that seems to be the problem. That specific board is not registered in the list of supported boards (see this file), so the library cannot find the module.

You have two options:

  1. Instead of using that XBeeDevice constructor, use the other that allows passing a UsbDevice object, something similar to

    UsbManager usbManager = (UsbManager) context.getSystemService(Context.USB_SERVICE);
    HashMap<String, UsbDevice> deviceList = usbManager.getDeviceList();
    
    // Get the USB device associated to your board.
    UsbDevice usbDevice = [...]
    
    // Create the XBee device object.
    XBeeDevice xbeeDevice = new XBeeDevice(context, 115200, usbDevice);
    

    Note that this constructor was added to the library recently, so it is not included in the latest release. You will need to checkout the code from master and compile the library in order to use it.

  2. Add the VID and PID of your board to the list mentioned above in the AndroidUSBInterface class. As in the other option, you will need to checkout the code and compile the library.

Hope this helps.

rubenmoral avatar Jan 23 '20 10:01 rubenmoral

I tried the first option. When I try to call the open function, it throws an exception could not determine operating mode

shubham9436 avatar Jan 23 '20 14:01 shubham9436

I tried the first option. When I try to call the open function, it throws an exception could not determine operating mode

Did you ever solve this error? I am seeing the same error on Android 14 https://github.com/digidotcom/xbee-android/issues/30

niccellular avatar Oct 15 '24 17:10 niccellular