WebUSB无法识别Windows设备。

huangapple go评论94阅读模式
英文:

WebUSB doesn't recognize Windows device

问题

我正在尝试通过WebUSB在我的Android手机和Windows PC之间建立通信。我的PC可以轻松看到我的手机,但我的手机不能。

我正在使用的代码,实际上是我调用的一个函数的一部分:

navigator.usb
    .requestDevice({ filters: [{vendorId: 8921}]})
    .then(device => {
        console.log('Found a device:', device);
        return device.open();
    })
    .catch(error => {
        console.error(`Error: ${error}`);
    })

我不知道为什么。但我在某处读到了一些关于WinUSB的问题,但我不清楚。

谢谢。

英文:

I'm trying to make communication between my Android phone and Windows PC via WebUSB. My PC can see my phone withput any troubles, but my phone can't.

Code I'm using, actually it's part of a function that I'm calling:

navigator.usb
    .requestDevice({ filters: [{vendorId: 8921}]})
    .then(device => {
        console.log('Found a device:', device);
        return device.open();
    })
    .catch(error => {
        console.error(`Error: ${error}`);
    })

I don't know why. But somewhere I've read about some problems with WinUSB, but I don't know.

Thanks.

答案1

得分: 1

USB有专用的主机和外围设备角色,因此您的PC作为主机将看到手机作为外围设备。 WebUSB仅支持在充当主机的设备上运行,因此除非您的PC可以切换模式(这是您的手机执行的操作,但大多数PC无法执行),否则您只会从您的PC看到您的手机,但反之则不会。

这意味着您无法使用WebUSB将PC上的网站连接到手机上的网站。

英文:

USB has dedicated host and peripheral roles, so your PC as the host will see the phone as the peripheral. WebUSB only supports running on the device acting as the host so unless your PC can switch modes (this is something your phone does, but most PCs can't) then you will only see your phone from your PC but not the other way around.

This means you can't use WebUSB to connect a website on your PC to a website on your phone.

huangapple
  • 本文由 发表于 2023年8月11日 01:03:03
  • 转载请务必保留本文链接:https://go.coder-hub.com/76877892.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定