-
-
Notifications
You must be signed in to change notification settings - Fork 122
Quick Start
Christian Findlay edited this page Feb 10, 2019
·
17 revisions
The easiest way to get going to clone a repo that uses Usb.Net or Hid.Net and modify the code to suit your needs. Please clone this repo, or one of the repos in Samples & Unit Tests.
If you have trouble getting a sample to compile, please see Build Issues
If you want to start fresh, the easiest way would be to create a .NET Core project on Windows with Visual Studio and add the NuGet packages you require. Please see the NuGet page.
Please see
Device Listener or Enumerating Connected Devices
Writing To and Reading From a Device
This is UWP code. The only difference for Windows is that you would call WindowsHidDeviceFactory.Register().
private static async Task InitializeTrezor()
{
//Register the factory for creating Usb devices. This only needs to be done once.
UWPUsbDeviceFactory.Register();
//Register the factory for creating Usb devices. This only needs to be done once.
UWPHidDeviceFactory.Register();
//Define the types of devices to search for. This particular device can be connected to via USB, or Hid
var deviceDefinitions = new List<FilterDeviceDefinition>
{
new FilterDeviceDefinition{ DeviceType= DeviceType.Hid, VendorId= 0x534C, ProductId=0x0001, Label="Trezor One Firmware 1.6.x" },
new FilterDeviceDefinition{ DeviceType= DeviceType.Usb, VendorId= 0x1209, ProductId=0x53C1, Label="Trezor One Firmware 1.7.x" },
new FilterDeviceDefinition{ DeviceType= DeviceType.Usb, VendorId= 0x1209, ProductId=0x53C0, Label="Model T" }
};
//Get the first available device and connect to it
var devices = await DeviceManager.Current.GetDevices(deviceDefinitions);
var trezorDevice = devices.FirstOrDefault();
await trezorDevice.InitializeAsync();
//Create a buffer with 3 bytes (initialize)
var buffer = new byte[64];
buffer[0] = 0x3f;
buffer[1] = 0x23;
buffer[2] = 0x23;
//Write the data to the device
await trezorDevice.WriteAsync(buffer);
//Read the response
var readBuffer = await trezorDevice.ReadAsync();
}