mik3y / usb-serial-for-android

Android USB host serial driver library for CDC, FTDI, Arduino and other devices.
MIT License
4.86k stars 1.59k forks source link

Only reading zeros from CdcAcmSerialDriver #6

Closed mik3y closed 10 years ago

mik3y commented 11 years ago

From mafish...@gmail.com on December 18, 2012 09:07:23

What steps will reproduce the problem? 1. Connect /dev/ttyACM0 device

  1. cat /dev/tty/ACM0 and watch serial traffic
  2. Use the usb-serial-for-android API and read only 0's for bytes What is the expected output? What do you see instead? Data other than 0's. What version of the product are you using? On what operating system? ICS 4.1.x Please provide any additional information below. I can see traffic by cat'ing the /dev/ttvACM0 device and by using the app "android-serialport-api" to do the same. However, when using this library, all I am reading is 0's. When the CdcAcmSerialDriver reads, it always reads the correct amount of data (never less than 0), but the bytes returned in the buffer are 0.

Original issue: http://code.google.com/p/usb-serial-for-android/issues/detail?id=6

mik3y commented 11 years ago

From mike.wak...@gmail.com on December 19, 2012 21:35:51

Are you cat'ing the device concurrently while using this driver, or was that just an example done at a separate time?

Are you running the v0.1.0 JAR, or the latest sources in git?

mik3y commented 11 years ago

From mafish...@gmail.com on December 20, 2012 03:44:01

Not cat'ing the device concurrently. Yes, running v0.1.0 JAR.

Upon further investigation, it appears that nothing is being returned at all. The value returned from read(...) is 0.

mik3y commented 11 years ago

From mike.wak...@gmail.com on April 07, 2013 22:47:59

Sorry for the delay in returning to this. Still an issue?

The driver will return 0 when there is (a) no data to be read, or (b) a timeout reading data. Is it possible you are calling read() on a device which doesn't have the baud rate set correctly, or with a very short timeout?

mik3y commented 11 years ago

From ruZ...@gmail.com on May 13, 2013 11:05:38

I saw this while using source instead of prebuilt. 010 jar fixed it. (FTDI, Samsung S3(9300), CM 10.1).

commit 22c4c9b280da08207ea6abf7a17a51c465447e9a

marlonscalabrin commented 10 years ago

I'm trying to connect to a MSP430G2 Launchpad. Same problem. The read() method returns the buffer size. And vector buffer remains zero all positions.

iforce2d commented 10 years ago

I had the same problem and had my comment all typed up and ready to click submit, then I noticed I was using the wrong baudrate. Hope this helps!

mik3y commented 10 years ago

@iforce2d: :grin: thanks for following up. We should add this to the FAQ as it's a common ailment (even on desktops). Marking closed!

marlonscalabrin commented 10 years ago

The problem was the index of the Endpoint. I solved this with the following code in the open() method: /* @author Marlon Scalabrin ( invent.to) / for (int j = 0; j < mDevice.getInterfaceCount(); j++) { UsbInterface mInterface = mDevice.getInterface(j); for (int i = 0; i < mInterface.getEndpointCount(); i++) { if (mInterface.getEndpoint(i).getType() == UsbConstants.USB_ENDPOINT_XFER_BULK) { if (mInterface.getEndpoint(i).getDirection() == UsbConstants.USB_DIR_OUT) { mWriteEndpoint = mInterface.getEndpoint(i); } if (mInterface.getEndpoint(i).getDirection() == UsbConstants.USB_DIR_IN) mReadEndpoint = mInterface.getEndpoint(i); } } } }

Att, []s Marlon Henrique Scalabrin invent.to http://invent.to - Soluções em Sistemas Computacionais

2014-08-20 2:46 GMT-03:00 mike w notifications@github.com:

Closed #6 https://github.com/mik3y/usb-serial-for-android/issues/6.

— Reply to this email directly or view it on GitHub https://github.com/mik3y/usb-serial-for-android/issues/6#event-154838943 .

mindentropy commented 9 years ago

@marlonscalabrin

I am also having the same problem with a Tiva MCU. Could please provide the complete modified code you put in open(..) method?

marlonscalabrin commented 9 years ago

I only verify all "endpoints" looking for the correct type. And selecting the "in point" and the "out point". Do it in the open() method in CdcAcmSerialDriver.java. You need add your vendorID and productID in UsbId.java. And add its reference on CdcAcmSerialDriver.java#getSupportedDevices().

Att, []s Marlon Henrique Scalabrin invent.to http://invent.to - Soluções em Sistemas Computacionais

2015-08-18 8:16 GMT-03:00 mindentropy notifications@github.com:

@marlonscalabrin https://github.com/marlonscalabrin

I am also having the same problem with a Tiva MCU. Could please provide the complete modified code you put in open(..) method?

— Reply to this email directly or view it on GitHub https://github.com/mik3y/usb-serial-for-android/issues/6#issuecomment-132174694 .