Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/271.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# UsbBulkInPipe不';t返回实际值_C#_Usb_Windows 8.1 - Fatal编程技术网

C# UsbBulkInPipe不';t返回实际值

C# UsbBulkInPipe不';t返回实际值,c#,usb,windows-8.1,C#,Usb,Windows 8.1,我正在使用UsbBulkInPipe从USB设备获取数据。当我读取数据时,长度是正确的,但值都是零。如何读取真实数据 这就是我尝试过的: UInt32 bytesRead = 0; UsbBulkInPipe bulkIn = device.DefaultInterface.BulkInPipes[0]; var stream = bulkIn.InputStream; DataReader reader = new DataReader(stream); try { bytesRe

我正在使用
UsbBulkInPipe
从USB设备获取数据。当我读取数据时,长度是正确的,但值都是零。如何读取真实数据

这就是我尝试过的:

UInt32 bytesRead = 0;
UsbBulkInPipe bulkIn = device.DefaultInterface.BulkInPipes[0];

var stream = bulkIn.InputStream;
DataReader reader = new DataReader(stream);

try
{
    bytesRead = await reader.LoadAsync(bulkIn.EndpointDescriptor.MaxPacketSize);
}
catch (Exception exception)
{
    //ShowStatus(exception.Message.ToString());
}
finally
{
    byte[] value = new byte[bytesRead];
    reader.ReadBytes(value);
}

目前我正在使用这种方法:

var t = reader.LoadAsync(buf.MaxPacketSize).AsTask(cancellationTokenSourceBulkIn.Token);    
uint len = t.Result;

byte[] data = reader.ReadBuffer(len).ToArray(); 

呃,我记得有这个问题。是时候翻阅我的WinUSB代码了。你的代码看起来就像是设计用来忽略所有错误的。是否抛出任何异常?最后一个街区应该做什么?此外,您没有显示实际打印字节值的代码部分,这部分可能存在错误。做一个SSCCE怎么样?