You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
can libaums support multiple devices connect simultaneously #71
Hi, I've tried it many times, I used a usb hub to connect to several devices at the same time. I can got all the dirs of all the devices.
As the picture shows, I use two listview, one use to show all the connected devices, the other one use to show the content of the specific deivce, when I clicked a specific device, I will refresh the content listview,
this worked fine, but when I clicked a specific folder in the content listview, I can't got the subdirectory of it and I got an error log as blow:
03-14 00:46:28.573 21986-21986/star.usbdevicescontroller W/System.err: java.io.IOException: Could not write to device, result == -1
03-14 00:46:28.573 21986-21986/star.usbdevicescontroller W/System.err: at com.github.mjdev.libaums.usb.JellyBeanMr2Communication.bulkOutTransfer(JellyBeanMr2Communication.java:42)
03-14 00:46:28.574 21986-21986/star.usbdevicescontroller W/System.err: at com.github.mjdev.libaums.driver.scsi.ScsiBlockDevice.transferCommand(ScsiBlockDevice.java:143)
03-14 00:46:28.574 21986-21986/star.usbdevicescontroller W/System.err: at com.github.mjdev.libaums.driver.scsi.ScsiBlockDevice.read(ScsiBlockDevice.java:209)
03-14 00:46:28.574 21986-21986/star.usbdevicescontroller W/System.err: at com.github.mjdev.libaums.partition.Partition.read(Partition.java:142)
03-14 00:46:28.574 21986-21986/star.usbdevicescontroller W/System.err: at com.github.mjdev.libaums.fs.fat32.FAT.getChain(FAT.java:134)
03-14 00:46:28.574 21986-21986/star.usbdevicescontroller W/System.err: at com.github.mjdev.libaums.fs.fat32.ClusterChain.(ClusterChain.java:64)
03-14 00:46:28.574 21986-21986/star.usbdevicescontroller W/System.err: at com.github.mjdev.libaums.fs.fat32.FatDirectory.init(FatDirectory.java:156)
03-14 00:46:28.574 21986-21986/star.usbdevicescontroller W/System.err: at com.github.mjdev.libaums.fs.fat32.FatDirectory.listFiles(FatDirectory.java:485)
03-14 00:46:28.574 21986-21986/star.usbdevicescontroller W/System.err: at star.usbdevicescontroller.usbmode.UsbFileListAdapter.refresh(UsbFileListAdapter.java:80)
03-14 00:46:28.574 21986-21986/star.usbdevicescontroller W/System.err: at star.usbdevicescontroller.usbmode.UsbFileListAdapter.(UsbFileListAdapter.java:60)
03-14 00:46:28.574 21986-21986/star.usbdevicescontroller W/System.err: at star.usbdevicescontroller.usbmode.UsbActivity$2.onItemClick(UsbActivity.java:255)
03-14 00:46:28.574 21986-21986/star.usbdevicescontroller W/System.err: at android.widget.AdapterView.performItemClick(AdapterView.java:310)
03-14 00:46:28.574 21986-21986/star.usbdevicescontroller W/System.err: at android.widget.AbsListView.performItemClick(AbsListView.java:1145)
03-14 00:46:28.574 21986-21986/star.usbdevicescontroller W/System.err: at android.widget.AbsListView$PerformClick.run(AbsListView.java:3066)
03-14 00:46:28.574 21986-21986/star.usbdevicescontroller W/System.err: at android.widget.AbsListView$3.run(AbsListView.java:3903)
03-14 00:46:28.574 21986-21986/star.usbdevicescontroller W/System.err: at android.os.Handler.handleCallback(Handler.java:739)
03-14 00:46:28.574 21986-21986/star.usbdevicescontroller W/System.err: at android.os.Handler.dispatchMessage(Handler.java:95)
03-14 00:46:28.574 21986-21986/star.usbdevicescontroller W/System.err: at android.os.Looper.loop(Looper.java:148)
03-14 00:46:28.574 21986-21986/star.usbdevicescontroller W/System.err: at android.app.ActivityThread.main(ActivityThread.java:5417)
03-14 00:46:28.574 21986-21986/star.usbdevicescontroller W/System.err: at java.lang.reflect.Method.invoke(Native Method)
03-14 00:46:28.574 21986-21986/star.usbdevicescontroller W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:742)
03-14 00:46:28.575 21986-21986/star.usbdevicescontroller W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:632)
03-14 00:46:34.560 21986-21986/star.usbdevicescontroller E/UsbMassStorageDevice: could not release interface!
03-14 00:46:34.560 21986-21986/star.usbdevicescontroller E/UsbMassStorageDevice: could not release interface!
(I have also tried to solve it, but I can't got it work. I need your help, thanks advance.
I come from China, so my English is not very well, hope you can understand me :) )
Hi, I found that when connect multiple devices, the JellyBeanMr2Communication Ojbect refrence to the wrong UsbDeviceConnection Object, but I can't find the specific position of the bug.
So I assume you are using a USB Hub, so maybe there is a shared device connection involved, because of that. I never tried that to be honest. But the error you have is unfortunately not very specific in what exactly failed.
What you maybe can do is change from the synchronous data transfer to the USB request mode like so (before you are initializing any devices): UsbCommunicationFactory.setUnderlyingUsbCommunication(UnderlyingUsbCommunication.USB_REQUEST_ASYNC);
Are you closing the devices when you change to another one? If not, try that maybe.
I am currently on a road trip so I cannot say when I will be able to test that myself.
I tried to modify the motheds of the UsbFile interface like this
UsbFile[] listFiles(UsbDeviceConnection deviceConnection) throws IOException;
and modity the relative implements, then it worked, but I don't think this is a good way.
To be honest, I don't really sure if I have a full understand of your idea, maybe I've wrong, so I need you guide. I've tried to make some debug in you project, and upload it as a temp project to github, soon I'll delete it. you can download it from https://github.com/StormLion/tproject
I'll add this one to the list of things I'll want to test on Qemu. This should also cover the case of devices with multiple USB ports without an external hub, for example on Android x86.
Activity
magnusja commentedon Mar 15, 2017
Hey there,
I have never really tried it, but it should work. Just try it and tell me if you have any problems.
StormLion commentedon Mar 16, 2017
Hi, I've tried it many times, I used a usb hub to connect to several devices at the same time. I can got all the dirs of all the devices.

As the picture shows, I use two listview, one use to show all the connected devices, the other one use to show the content of the specific deivce, when I clicked a specific device, I will refresh the content listview,
this worked fine, but when I clicked a specific folder in the content listview, I can't got the subdirectory of it and I got an error log as blow:
03-14 00:46:28.573 21986-21986/star.usbdevicescontroller W/System.err: java.io.IOException: Could not write to device, result == -1
03-14 00:46:28.573 21986-21986/star.usbdevicescontroller W/System.err: at com.github.mjdev.libaums.usb.JellyBeanMr2Communication.bulkOutTransfer(JellyBeanMr2Communication.java:42)
03-14 00:46:28.574 21986-21986/star.usbdevicescontroller W/System.err: at com.github.mjdev.libaums.driver.scsi.ScsiBlockDevice.transferCommand(ScsiBlockDevice.java:143)
03-14 00:46:28.574 21986-21986/star.usbdevicescontroller W/System.err: at com.github.mjdev.libaums.driver.scsi.ScsiBlockDevice.read(ScsiBlockDevice.java:209)
03-14 00:46:28.574 21986-21986/star.usbdevicescontroller W/System.err: at com.github.mjdev.libaums.partition.Partition.read(Partition.java:142)
03-14 00:46:28.574 21986-21986/star.usbdevicescontroller W/System.err: at com.github.mjdev.libaums.fs.fat32.FAT.getChain(FAT.java:134)
03-14 00:46:28.574 21986-21986/star.usbdevicescontroller W/System.err: at com.github.mjdev.libaums.fs.fat32.ClusterChain.(ClusterChain.java:64)
03-14 00:46:28.574 21986-21986/star.usbdevicescontroller W/System.err: at com.github.mjdev.libaums.fs.fat32.FatDirectory.init(FatDirectory.java:156)
03-14 00:46:28.574 21986-21986/star.usbdevicescontroller W/System.err: at com.github.mjdev.libaums.fs.fat32.FatDirectory.listFiles(FatDirectory.java:485)
03-14 00:46:28.574 21986-21986/star.usbdevicescontroller W/System.err: at star.usbdevicescontroller.usbmode.UsbFileListAdapter.refresh(UsbFileListAdapter.java:80)
03-14 00:46:28.574 21986-21986/star.usbdevicescontroller W/System.err: at star.usbdevicescontroller.usbmode.UsbFileListAdapter.(UsbFileListAdapter.java:60)
03-14 00:46:28.574 21986-21986/star.usbdevicescontroller W/System.err: at star.usbdevicescontroller.usbmode.UsbActivity$2.onItemClick(UsbActivity.java:255)
03-14 00:46:28.574 21986-21986/star.usbdevicescontroller W/System.err: at android.widget.AdapterView.performItemClick(AdapterView.java:310)
03-14 00:46:28.574 21986-21986/star.usbdevicescontroller W/System.err: at android.widget.AbsListView.performItemClick(AbsListView.java:1145)
03-14 00:46:28.574 21986-21986/star.usbdevicescontroller W/System.err: at android.widget.AbsListView$PerformClick.run(AbsListView.java:3066)
03-14 00:46:28.574 21986-21986/star.usbdevicescontroller W/System.err: at android.widget.AbsListView$3.run(AbsListView.java:3903)
03-14 00:46:28.574 21986-21986/star.usbdevicescontroller W/System.err: at android.os.Handler.handleCallback(Handler.java:739)
03-14 00:46:28.574 21986-21986/star.usbdevicescontroller W/System.err: at android.os.Handler.dispatchMessage(Handler.java:95)
03-14 00:46:28.574 21986-21986/star.usbdevicescontroller W/System.err: at android.os.Looper.loop(Looper.java:148)
03-14 00:46:28.574 21986-21986/star.usbdevicescontroller W/System.err: at android.app.ActivityThread.main(ActivityThread.java:5417)
03-14 00:46:28.574 21986-21986/star.usbdevicescontroller W/System.err: at java.lang.reflect.Method.invoke(Native Method)
03-14 00:46:28.574 21986-21986/star.usbdevicescontroller W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:742)
03-14 00:46:28.575 21986-21986/star.usbdevicescontroller W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:632)
03-14 00:46:34.560 21986-21986/star.usbdevicescontroller E/UsbMassStorageDevice: could not release interface!
03-14 00:46:34.560 21986-21986/star.usbdevicescontroller E/UsbMassStorageDevice: could not release interface!
(I have also tried to solve it, but I can't got it work. I need your help, thanks advance.
I come from China, so my English is not very well, hope you can understand me :) )
StormLion commentedon Mar 16, 2017
And here are some relative code snippets:
StormLion commentedon Mar 17, 2017
Hi, I found that when connect multiple devices, the JellyBeanMr2Communication Ojbect refrence to the wrong UsbDeviceConnection Object, but I can't find the specific position of the bug.
magnusja commentedon Mar 17, 2017
Hey there. Are you sure that is the case? This line creates the connection: https://github.com/magnusja/libaums/blob/develop/libaums/src/main/java/com/github/mjdev/libaums/UsbMassStorageDevice.java#L213
So I assume you are using a USB Hub, so maybe there is a shared device connection involved, because of that. I never tried that to be honest. But the error you have is unfortunately not very specific in what exactly failed.
What you maybe can do is change from the synchronous data transfer to the USB request mode like so (before you are initializing any devices):
UsbCommunicationFactory.setUnderlyingUsbCommunication(UnderlyingUsbCommunication.USB_REQUEST_ASYNC);Are you closing the devices when you change to another one? If not, try that maybe.
I am currently on a road trip so I cannot say when I will be able to test that myself.
StormLion commentedon Mar 20, 2017
I can't closing any devices, because I need to copy data from all the devices at the same time.
StormLion commentedon Mar 20, 2017
And I've tried UsbCommunicationFactory.setUnderlyingUsbCommunication(UnderlyingUsbCommunication.USB_REQUEST_ASYNC);
but it didn't work
StormLion commentedon Mar 20, 2017
I tried to modify the motheds of the UsbFile interface like this
UsbFile[] listFiles(UsbDeviceConnection deviceConnection) throws IOException;
and modity the relative implements, then it worked, but I don't think this is a good way.
magnusja commentedon Mar 20, 2017
I don't think I understand, can you show some code?
StormLion commentedon Mar 21, 2017
To be honest, I don't really sure if I have a full understand of your idea, maybe I've wrong, so I need you guide. I've tried to make some debug in you project, and upload it as a temp project to github, soon I'll delete it. you can download it from
https://github.com/StormLion/tproject
magnusja commentedon Mar 21, 2017
Thanks, I downloaded it and will have a look as soon as I am home.
blood-mist commentedon Mar 29, 2017
If you get multiple device supporting done, please post a little code snippet on how to achieve it. Thanks.
magnusja commentedon May 13, 2020
Fixed with #242
depau commentedon May 13, 2020
I'll add this one to the list of things I'll want to test on Qemu. This should also cover the case of devices with multiple USB ports without an external hub, for example on Android x86.