Question

I am working on the USB serial. I want to make a Nexus to read data from USB.

I found the example project to do it. here

So, I cloned the project and complied with eclipse. Everything works well. I can install and run my app. The app can find my USB when it is plugged to Nexus by using intent.

However, I cannot read and write data. The code is following :

protected void onResume() {
    super.onResume();
    mSerialDevice = UsbSerialProber.acquire(mUsbManager);
    Log.d(TAG, "Resumed, mSerialDevice=" + mSerialDevice);

    if (mSerialDevice == null) {
        mTitleTextView.setText(String.valueOf(mSerialDevice));
    } 
    else{
        ...
        ...
    }
    ....
}

I read all the code. I found that the "mSerialDevice" is always null. Actually, the else loop is put an instruction to read data. I tried to debug but I cannot find any reasons why it is null. I need you help.. :(

Thank in advance !

Was it helpful?

Solution

Now, I found the way to solve it. Actually, I really don't know why it is null but I changed the way to do that by using the following code :

HashMap<String, UsbDevice> deviceList = mUsbManager.getDeviceList();
Iterator<UsbDevice> deviceIterator = deviceList.values().iterator();
UsbDevice device = null;
while (deviceIterator.hasNext()) {
    ...
}

I can read vendor-id, product-id, and etc. However, I still don't know how to read folders in which my USB. If anyone knows that I need you help.

Thank you.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top