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

Strange issue when calling readBytes() byte per byte #323

Open
afalkenhahn opened this issue Dec 24, 2020 · 0 comments
Open

Strange issue when calling readBytes() byte per byte #323

afalkenhahn opened this issue Dec 24, 2020 · 0 comments

Comments

@afalkenhahn
Copy link

I'm having a strange issue when using readBytes() to read just a single byte. When I send 7 bytes from a PC to an Android device, and try to read them using something like this, it works fine:

byte[] data = new byte[7];
int k = 0;
while(k != 7) {
    int len = readBytes(data, 0);    
    if(len > 0) k += len;
}

But when I send 7 bytes from a PC to an Android device and I use a buffer that is only a single byte, it doesn't work. This is the code:

byte[] data = new byte[1];
int k = 0;
while(k != 7) {
    int len = readBytes(data, 0);    
    if(len > 0) k += len;
}

The code above will loop forever because k will never be more than 0.

I've debugged it and found out that bulkTransfer always returns -1 so I suspect it does so because the buffer is too small (just 1 byte) for bulkTransfer to copy all data it has. Could this be the reason?

If it is, shouldn't UsbSerial be fixed to work around this so that readBytes can be used with arbitrary buffer sizes? E.g. readBytes could call syncRead in buffers of 8kb or so internally so that bulkTransfer will never fail because of a buffer being too small...

Any ideas/thoughts on this?

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

1 participant