K8097 dll with C++

For a school project, my group and i are thinking of buying K8097 (velleman.eu/products/view/?id=386156) to control 3 stepper motors. A reason for our choice was the inclusion of a dll file. But, as the head programmer, i wonder if the dll works with C++. I have downloaded the file, and it tells me that it needs Visual .NET. So, if any of you have any experience with it, can you tell me if the dll works with C++ code and with Visual C++ compiler?

Thanks

During install you will be asked what components you want to install. There is the native DLL file ‘mtrapi32.dll’ that you can use in C/C++. And then there is the .NET assembly file ‘MotorLibNET.dll’ that is a wrapper around the native DLL.

These are the declarations in borland pascal:
procedure SMCDisconnect; stdcall;
function SMCConnect(Port: PChar; Motors: DWORD): BOOL; stdcall;
function SMCGetMotorCount: DWORD; stdcall;
function SMCGetInputCount: DWORD; stdcall;
function SMCGetOutputCount: DWORD; stdcall;
function SMCConnected: BOOL; stdcall;
procedure SMCSetDemo(Enabled: BOOL); stdcall;
procedure SMCMove(Motor, Steps: DWORD; Direction: DWORD; Speed: DWORD); stdcall;
procedure SMCStop(Motor: DWORD); stdcall;
function SMCGetMoving(Motor: DWORD): BOOL; stdcall;
function SMCGetDirection(Motor: DWORD): DWORD; stdcall;
procedure SMCSetTorque(Motor: DWORD; Enabled: BOOL); stdcall;
function SMCGetTorque(Motor: DWORD): BOOL; stdcall;
function SMCGetInput(Input: DWORD): BOOL; stdcall;
procedure SMCSetOutput(Active: BOOL); stdcall;
function SMCGetOutput: BOOL; stdcall;

They should be easy to understand and convert to C. If you need a lib file, you can generate one from the DLL using the tools available in Visual Studio.

Hallo Support,

I bought a PCB K8097 (4) and i tryed to connect with the AutoLibNET.dll - my GetProcAddress() fail always.

Is it possible to show me a short working example to work with this DLL?

THX & best regards

Stanford

Hi all,

this works with RAD Studio XE5:

HMODULE hDLL_SMC;

void WINAPI (*SMC_Disconnect)(void);
int WINAPI (*SMC_Connect)(char *cPort, unsigned long ulMotorCnt);
void WINAPI (*SMC_Move)(unsigned long ulMotorIdx, unsigned long ulSteps, unsigned long ulDirection, unsigned long Speed);
... and so on ...

__fastcall TDlgMotorControl::TDlgMotorControl(TComponent* Owner):TForm(Owner)
{
	// load DLL
	AnsiString DLLPath= ExtractFilePath(Application->ExeName) + "mtrapi32.dll";
	hDLL_SMC= LoadLibrary(DLLPath.c_str());

	if(hDLL_SMC == NULL)
	{
		throw Exception("Can't find mtrapi32.dll file");
	}

	// init function pointers 
	*(FARPROC*)&SMC_Disconnect=     GetProcAddress(hDLL_SMC, "SMCDisconnect");
	*(FARPROC*)&SMC_Connect=        GetProcAddress(hDLL_SMC, "SMCConnect");
// and so on

	SMC_Connect("COM7", 4);  // COM7 in my case
	SMC_Move(0, 300, 1, 50);
	SMC_SetTorque(0, 1);
	SMC_SetTorque(0, 0);


}

Thank you for this example

Hi all,

How can I send two Move commands for them to be executed one after another? I have tried to separate them like this:

Move(0, 300, 1, 30);

while (GetMoving(0)){}

Move (0, 500, 0, 50);

but that doesn’t work. Even when I wait a certain time with a Sleep() funkction to check the motor status the GetMoving() function returns 0 despite the motor running.

The same thing goes with the GetTorque() function - it always returns 0.

On the contrary, the function GetInputCount() returns the proper value of 6.