Device.Net
Device.Net copied to clipboard
.net 5 to .net 6
Describe the issue modify .csproj file old file
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Device.Net" Version="4.2.1" />
<PackageReference Include="Hid.Net" Version="4.2.1" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.0" />
</ItemGroup>
modified
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Device.Net" Version="4.2.1" />
<PackageReference Include="Hid.Net" Version="4.2.1" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.0" />
</ItemGroup>
Screenshots

Your Code
internal class Program
{
static void Main(string[] args)
{
run();
Console.ReadLine();
}
static async Task run()
{
try
{
var loggerFactory = LoggerFactory.Create((builder) =>
{
_ = builder.SetMinimumLevel(LogLevel.Trace);
});
//----------------------
// This is Windows specific code. You can replace this with your platform of choice or put this part in the composition root of your app
//Register the factory for creating Hid devices.
var hidFactory =
new FilterDeviceDefinition(vendorId: 0x8888, productId: 0x00D1, label: "Trezor One Firmware 1.6.x", usagePage: 65280)
.CreateWindowsHidDeviceFactory(loggerFactory);
//Register the factory for creating Usb devices.
var usbFactory =
new FilterDeviceDefinition(vendorId: 0x1209, productId: 0x53C1, label: "Trezor One Firmware 1.7.x").
CreateWindowsHidDeviceFactory(loggerFactory);
//----------------------
//Join the factories together so that it picks up either the Hid or USB device
var factories = hidFactory.Aggregate(usbFactory);
//Get connected device definitions
var deviceDefinitions = (await factories.GetConnectedDeviceDefinitionsAsync().ConfigureAwait(false)).ToList();
if (deviceDefinitions.Count == 0)
{
//No devices were found
return;
}
//Get the device from its definition
var trezorDevice = await hidFactory.GetDeviceAsync(deviceDefinitions.First()).ConfigureAwait(false);
//Initialize the device
await trezorDevice.InitializeAsync().ConfigureAwait(false);
//Create the request buffer
var buffer = new byte[65];
buffer[0] = 0x00;
buffer[1] = 0x3f;
buffer[2] = 0x23;
buffer[3] = 0x23;
//Write and read the data to the device
var readBuffer = await trezorDevice.WriteAndReadAsync(buffer).ConfigureAwait(false);
}
catch (Exception ex)
{
Debug.WriteLine(ex.ToString());
}
}
}
Info
- Platform: windows 10
- dotnet sdk : 6.0.1
- Device Type: USB-HID
- Version: 4.2.1
@qmtdlt dis you mean to do a pull request?