我不想读取串口或其他可能的简易快捷方式。我想知道如何使用C#在我的笔记本电脑上读取USB端口。 无论您能否建议一个网站或解释流程,我都非常感激您的帮助。
我不想读取串口或其他可能的简易快捷方式。我想知道如何使用C#在我的笔记本电脑上读取USB端口。 无论您能否建议一个网站或解释流程,我都非常感激您的帮助。
public override async Task<byte[]> ReadAsync()
{
return await Task.Run(() =>
{
var bytes = new byte[ReadBufferSize];
//TODO: Allow for different interfaces and pipes...
var isSuccess = WinUsbApiCalls.WinUsb_ReadPipe(_DefaultUsbInterface.Handle, _DefaultUsbInterface.ReadPipe.WINUSB_PIPE_INFORMATION.PipeId, bytes, ReadBufferSize, out var bytesRead, IntPtr.Zero);
HandleError(isSuccess, "Couldn't read data");
Tracer?.Trace(false, bytes);
return bytes;
});
}
[DllImport("winusb.dll", SetLastError = true)]
public static extern bool WinUsb_ReadPipe(SafeFileHandle InterfaceHandle, byte PipeID, byte[] Buffer, uint BufferLength, out uint LengthTransferred, IntPtr Overlapped);
所有的代码和示例(包括其他平台)都可以在这里找到:https://github.com/MelbourneDeveloper/Device.Net