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());
}
}
}
Describe the issue modify .csproj file old file
modified
Screenshots
Your Code
Info