使用.NET控制台应用程序通过芯片选择写入HID [英] Write to HID with Chip Selection with .NET Console App
问题描述
我正在编写一个简单的控制台应用程序,该应用程序需要将字节写入MCP2210 USB to SPI Master
我在此处上找到了该库,似乎在连接设备和读取元数据方面做得很好
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
非常感谢您的帮助
这是我正在使用的MC, https://www.microchip.com/wwwproducts/zh/MCP2210
Here is the MC I am using 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.
这篇关于使用.NET控制台应用程序通过芯片选择写入HID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!