BulkTransfer 中的 System.AccessViolationException(LibUsbDotNet.DeviceHandle, Byte, Byte*, Int32, Int32 ByRef, UInt32)

问题描述

我在调用 UsbEndpointReader Read 方法时遇到此异常。第一次通话时不会发生这种情况。它发生在 10 到 20 个电话之后。

System.AccessViolationException: '试图读取或写入受保护的内存。这通常表明其他内存已损坏。'

堆栈跟踪:

at LibUsbDotNet.NativeMethods.BulkTransfer(DeviceHandle devHandle,Byte endpoint,Byte* data,Int32 length,Int32& actualLength,UInt32 timeout)
at LibUsbDotNet.LibUsb.UsbEndpointBase.Transfer(IntPtr buffer,Int32 offset,Int32 timeout,Int32& transferLength)
at LibUsbDotNet.LibUsb.UsbEndpointBase.Transfer(Object buffer,Int32& transferLength)
at LibUsbDotNet.LibUsb.UsbEndpointReader.Read(Byte[] buffer,Int32 count,Int32& transferLength)

我的代码

 Error ec = 0;
                byte[] readBuffer = new byte[1000];
                while (!_stop)
                {
                    ec = _reader.Read(readBuffer,10000,out var bytesRead);
                    if (ec != 0)
                         break;

                    if (bytesRead <= 0)
                        continue;

                     /* use readBuffer  here */
                }

知道我做错了什么吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)