简体   繁体   English

使用.NET Console App通过芯片选择写入HID

[英]Write to HID with Chip Selection with .NET Console App

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. 嗨,我正在编写一个简单的控制台应用程序,需要将字节写入MCP2210 USB to SPI Master我在这里找到了这个库,似乎在连接设备和读取元数据方面做得很好。

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 编写时,我需要进行另一个终端中显示的芯片选择 在此处输入图片说明

Any help is greatly appreciated 任何帮助是极大的赞赏

Here is the MC I am using https://www.microchip.com/wwwproducts/en/MCP2210 这是我正在使用的MC https://www.microchip.com/wwwproducts/en/MCP2210

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. 但是没有参数是不可能的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM