Write to HID with Chip Selection with .NET Console App
Asked Answered
R

1

2

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

Regression answered 18/1, 2019 at 8:56 Comment(0)
B
0

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.

Bowlder answered 18/1, 2019 at 12:15 Comment(1)
that's not the issue. My question is how do I select chip for GPIOsRegression

© 2022 - 2024 — McMap. All rights reserved.