基本上,我正在尝试使用提供的DLL(mpusbapi.dll)和头文件(mpusbapi.h)来控制USB设备(线性执行器控制板)。但是,我不能为我的生活找出我需要传递给MPUSBWrite()
的参数。
特别是MPUSBWrite()
的第2,第3和第4参数。第一个参数显然是MPUSBOpen()
返回的句柄,最后一个参数是以ms为单位的超时。
我预感它与LAC advance config的第6页有关。
非常感谢任何帮助。谢谢!
mpusbapi.h文件
#ifndef _MPUSBAPI_H_
#define _MPUSBAPI_H_
#define MPUSB_FAIL 0
#define MPUSB_SUCCESS 1
#define MP_WRITE 0
#define MP_READ 1
// MAX_NUM_MPUSB_DEV is an abstract limitation.
// It is very unlikely that a computer system will have more
// then 127 USB devices attached to it. (single or multiple USB hosts)
#define MAX_NUM_MPUSB_DEV 127
DWORD (*MPUSBGetDLLVersion)(void);
DWORD (*MPUSBGetDeviceCount)(PCHAR pVID_PID);
HANDLE (*MPUSBOpen)(DWORD instance, // Input
PCHAR pVID_PID, // Input
PCHAR pEP, // Input
DWORD dwDir, // Input
DWORD dwReserved); // Input <Future Use>
DWORD (*MPUSBRead)(HANDLE handle, // Input
PVOID pData, // Output
DWORD dwLen, // Input
PDWORD pLength, // Output
DWORD dwMilliseconds); // Input
DWORD (*MPUSBWrite)(HANDLE handle, // Input
PVOID pData, // Input
DWORD dwLen, // Input
PDWORD pLength, // Output
DWORD dwMilliseconds); // Input
DWORD (*MPUSBReadInt)(HANDLE handle, // Input
PVOID pData, // Output
DWORD dwLen, // Input
PDWORD pLength, // Output
DWORD dwMilliseconds); // Input
BOOL (*MPUSBClose)(HANDLE handle);
#endif
LACTesting.cpp文件
#include <windows.h> // This is a windows header file. The functions I mentioned above are declared here
#include "mpusbapi.h" // This is the header file supplied. It declares the function prototypes that are defined in the DLL
#include <iostream>
#include "ioctls.h"
using namespace std;
int main(int argc, char* argv)
{
// Try to load the library
HMODULE mpbusDLL = NULL;
mpbusDLL = LoadLibrary(L"mpusbapi.dll");
if (mpbusDLL != NULL) {
// If the library could be loaded, then load the functions using GetProcAddress()
// Load the function 'MPUSBOpen' from the DLL
MPUSBOpen = (HANDLE(*)(DWORD, PCHAR, PCHAR, DWORD, DWORD)) GetProcAddress(mpbusDLL, "_MPUSBOpen");
MPUSBOpen=(HANDLE(*)(DWORD,PCHAR,PCHAR,DWORD,DWORD))GetProcAddress(mpbusDLL,"_MPUSBOpen");
MPUSBGetDLLVersion=(DWORD(*)(void))GetProcAddress(mpbusDLL,"_MPUSBGetDLLVersion");
MPUSBGetDeviceCount=(DWORD(*)(PCHAR))GetProcAddress(mpbusDLL,"_MPUSBGetDeviceCount");
MPUSBWrite=(DWORD(*)(HANDLE,PVOID,DWORD,PDWORD,DWORD))GetProcAddress(mpbusDLL,"_MPUSBWrite");
MPUSBRead=(DWORD(*)(HANDLE,PVOID,DWORD,PDWORD,DWORD))GetProcAddress(mpbusDLL,"_MPUSBRead");
MPUSBReadInt=(DWORD(*)(HANDLE,PVOID,DWORD,PDWORD,DWORD))GetProcAddress(mpbusDLL,"_MPUSBReadInt");
MPUSBClose=(BOOL(*)(HANDLE))GetProcAddress(mpbusDLL,"_MPUSBClose");
}
//If the DLL didn't load, let me know!
else cout<<"DLL didn't load"<<endl;
//Declarations
HANDLE LACHandle;
PCHAR pipeName=MCHPUSB_PIPE_NAME;// intializes pipeName to "\\MCHP_EP"
PCHAR VidPid="vid_04d8&pid_fc5f";
LACHandle=MPUSBOpen(0,VidPid,pipeName,1,0);//open device connection
//Not sure if I pass in the correct arguements for MBUSBOpen. VidPid and pipeName are correct.
cout<<"Device ID "<<VidPid<<"is open with "<<MPUSBGetDeviceCount(VidPid)<<" device(s)."<<endl;
//sMPUSBWrite(LACHandle,,3,,1000); <- this is where I am having issues.
//I can't figure out how to use MPUSBWrite
MPUSBClose(LACHandle);// closes device connection
}
答案 0 :(得分:1)
我认为你应该看看
然后处理Windows系统编程示例,然后您将清楚地理解逻辑。
对于你的问题,我看到了我猜的代码
// yourData which want to write
PVOID pData
// sizeof(yourData) google "sizeof"
DWORD dwLen
/* I have no idea about this, but its output you can see it
after running function */
PDWORD pLength
希望这有帮助