Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Xbee Device Not Found #14

Open
shubham9436 opened this issue Jan 23, 2020 · 4 comments
Open

Xbee Device Not Found #14

shubham9436 opened this issue Jan 23, 2020 · 4 comments

Comments

@shubham9436
Copy link

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();
            }
        });
    }
}
@rubenmoral
Copy link
Member

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.

@shubham9436
Copy link
Author

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.

@rubenmoral
Copy link
Member

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.

@shubham9436
Copy link
Author

shubham9436 commented Jan 23, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants