Write to HID with Chip Selection with .NET Console App

243 views Asked by At

Hi I am writing a simple console app that needs to write bytes to MCP2210 USB to SPI Master I found this library over here, seems to do good job with connecting the device and reading the metadata.

I am writing message to the board as below

 public static byte[] Talk()
        {
            var device = DeviceList.Local.GetHidDevices(1240, 222).FirstOrDefault();
            if (device == null)
            {
                Console.WriteLine($"Could not find a device with Vendor Id:1240, Product Id:222 ");
                return null;
            }
var reportDescriptor = device.GetReportDescriptor();
            foreach (var deviceItem in reportDescriptor.DeviceItems)
            {
Console.WriteLine("Opening device for 20 seconds...");
                if (!device.TryOpen(out var hidStream))
                {
                        Console.WriteLine("Failed to open device.");
                        continue;
                }

                    Console.WriteLine("Opened device.");
                    hidStream.ReadTimeout = Timeout.Infinite;
                    hidStream.Write(new byte[3] {60, 00, 00});
           }  

Not sure If I am writing it correctly. While writing I need to do a chip selection as displayed in this other terminal enter image description here

Any help is greatly appreciated

Here is the MC I am using https://www.microchip.com/wwwproducts/en/MCP2210

1

There are 1 answers

1
Robetto On

I do not see a closing of your stream. This may cause your data to not even being sent (at least not in time).

Consider using blocks with streams. But with out parameters not possible.