Windows 上基于 Android 配件的软件

发布于 2024-12-29 12:59:20 字数 911 浏览 5 评论 0原文

我想使用我的应用程序将我的计算机变成 Android 配件。因此,这将不是专门的硬件,而只是将手机切换到配件模式的 PC,从而在手机上启动一些与主机硬件关联的 Java 应用程序并创建通信通道。

我找到了一个 示例代码(以及一些 Java Android 应用程序),可以使用 libusb 在 Linux 上执行此操作。它的工作原理是使用标准 VID 和 PID“打开”手机。然后它发送打开配件模式的命令,以及模型等元数据、版本等。

如果手机支持附件模式,它将断开连接并使用不同的 PID 重新枚举。然后示例代码检查是否已打开并打开新设备。

不过,我正在尝试让它在 Windows 上运行。我发现了一些 USB 库,例如 LibUsbDotNet,但它们似乎都需要使用 WinUSB/ 的设备libusb 驱动程序。我使用 LibUsbDotNet 中的一个工具为我的手机生成 libusb 驱动程序,并将其安装在旧的通用可移动驱动器上。但这意味着我现在无法在需要时将手机作为可移动驱动器访问,因此这不是解决方案。

有没有一种方法(最好是一个库)可以根据 VID 和 PID 打开任何连接的 USB 设备,然后向其发送一些原始命令?

之后设备将使用不同的 PID 重新枚举,我可以用它来创建我自己的 WinUSB 驱动程序,所以这不是问题。我只需要通过/围绕默认驱动程序注入一些命令即可打开附件模式。

(我更喜欢 .NET 解决方案,但任何 Windows 都可以,我可以编写自己的互操作包装器)

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)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

兲鉂ぱ嘚淚 2025-01-05 12:59:20

我也在寻找类似的解决方案。我尝试了Linux版本,带有libusb,有一点小问题,能够与设备通信。
在 Windows 上寻找解决方案时,我尝试了很多技巧。
如果需要在 ADK 模式下与设备通信,我需要发送几个供应商命令,现在我需要在大容量存储模式下连接时执行此操作。使用大容量存储驱动程序这是不可能的。我尝试获取连接的 USB 设备的节点句柄,看看是否可以发送供应商命令,但在那里我只能提交“获取描述符”请求。所以我采用了丑陋的方法,用 libusb-win32 替换了大容量存储驱动程序,看看它是否可以做同样的事情,是的,它有效,但根本不是一个好的解决方案。

仍在寻找..

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..

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文