错误_无效_句柄
我正在尝试使用 mpusbapi.h 中定义的以下函数
HANDLE(*MPUSBOpen)(DWORD instance, //Input
PCHAR pVID_PID, //Input identifier
PCHAR pEP, //Input pipe
DWORD dwDir, //Input
DWORD dwReserved); //Input <Future Use>
DWORD(*MPUSBWrite)(HANDLE handle, //Input
PVOID pData, //Input
DWORD dwLen, //Input
PDWORD pLength, //Output
DWORD dwMilliseconds); //Input
当我在 test.cpp 中使用这些函数时,它看起来像;
HANDLE LACOutpipe;
pipeName="\\MCHP_EP";
PCHAR VidPid="vid_04d8&pid_fc5f";
BYTE bufData[3];
DWORD buflen=sizeof(bufData);
DWORD bufProcessed;
LACOutpipe=MPUSBOpen(0, //only one device connected, dont need to check for multiple
VidPid, //this is the device driver vid and pid
pipeName, //the pipe to write to?
MP_WRITE, //MP_WRITE is just 1
0); //not supported yet?
cout<<LACOutpipe<<endl;
//now use LACOutpipe handle to write
cout<<MPUSBWRITE(LACOutpipe, //the handle to write to
bufData, //BYTE array with data to be sent
bufLen, //length of bufData
&bufProcessed, //bytes processed
10000) //10 second timeout
<<endl;
cout<<GetLastError()<<endl;
控制台输出为:
FFFFFFFF
0
6
Press any key to continue...
MPUSBWrite 返回 0 表示写入功能失败。错误代码 6 对应于 ERROR_INVALID_HANDLE:句柄无效。
有人知道为什么吗?我有预感它是 pipeName
但不知道如何检查/修复它。
I am trying to use the following functions defined in mpusbapi.h
HANDLE(*MPUSBOpen)(DWORD instance, //Input
PCHAR pVID_PID, //Input identifier
PCHAR pEP, //Input pipe
DWORD dwDir, //Input
DWORD dwReserved); //Input <Future Use>
DWORD(*MPUSBWrite)(HANDLE handle, //Input
PVOID pData, //Input
DWORD dwLen, //Input
PDWORD pLength, //Output
DWORD dwMilliseconds); //Input
When I use these in my test.cpp, it looks like;
HANDLE LACOutpipe;
pipeName="\\MCHP_EP";
PCHAR VidPid="vid_04d8&pid_fc5f";
BYTE bufData[3];
DWORD buflen=sizeof(bufData);
DWORD bufProcessed;
LACOutpipe=MPUSBOpen(0, //only one device connected, dont need to check for multiple
VidPid, //this is the device driver vid and pid
pipeName, //the pipe to write to?
MP_WRITE, //MP_WRITE is just 1
0); //not supported yet?
cout<<LACOutpipe<<endl;
//now use LACOutpipe handle to write
cout<<MPUSBWRITE(LACOutpipe, //the handle to write to
bufData, //BYTE array with data to be sent
bufLen, //length of bufData
&bufProcessed, //bytes processed
10000) //10 second timeout
<<endl;
cout<<GetLastError()<<endl;
The console output is:
FFFFFFFF
0
6
Press any key to continue...
MPUSBWrite returning 0 means that the write function failed. Error code 6 corresponds to ERROR_INVALID_HANDLE: The handle is invalid.
Anyone know why? I have a hunch it is the pipeName
but not sure how to check/fix this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,明白了。
错误声明:
正确声明
请注意,对于 Firgelli LAC 板,只有端点 1 可用于 IN 和 OUT 管道。
我希望这能解决那些像我一样花费大量时间尝试解决 Firgelli LAC 板的精益文档但没有 Visual C++ 示例的人所遇到的一些挫折问题。
O.K. figured this out.
Incorrect declaration:
Correct declaration
Note that for the Firgelli LAC Board, there is only endpoint 1 available for IN and OUT pipes.
I hope this solves some of the frustration problems that arise for anyone out there that has spent as much time as me trying to work around their lean documentation and no Visual C++ examples for the Firgelli LAC Board.