1

这是我的隐藏库。它支持 UWP 和 Android。 https://bitbucket.org/MelbourneDeveloper/hid.net/src/master/

这是与 Trezor 硬件钱包一起使用的库的示例: https ://github.com/MelbourneDeveloper/Trezor.Net

我可以在 UWP 上毫无问题地连接到 Trezor,但我无法连接到其他硬件钱包的 KeepKey 或 Ledger。这是我用来连接库中两个设备的代码。它查看设备列表,尝试连接并返回第一个连接正常的设备:

public async Task InitializeAsync()
{
    Logger.Log("Initializing Hid device", null, nameof(UWPHidDevice));

    foreach (var deviceInformation in _WindowsDeviceInformationList)
    {
        var hidDeviceOperation = HidDevice.FromIdAsync(deviceInformation.Id, Windows.Storage.FileAccessMode.ReadWrite);
        var task = hidDeviceOperation.AsTask();
        _HidDevice = await task;
        if (_HidDevice != null)
        {
            break;
        }
    }

    if (_HidDevice == null)
    {
        throw new Exception($"Could not obtain a connection to the device.");
    }

    _HidDevice.InputReportReceived += _HidDevice_InputReportReceived;

    if (_HidDevice == null)
    {
        throw new Exception("Could not connect to the device");
    }

    Connected?.Invoke(this, new EventArgs());
}

Trezor 连接返回正常,但 Ledger 只是循环通过现有的有效驱动程序而不返回任何内容。我强烈怀疑这是权限问题。为了在 UWP 中连接到 USB 设备,我需要指定设备功能:

这是 Trezor 的部分:

  <Capabilities>
    <Capability Name="internetClient" />
    <uap:Capability Name="removableStorage" />
    <DeviceCapability Name="humaninterfacedevice">
      <Device Id="vidpid:534C 0001">
        <Function Type="usage:0005 *" />
        <Function Type="usage:FF00 0001" />
        <Function Type="usage:ff00 *" />
      </Device>
    </DeviceCapability>
  </Capabilities>

除了供应商之外,我对 KeepKey 有完全相同的东西:

<DeviceCapability Name="humaninterfacedevice">
  <Device Id="vidpid:‭‭2B24‬‬ 0001">
    <Function Type="usage:0005 *" />
    <Function Type="usage:FF00 0001" />
    <Function Type="usage:ff00 *" />
  </Device>
</DeviceCapability>

和分类帐:

  <Capabilities>
    <Capability Name="internetClient" />
    <uap:Capability Name="removableStorage" />   
    <DeviceCapability Name="humaninterfacedevice">
      <Device Id="vidpid:‭2C97‬ 0001">
        <Function Type="usage:0005 *" />
        <Function Type="usage:FF00 0001" />
        <Function Type="usage:ff00 *" />
      </Device>
    </DeviceCapability>
  </Capabilities>

但是,Visual Studio 抱怨这个错误:

ID 属性无效 - 根据其数据类型,值 'vidpid:2B24 0001' 无效http://schemas.microsoft.com/appx/manifest/types:ST_DeviceId

但是,这是供应商 ID 的十六进制值。我无法更改它,因为它需要匹配 2B24 和 2C97 或 11044 和 11415 作为整数的供应商 ID。

我将此架构追踪到此处: https ://github.com/tpn/winsdk-10/blob/master/Include/10.0.16299.0/winrt/AppxManifestTypes.xsd

这似乎是规则:

 <xs:simpleType name="ST_DeviceId">
    <xs:restriction base="ST_NonEmptyString">
      <xs:pattern value="any"/>
      <xs:pattern value="vidpid:[0-9a-fA-F]{4} [0-9a-fA-F]{4}( (usb|bluetooth))?"/>
      <xs:pattern value="model:[^;]{1,512};.{1,512}"/>
    </xs:restriction>
</xs:simpleType>

我实际上现在收到了这个有用的错误:

严重性代码描述项目文件行抑制状态错误验证错误。错误 C00CE169:应用程序清单验证错误:应用程序清单必须根据架构有效:第 36 行,第 15 列,原因:“vidpid:2C97 0001”违反了“任何|vidpid:[0-9a-fA-”的模式约束F]{4} [0-9a-fA-F]{4}( (usb|蓝牙))?|型号:[^;]{1,512};.{1,512}'。无法解析值为“vidpid:2C97 0001”的属性“Id”。LedgerWalletUWPSample C:\GitRepos\ledger-dotnet-api\LedgerWalletUWPSample\bin\x86\Debug\AppxManifest.xml

4

0 回答 0