Hi all,
I am trying to write some code in order to execute two Move commands one after another on a k8097 card in C++ using the mtrapi32.dll. To do so I check GetMoving() of the appropriate motor in an empty while loop. The problem is that no matter how I try to check the motor status via GetMoving function, it always returns 0. I have read a similar topic about this issue and thus tried to declare the return value of the GetMoving as bool, int, unsigned int, unsigned long, but it always fails to return 1. On the other hand, I have no problem checking the connection status
#include <iostream>
#include <windows.h>
#include <string>
#include <stdlib.h>
using namespace std;
HINSTANCE MyDll;
int main() {
//string DLLPath= "mtrapi32.dll";
MyDll= LoadLibrary("mtrapi32.dll");
bool WINAPI (*Connect) (char *cPort, unsigned long ulMotorCnt);
void WINAPI (*Disconnect)(void);
int WINAPI (*GetMoving)(unsigned long ulMotorIndx);
bool WINAPI (*Connected) ();
void WINAPI (*Move)(unsigned long ulMotorIdx, unsigned long ulSteps, unsigned long ulDirection, unsigned long Speed);
*(FARPROC*)&Connect = GetProcAddress(MyDll, "SMCConnect");
*(FARPROC*)&GetMoving =GetProcAddress(MyDll, "SMCGetMoving");
*(FARPROC*)&Connected = GetProcAddress(MyDll, "SMCConnected");
*(FARPROC*)&Move = GetProcAddress(MyDll, "SMCMove");
*(FARPROC*)&Disconnect = GetProcAddress(MyDll, "SMCDisconnect");
Connect("COM3", 4);
if (Connected())
{
Move(0, 2000, 1, 30);
// the following GetMoving returns 0 even if I postpone the calling with Sleep(100)
while (GetMoving(0)){}
Move(0, 1000, 0, 30);
}
Disconnect();
FreeLibrary(MyDll);
return 0;
}
The code above makes the motor execute only the Move(0, 1000, 0, 30) command.