Device.Net, Does anyone have some experience using Device.Net?

ty bender

New member
Joined
Feb 28, 2021
Messages
2
Programming Experience
Beginner
I have grabbed a sample code that they publish with the documentation, but I am confused at why I am getting errors in Visual Studio. I highlighted the lines i'm getting errors at. Please note I have not changed anything in the sample.

Code:
Sample Code:
private static async Task checkHID()
        {
            var loggerFactory = LoggerFactory.Create((builder) =>
            {
                _ = builder.AddDebug().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: 0x534C, productId: 0x0001, 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")
                .CreateWindowsUsbDeviceFactory(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);
        }





Here are the errors,
errors.PNG
 
CreateWindowsHidDeviceFactory is also an extension method and it can be found here:


Have you referenced the appropriate assembly, either directly or via NuGet, and imported the appropriate namespace?

Likewise, the CreateWindowsUsbDeviceFactory method can be found here:

 
With regards to the error on this line:
C#:
if (deviceDefinitions.Count == 0)
the only explanation that comes to mind is that you have not imported System.Collections.Generic and that Count is being interpreted as the IEnumerable<T>.Count extension method rather than the List<T>.Count property. If that is the case then you can either import the namespace or add parentheses to call the method.
 
Back
Top Bottom