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

Reading from Barcode reader with CdcAcmSerialDriver returns zeros #602

Open
vladaman opened this issue Oct 22, 2024 · 1 comment
Open

Reading from Barcode reader with CdcAcmSerialDriver returns zeros #602

vladaman opened this issue Oct 22, 2024 · 1 comment

Comments

@vladaman
Copy link

vladaman commented Oct 22, 2024

I am trying to read data from Barcode, which is set to CDC Mode. Tested on Linux with cat /dev/ttyACM0 which it gives me proper output. Android code:

ProbeTable customTable = new ProbeTable();
customTable.addProduct(0x0525, 0xa4a7, CdcAcmSerialDriver.class);
customTable.addProduct(0x1eab, 0x1D06, CdcAcmSerialDriver.class); 
UsbSerialProber prober = new UsbSerialProber(customTable);
List<UsbSerialDriver> availableDrivers = prober.findAllDrivers(manager);

UsbSerialDriver driver = availableDrivers.get(0);
UsbDeviceConnection connection = manager.openDevice(driver.getDevice());
UsbSerialPort usbSerialPort = driver.getPorts().get(0);
usbSerialPort.open(connection);
usbSerialPort.setParameters(9600, 8, UsbSerialPort.STOPBITS_1, UsbSerialPort.PARITY_NONE); // whatever speed I set I get zeros bellow

byte[] response = new byte[6];
while (!Thread.interrupted() && active) {
  int len = usbSerialPort.read(response, READ_WAIT_MILLIS);
  // response byte content is 0x000000000000
}
 Available driver device=UsbDevice[mName=/dev/bus/usb/001/007,mVendorId=7851,mProductId=7430,mClass=2,mSubclass=0,mProtocol=0,mManufacturerName=Newland Auto-ID,mProductName=NLS-FM430MD-SR-U USB CDC,mVersion=0.01,mSerialNumberReader=android.hardware.usb.IUsbSerialReader$Stub$Proxy@43902ce, mHasAudioPlayback=false, mHasAudioCapture=false, mHasMidi=false, mHasVideoCapture=false, mHasVideoPlayback=false, mConfigurations=[
    UsbConfiguration[mId=1,mName=USB CDC mode,mAttributes=128,mMaxPower=250,mInterfaces=[
    UsbInterface[mId=0,mAlternateSetting=0,mName=CDC ACM Comm,mClass=2,mSubclass=2,mProtocol=1,mEndpoints=[
UsbEndpoint[mAddress=131,mAttributes=3,mMaxPacketSize=16,mInterval=8]]
      UsbInterface[mId=1,mAlternateSetting=0,mName=CDC ACM Data,mClass=10,mSubclass=0,mProtocol=0,mEndpoints=[
UsbEndpoint[mAddress=129,mAttributes=2,mMaxPacketSize=64,mInterval=0]
UsbEndpoint[mAddress=2,mAttributes=2,mMaxPacketSize=64,mInterval=0]]]] ports=[<CdcAcmSerialPort device_name=/dev/bus/usb/001/007 device_id=1007 port_number=0>]

It always reads zeros, regardless of setRTS/setDTR/setParameters values.

@kai-morich
Copy link
Collaborator

please try with a larger read buffer as explained here

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

No branches or pull requests

2 participants