Hi all,
When using a USB accessory, I'm experiencing problems on certain Android platforms.
AsyncStream gets stuck after various time of running properly, calling errors. Dis- and reconnecting USBserial won't let me reestablish the connection to the peripheral, only if I manually dis-/reconnect the USB plug of the accessory, a new connection is possible.
After many hours of trying different ways and searching for solutions, it seems to be a known problem with the USB stack: https://code.google.com/p/android/issues/detail?id=20545
Then I've found the USB Host Controller app on playstore which let me reset the USB port without manually dis-/reconnecting the plug - I assume this app uses "USBDEVFS_RESET" to achieve it.
The thread on code.google.com regarding the issue also has a code sample showing a way to call the JNI function for "USBDEVFS_RESET" in c. Could someone help my to port this function to B4A?
Many thanks!
When using a USB accessory, I'm experiencing problems on certain Android platforms.
AsyncStream gets stuck after various time of running properly, calling errors. Dis- and reconnecting USBserial won't let me reestablish the connection to the peripheral, only if I manually dis-/reconnect the USB plug of the accessory, a new connection is possible.
After many hours of trying different ways and searching for solutions, it seems to be a known problem with the USB stack: https://code.google.com/p/android/issues/detail?id=20545
Then I've found the USB Host Controller app on playstore which let me reset the USB port without manually dis-/reconnecting the plug - I assume this app uses "USBDEVFS_RESET" to achieve it.
The thread on code.google.com regarding the issue also has a code sample showing a way to call the JNI function for "USBDEVFS_RESET" in c. Could someone help my to port this function to B4A?
B4X:
// Note: the underlying usb device name may change on enumeration.
// Harcoded for testing only.
#define ACCUSBDEVICE "/dev/bus/usb/001/001" // Rather than gadget name "/dev/usb_accessory"
// This requires root privileges for write permissions to device.
JNIEXPORT jint JNICALL
Java_com_genericminds_usbio_UsbAccessoryIO_nativeReset(JNIEnv* env, jclass cls) {
int result,fd;
result = system("su -c \"chmod -R 777 " ACCUSBDEVICE "\"");
if (result != 0) {
return result;
}
fd = open(ACCUSBDEVICE, O_RDWR);
if (fd < 0) {
return fd;
}
result = ioctl(fd, USBDEVFS_RESET, 0);
close(fd);
if (result < 0) {
return result;
}
return 0;
}
Many thanks!