我正在尝试使用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
,但不知道如何检查/修复此问题。
答案 0 :(得分:0)
O.K。想通了这个。
声明不正确:
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 Board没有Visual C ++示例的人所遇到的一些挫折问题。