0

I am making an Android app in Odroid Xu4, connected to it is the Xbee Pro s2 via usb serial converter with cp210x driver using ttyUBS0 port but inside the app it disconnects from ttyUBS0 and uses bus /dev/bus/usb/.. No I have to open the serial port to access Rx/Tx for xbee. I am right now using usb-serial-for-android https://github.com/mik3y/usb-serial-for-android/tree/master/usbSerialExamples

But its not helping much, my app crash as soon as open the xbee device. Here is my code

 List<UsbSerialDriver> availableDrivers = UsbSerialProber.getDefaultProber().findAllDrivers(manager);
    if (availableDrivers.isEmpty()) {
        return;
    }

    UsbSerialDriver driver = availableDrivers.get(0);
    Toast.makeText(this, "connection done" + driver, Toast.LENGTH_LONG).show();
    List<UsbSerialPort> availableports = driver.getPorts();
    for (UsbSerialPort port : availableports) {
        Toast.makeText(this, "port please :" + port.getPortNumber(), Toast.LENGTH_LONG).show();
        UsbDeviceConnection connection = manager.openDevice(driver.getDevice());
        try {
            port.open(connection);
            Toast.makeText(this," yes i m connected to port", Toast.LENGTH_LONG).show();
            port.setParameters(BAUDRATE, 8, 1, 0);
            Toast.makeText(this," baudrate set", Toast.LENGTH_LONG).show();
            PORT = driver.getDevice().toString();
            if (PORT == null) {
                Toast.makeText(this, "not connected",Toast.LENGTH_LONG).show();
            }
            else
            {
                XBeeDevice mydevice = new XBeeDevice(PORT, BAUDRATE);
                Toast.makeText(this, "connected",Toast.LENGTH_LONG).show();
                try {
                    mydevice.open(); //App crashes now :(
                    Toast.makeText(this, "connected woow",Toast.LENGTH_LONG).show();
                } catch (XBeeException e) {
                    e.printStackTrace();
                }
            }


        } catch (IOException e) {
            e.printStackTrace();
        }

    }

Can someone guide. Am I doing something wrong in the code? Here is another library i found http://antipastohw.pbworks.com/w/page/41729078/How-to%20use%20a%20serial%20port%20with%20Android,%20Liquidware%20Ambrosia%20edition Can it be helpful?

shruti
  • 459
  • 6
  • 24

1 Answers1

-1

https://code.google.com/p/android-serialport-api/ This api works as required, it will find all the required ports. You would require to add the .java files in your project.

shruti
  • 459
  • 6
  • 24