错误_无效_句柄

发布于 2025-01-08 21:35:12 字数 1762 浏览 0 评论 0原文

我正在尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浅语花开 2025-01-15 21:35:12

好的,明白了。

错误声明:

PCHAR VidPid= "vid_04d8&pid_fc5f";
DWORD pipeName="\\MCHP_EP1";

正确声明

char VidPid[]="vid_04d8&pid_fc5f";
char pipename[]="\\MCHP_EP1";

请注意,对于 Firgelli LAC 板,只有端点 1 可用于 IN 和 OUT 管道。

我希望这能解决那些像我一样花费大量时间尝试解决 Firgelli LAC 板的精益文档但没有 Visual C++ 示例的人所遇到的一些挫折问题。

O.K. figured this out.

Incorrect declaration:

PCHAR VidPid= "vid_04d8&pid_fc5f";
DWORD pipeName="\\MCHP_EP1";

Correct declaration

char VidPid[]="vid_04d8&pid_fc5f";
char pipename[]="\\MCHP_EP1";

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文