这是我的隐藏库。它支持UWP和Android。 https://bitbucket.org/MelbourneDeveloper/hid.net/src/master/
这是Trezor硬件钱包使用的库的示例: https://github.com/MelbourneDeveloper/Trezor.Net
我可以在UWP上毫无问题地连接到Trezor,但是我不能连接到其他硬件钱包的KeepKey或Ledger。这是我用来连接到库中两个设备的代码。它浏览设备列表,尝试连接并返回连接OK的第一个设备:
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:2B240001'为 根据其数据类型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:2C970001'违反了 'any | vidpid:[0-9a-fA-F] {4} [0-9a-fA-F] {4}( (usb | bluetooth))?| model:[^;] {1,512};。{1,512}'。属性“ Id”具有 值'vidpid:2C970001'失败 解析。 LedgerWalletUWPSample C:\ GitRepos \ ledger-dotnet-api \ LedgerWalletUWPSample \ bin \ x86 \ Debug \ AppxManifest.xml