Software based Android accessory on Windows
Asked Answered
H

1

10

I would like to turn my computer into an Android accessory using my application. So instead of a specialized hardware this will be just PC that will switch the phone into accessory mode, thus launching some Java app on the phone associated with the host hardware and create a communication channel.

I've found a sample code (plus some Java Android app) to do this on Linux using libusb. It works by "opening" the phone using the standard VID and PID. Then it sends a command to turn on the accessory mode, along with the metadata like model, version etc.

If the phone supports accessory mode it'll then disconnect and reenumerate with a different PID. The sample code then checks if it did and opens the new device.

However, I'm trying to get this running on Windows. I've found a few USB libraries, like LibUsbDotNet, but they all seem to require the device using a WinUSB/libusb driver. I've used a tool in LibUsbDotNet to generate a libusb driver for my phone, installing it over the old generic removable drive one. But this means I now can't access the phone as a removable drive when I want to, so this is not a solution.

Is there a way (preferably a library) that can open any connected USB device based on VID and PID, and then send a few raw commands to it?

After that the device will reenumerate with a different PID, which I can use to create my own WinUSB driver, so that is not an issue. I just need to inject some commands through/around the default driver to turn the accessory mode on.

(I would prefer .NET solution, but anything Windows is fine and I can write my own interop wrapper)

Hiawatha answered 26/1, 2012 at 16:43 Comment(5)
what about wifi ? cant you use that for communication ?Latialatices
Unfortunately, no, not in this case. Also, even if I could, USB would be much better - charges the phone, triggers launching a backend app on the phone, and car recognize various computers based on the serial number provided, triggering a different reaction in each case.Hiawatha
the question is if its worth the effort you could also use bluetooth. Theoretically you could use adb it can start a application you need and works over usb . the pull and push commands could be used to transfer dataLatialatices
I appreciate your help but what I posted above is exactly what I want and need. I would like to do it the easy way with BT, WiFi or adb, but I can't. I really need to put the device into usb accessory mode, by forcing some data through the usb to make it reenumerate. Ignore the Android parts of the question, this is really about doing USB stuff on Windows with non-WinUSB drivers.Hiawatha
Hi @Hiawatha did you get any workable solution for usb communication between android phone and windoes PCHuh
D
1

I am also searching for a similar solution. I tried the Linux version, with libusb, with little hickups, was able to communicate with the device. While searching for the solutions on windows I tried many hacks. If need to communicate with device in ADK mode, I need to send several Vendor Commands, now this I need to do while its connected in Mass Storage mode. This is impossible using Mass Storage driver. I tried to get the Node handle of connected USB device to see if could send vendor command, but there I could only file Get Descriptor requests. So I went ugly method, replaced mass storage driver with libusb-win32, to see it could do the same, YES, it worked, but not at all a good solution.

Still searching..

Digitigrade answered 2/6, 2013 at 16:23 Comment(1)
Hi sachin did you get any solution for USB communication.Huh

© 2022 - 2024 — McMap. All rights reserved.