Closed jparedesj closed 10 years ago
Hello, I will check this further but, in the meantime, you could extract of the onClick event near all of that. Ideally your onClick button should be like this:
public void onClick(View arg0) { us.write(b.getBytes()); } });
I have an example in production which is very similar and the only thing which I am not doing everytime a button is pressed is UsbManager lclMan=(UsbManager) getSystemService(Context.USB_SERVICE);
Please, tell me if this is working for you.
This looks like some internal android stuff http://stackoverflow.com/questions/15446413/usbconnection-bulktransfer-returns-1-what-does-it-mean
It looks like a good thing to avoid open and close devices very often.
Thanks for your answer.
I will try to modify my logic today to keep the connection always open until the activity stops.
I'll let you know.
It works perfectly after the change of logic.
Thanks for the tip. I think it's an Android issue...
Regards!
I close the issue. I added further information about UsbSerial here http://felhr85.net/2014/11/11/usbserial-a-serial-port-driver-library-for-android-v2-0/
Regards!
Hello,
I don't know if this is an issue of the UsbSeria libraryl or my implementation is bad.
Anyway this UsbSerial it's great!
I had the following code in a click event. It works fine one or two times, then I get "device is closed in native_control_request".
It fails in this piece of code with the following error because "position" it's still "-1" after "wait()".
11-03 20:58:29.836: E/AndroidRuntime(7937): FATAL EXCEPTION: Thread-445 11-03 20:58:29.836: E/AndroidRuntime(7937): java.lang.IllegalArgumentException 11-03 20:58:29.836: E/AndroidRuntime(7937): at java.util.Arrays.copyOfRange(Arrays.java:2691) 11-03 20:58:29.836: E/AndroidRuntime(7937): at com.felhr.usbserial.SerialBuffer$SynchronizedBuffer.get(SerialBuffer.java:152) 11-03 20:58:29.836: E/AndroidRuntime(7937): at com.felhr.usbserial.SerialBuffer.getWriteBuffer(SerialBuffer.java:83) 11-03 20:58:29.836: E/AndroidRuntime(7937): at com.felhr.usbserial.UsbSerialDevice$WriteThread.run(UsbSerialDevice.java:218)
public synchronized byte[] get() { if(position == -1) { try { wait(); } catch (InterruptedException e) { e.printStackTrace(); } }
Here is what I have in my onclick event....
It is a 4.2.2 Android (Rikomagic MK802IV)