cordovarduino: Crash when attempting to open a connection
When I try to open a serial connection with serial.open({baudRate:57600}, sCallback, eCallback)
, the entire app crashes. This is the error it prints to the ADB log:
08-03 06:01:27.594 28970 29027 D Serial : Action: openSerial
08-03 06:01:27.601 28970 29000 E AndroidRuntime: FATAL EXCEPTION: pool-1-thread-1
08-03 06:01:27.601 28970 29000 E AndroidRuntime: Process: io.cordova.hellocordova, PID: 28970
08-03 06:01:27.601 28970 29000 E AndroidRuntime: java.lang.NullPointerException: Attempt to invoke interface method 'android.hardware.usb.UsbDevice com.hoho.android.usbserial.driver.UsbSerialDriver.getDevice()' on a null object reference
08-03 06:01:27.601 28970 29000 E AndroidRuntime: at fr.drangies.cordova.serial.Serial$3.run(Serial.java:226)
08-03 06:01:27.601 28970 29000 E AndroidRuntime: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
08-03 06:01:27.601 28970 29000 E AndroidRuntime: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
08-03 06:01:27.601 28970 29000 E AndroidRuntime: at java.lang.Thread.run(Thread.java:818)
08-03 06:01:27.607 858 3262 W ActivityManager: Force finishing activity io.cordova.hellocordova/.MainActivity
Any ideas?
About this issue
- Original URL
- State: open
- Created 8 years ago
- Comments: 29 (8 by maintainers)
@FilipMatys, Yes buddy, I got that by now. I have also done a test build for the app. Now making the changes for not considering read endpoint. Hopefully, I will get it right.
Keeping my finger crossed. 🤞
So I made it work. To avoid the same frustration I have been through, here is how I did it:
I had to download this library: https://github.com/mik3y/usb-serial-for-android
It is the one this plugin is dependent on. Unfortunately, the library in this plugin is quite old and expects the device to have multiple interfaces. New version of the library does not.
I used this fork, which uses raw files, not library: https://github.com/r1000ru/cordovarduino
I removed obsolete files from config.xml (like example files) and copied the new library into that fork. Watch for proper paths!
Still, it was not enough 😃 But it might be for you.
I went through the driver code and found out it required both read and write endpoints. And that was the reason, why connection with my printer could not be opened. I modified the driver to not require 3 endpoints and to not throw exception when there is no read endpoint.
And thank the Almighty whoever that is, it works now.