简介 上完大学课程后,我正在重新自学 C++。我最近购买了一个 Arcus Performax PMX-4EX-SA-TB9 步进电机控制器,它有一个我打算使用的 USB 连接。该公司提供使用其专有代码手动控制步进器的软件,并在其软件中提供一个终端,您可以在其中向控制器发送单行代码以控制步进器。您可以控制加速度和最高速度以及各种东西。玩起来很有趣,但现在我想更进一步。在线手册讨论了使用 C++ 为步进器编写自己的程序,我下载了我认为我需要的文件。我有一个 DLL 文件、一个 lib 文件和一个头文件。因此,我了解到 DLL 文件是在可执行文件运行时使用的动态链接库。我通读了 lib 文件和头文件,发现我认为头文件中的一些函数声明类似于一些电机命令。我将在下面插入头文件。
我的问题
我可以使用 DLL 文件以及 lib 和头文件来使用我在头文件中看到的函数来控制这个设备吗?我如何加载这一切?有人愿意使用下面包含的 fnPerformaxComDoMove 函数编写一个简短的小示例吗?这样我就可以从那里走了?我正在使用 Visual Studio C++ 2013,并且我已经完成了有关创建和使用我自己制作的 DLL 的在线教程,但与这个相比,这些都显得如此简单。
我的理解
我相信,由于我得到了一个 DLL、头文件和 lib 文件,我将使用 _declspec(dllexport) 定义而不是导入版本。所有的函数声明都以“BOOL”开头,然后是“PERFORMAXCOM_API”,然后是“_stdcall”,我只习惯于查看类型,然后是函数名,然后是括号中的参数。在所有不同的功能之前,“PERFORMAX_API”和“_stdcall”是什么意思?我知道 DWORD 是双字,是一个 32 位整数,但有些参数要求一个轴,比如 x、y 和 z……当他们本来可以要求一个字符时,为什么他们想要一个数字?非常感谢任何可以帮助我提供任何信息的人。我非常想学习如何使用它。
标题
#ifdef PERFORMAXCOM_EXPORTS
#define PERFORMAXCOM_API __declspec(dllexport)
#else
#define PERFORMAXCOM_API __declspec(dllimport)
#endif
extern PERFORMAXCOM_API int nPerformaxCom;
#ifdef __cplusplus
extern "C" {
#endif
PERFORMAXCOM_API int fnPerformaxCom(void);
//USB reset
BOOL PERFORMAXCOM_API _stdcall fnPerformaxComUSBReset(IN HANDLE pHandle);
BOOL PERFORMAXCOM_API _stdcall fnPerformaxComFlush(IN HANDLE pHandle);
BOOL PERFORMAXCOM_API _stdcall fnPerformaxComGetNumDevices(OUT LPDWORD lpNumDevices);
BOOL PERFORMAXCOM_API _stdcall fnPerformaxComGetProductString(IN DWORD dwNumDevices, OUT LPVOID lpDeviceString, IN DWORD dwOptions);
BOOL PERFORMAXCOM_API _stdcall fnPerformaxComOpen(IN DWORD dwDeviceNum, OUT HANDLE* pHandle);
BOOL PERFORMAXCOM_API _stdcall fnPerformaxComClose(IN HANDLE pHandle);
BOOL PERFORMAXCOM_API _stdcall fnPerformaxComSetTimeouts(IN DWORD dwReadTimeout, DWORD dwWriteTimeout);
BOOL PERFORMAXCOM_API _stdcall fnPerformaxComSendRecv(IN HANDLE pHandle, IN LPVOID wBuffer, IN DWORD dwNumBytesToWrite,IN DWORD dwNumBytesToRead,OUT LPVOID rBuffer);
signed int PERFORMAXCOM_API _stdcall fnPerformaxMove(IN HANDLE pHandle,
IN int commandCode,
IN int axes,
IN int moveDir,
IN long *value,
IN int modelCode);
signed int PERFORMAXCOM_API _stdcall fnPerformaxCommandReply(IN HANDLE pHandle,
IN char *command,
IN char *reply);
signed int PERFORMAXCOM_API _stdcall fnPerformaxIO(IN HANDLE pHandle,
IN int commandCode,
IN int bitNumber,
IN long *value,
IN int modelCode);
signed int PERFORMAXCOM_API _stdcall fnPerformaxMotorStat(IN HANDLE pHandle,
IN int commandCode,
IN int axes,
IN long *value,
IN int modelCode);
signed int PERFORMAXCOM_API _stdcall fnPerformaxSpeedAccel(IN HANDLE pHandle,
IN int commandCode,
IN int axes,
IN long *value,
IN int modelCode);
signed int PERFORMAXCOM_API _stdcall fnPerformaxGeneral(IN HANDLE pHandle,
IN int commandCode,
IN int axes,
IN long *value,
IN int modelCode);
long PERFORMAXCOM_API _stdcall fnPerformaxComGetAxisStatus(IN HANDLE pHandle,DWORD dwAxisNumber);
long PERFORMAXCOM_API _stdcall fnPerformaxComGetPulseSpeed(IN HANDLE pHandle,DWORD dwAxisNumber);
long PERFORMAXCOM_API _stdcall fnPerformaxComGetPulsePos(IN HANDLE pHandle,DWORD dwAxisNumber);
BOOL PERFORMAXCOM_API _stdcall fnPerformaxComSetPulsePos(IN HANDLE pHandle,DWORD dwAxisNumber, DWORD pos);
long PERFORMAXCOM_API _stdcall fnPerformaxComGetEncoderPos(IN HANDLE pHandle,DWORD dwAxisNumber);
BOOL PERFORMAXCOM_API _stdcall fnPerformaxComSetEncoderPos(IN HANDLE pHandle,DWORD dwAxisNumber, DWORD pos);
BOOL PERFORMAXCOM_API _stdcall fnPerformaxComSetPolarity(IN HANDLE pHandle,DWORD dwAxisNumber,DWORD dwPolarity);
long PERFORMAXCOM_API _stdcall fnPerformaxComGetPolarity(IN HANDLE pHandle,DWORD dwAxisNumber);
long PERFORMAXCOM_API _stdcall fnPerformaxComGetDIOSetup(IN HANDLE pHandle);
BOOL PERFORMAXCOM_API _stdcall fnPerformaxComSetDIOSetup(IN HANDLE pHandle, DWORD dio_setup);
long PERFORMAXCOM_API _stdcall fnPerformaxComGetDIO(IN HANDLE pHandle);
BOOL PERFORMAXCOM_API _stdcall fnPerformaxComGetDIOBit(IN HANDLE pHandle,DWORD bitn);
BOOL PERFORMAXCOM_API _stdcall fnPerformaxComSetDIO(IN HANDLE pHandle,DWORD dio_value );
BOOL PERFORMAXCOM_API _stdcall fnPerformaxComSetDIOBit(IN HANDLE pHandle,DWORD bitn,DWORD bitv );
BOOL PERFORMAXCOM_API _stdcall fnPerformaxComDoHome(IN HANDLE pHandle,
DWORD axis,
DWORD dir,
DWORD low_speed,
DWORD high_speed,
DWORD accel_time,
DWORD decel_time,
DWORD search_mode,
DWORD ramp_mode);
BOOL PERFORMAXCOM_API _stdcall fnPerformaxComDoMove(IN HANDLE pHandle,
DWORD axisn,
DWORD target,
DWORD low_speed,
DWORD high_speed,
DWORD accel_time,
DWORD decel_time);
BOOL PERFORMAXCOM_API _stdcall fnPerformaxComStop(IN HANDLE pHandle,
DWORD axisn,
DWORD ramp_stop);
#ifdef __cplusplus
}
#endif