The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum for Programming
 Forum for Origin C
 Problem with dll provided by device manufacturer
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

sakuracz

4 Posts

Posted - 01/29/2012 :  2:45:54 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Ver. 7.5 SR0
Operating System: Win XP

Hi there!

I wanted to incorporate an interface to my Origin that would let me control a device I'm using in my spectroscopy setup, namely this motorized translation stage http://www.vm-tim.de/eng/8mt173.htm via this controler http://www.vm-tim.de/eng/8smc1.htm.

So I started by creating an resource-only dll for the dialog but that's not really important - that works fine. The problems start when I try to invoke the device specific functions provided by the manufacturer in his dll. Let me give you an example of a program that should work but does not:

#include <Origin.h>
#include "USMCDLL.h" //.h list of functions found in the dll and type definitions

int mainLAL()
{
out_str("lal");
USMC_Devices dev;
out_str("lel");
USMC_Init(&dev); //something's wrong here

out_str("lol");

return 0;
}

Execution stops during USMC_Init(&dev). The problem I'm seeing here is the strange invocation of USMC_Init(). In the sample program provided by the manufacturer, they do something like this

USMC_Devices dev;
USMC_Init(dev);

However, doing this in origin results in a "Error, function call and declaration mismatch" compilation error.
I have no idea what to do next. Would greatly appreciate your help.

Thanks,
Mike

PS. The include file looks like this:

//	USMCDLL.h	- header file with declorations of USMCDLL.dll functions and used structures
//	-SD
//  Note::C++
//  Use functions with reference arguments as in sample
//  Note.C
//	Use functions with address of operator in invoke expression: func(var1, &struct);
//	(For Rev. 24) Will work correctly with firmware version 24.03 or better

//#pragma once

//#include <windows.h>

// Please use the USMCDLL.lib to easely import functions from dll with "dllimport" (In Microsoft Visual Studio)
#ifdef USMCDLL_EXPORTS
#define USMCDLL_API __declspec(dllexport)
#else
#define USMCDLL_API __declspec(dllimport)
#endif

// Structure representing connected devices
typedef struct USMC_Devices_st{
	DWORD NOD;			// Number of the devices ready to work

	char **Serial;		// Array of 16 byte ASCII strings
	char **Version;		// Array of 4 byte ASCII strings
} USMC_Devices;			// Structure representing connected devices

// Structure representing some of divice parameters
typedef struct USMC_Parameters_st{
    float AccelT;		// Acceleration time (in ms)
    float DecelT;		// Deceleration time (in ms)
    float PTimeout;		// Time (in ms) after which current will be reduced to 60% of normal
    float BTimeout1;	// Time (in ms) after which speed of step motor rotation will be equal to the one specified at
						// BTO1P field (see below). (This parameter is used when controlling step motor using buttons)
    float BTimeout2;	//
    float BTimeout3;	//
    float BTimeout4;	//
    float BTimeoutR;	// Time (in ms) after which reset command will be performed
    float BTimeoutD;	// This field is reserved for future use
    float MinP;			// Speed (steps/sec) while performing reset operation. (This parameter is used when controlling
						// step motor using buttons)
    float BTO1P;		// Speed (steps/sec) after BTIMEOUT 1 time have passed. (This parameter is used when controlling
						// step motor using buttons)
    float BTO2P;		//
    float BTO3P;		//
    float BTO4P;		//
    WORD MaxLoft;		// Value in full steps that will be used performing backlash operation
    DWORD StartPos;		// Current Position Saved to FLASH (see Test MicroSMC.cpp)
	WORD RTDelta;		// Revolution distance  number of full steps per one full revolution
    WORD RTMinError;	// Number of full steps missed to raise the error flag
	float MaxTemp;		// Maximum allowed temperature (Celsius)
	BYTE SynOUTP;		// Duration of the output synchronization pulse
	float LoftPeriod;	// Speed of the last phase of the backlash operation.
	float EncMult;		// Should be <Encoder Steps per Evolution> / <SM Steps per Evolution> and should be integer multiplied by 0.25

	BYTE Reserved[16];	// <Unused> File padding

} USMC_Parameters;

// Structure representing start function parameters
typedef struct USMC_StartParameters_st{
	BYTE SDivisor;		// Step is divided by this factor (1,2,4,8)
	BOOL DefDir;		// Direction for backlash operation (relative)
    BOOL LoftEn;		// Enable automatic backlash operation (works if slow start/stop mode is off)
	BOOL SlStart;		// If TRUE slow start/stop mode enabled.
	BOOL WSyncIN;		// If TRUE controller will wait for input synchronization signal to start
	BOOL SyncOUTR;		// If TRUE output synchronization counter will be reset
	BOOL ForceLoft;		// If TRUE and destination position is equal to the current position backlash operation will be performed.
	BYTE Reserved[4];	// <Unused> File padding
} USMC_StartParameters;

// Structure representing some of divice parameters
typedef struct USMC_Mode_st{
    BOOL PMode;			// Turn off buttons (TRUE - buttons disabled)
    BOOL PReg;			// Current reduction regime (TRUE - regime is on)
    BOOL ResetD;		// Turn power off and make a whole step (TRUE - apply)
    BOOL EMReset;		// Quick power off
    BOOL Tr1T;			// Trailer 1 TRUE state (TRUE : +3/+5; FALSE : 0)
    BOOL Tr2T;			// Trailer 2 TRUE state (TRUE : +3/+5; FALSE : 0)
    BOOL RotTrT;		// Rotary Transducer TRUE state (TRUE : +3/+5; FALSE : 0)
    BOOL TrSwap;		// If TRUE, Trailers are treated to be swapped
    BOOL Tr1En;			// If TRUE Trailer 1 Operation Enabled
    BOOL Tr2En;			// If TRUE Trailer 2 Operation Enabled
    BOOL RotTeEn;		// If TRUE Rotary Transducer Operation Enabled
    BOOL RotTrOp;		// Rotary Transducer Operation Select (stop on error for TRUE)
    BOOL Butt1T;		// Button 1 TRUE state (TRUE : +3/+5; FALSE : 0)
    BOOL Butt2T;		// Button 2 TRUE state (TRUE : +3/+5; FALSE : 0)
    BOOL ResetRT;		// Reset Rotary Transducer Check Positions (need one full revolution before it can detect error)
    BOOL SyncOUTEn;		// If TRUE output syncronization enabled
    BOOL SyncOUTR;		// If TRUE output synchronization counter will be reset
    BOOL SyncINOp;		// Synchronization input mode:
						// True - Step motor will move one time to the destination position
						// False - Step motor will move multiple times by steps equal to the value destination position
	DWORD SyncCount;	// Number of steps after which synchronization output sygnal occures
	BOOL SyncInvert;	// Set to TRUE to invert output synchronization signal

	BOOL EncoderEn;		// Enable Encoder on pins {SYNCIN,ROTTR} - disables Synchronization input and Rotary Transducer
	BOOL EncoderInv;	// Invert Encoder Counter Direction
	BOOL ResBEnc;		// Reset <Encoder Position> and <SM Position in Encoder units> to 0
	BOOL ResEnc;		// Reset <SM Position in Encoder units> to <Encoder Position>

	BYTE Reserved;	// <Unused> File padding

} USMC_Mode;

// Structure representing divice state
typedef struct USMC_State_st{
	int CurPos;			// Current position (in microsteps)
	float Temp;			// Current temperature of the driver
	BYTE SDivisor;		// Step is divided by this factor
	BOOL Loft;			// Indicates backlash status
	BOOL FullPower;		// If TRUE then full power.
	BOOL CW_CCW;		// Current direction. Relatively!
	BOOL Power;			// If TRUE then Step Motor is ON.
	BOOL FullSpeed;		// If TRUE then full speed. Valid in "Slow Start" mode only.
	BOOL AReset;		// TRUE After Device reset, FALSE after "Set Position".
	BOOL RUN;			// Indicates if step motor is rotating
	BOOL SyncIN;		// Logical state directly from input synchronization PIN
	BOOL SyncOUT;		// Logical state directly from output synchronization PIN
	BOOL RotTr;			// Indicates current rotary transducer press state
	BOOL RotTrErr;		// Indicates rotary transducer error flag
	BOOL EmReset;		// Indicates state of emergency disable button (local control)
	BOOL Trailer1;		// Indicates trailer 1 logical state.
	BOOL Trailer2;		// Indicates trailer 2 logical state.
	float Voltage;		// Input power source voltage (6-39V) -=24 version 0nly=-

	BYTE Reserved;	// <Unused> File padding
} USMC_State;

// New For Firmware Version 2.4.1.0 (0x2410)
typedef struct USMC_EncoderState_st{
	int EncoderPos;		// Current position measured by encoder
	int ECurPos;		// Current position (in Encoder Steps) - Synchronized with request call

	BYTE Reserved;	// <Unused> File padding
} USMC_EncoderState;

// ~New For Firmware Version 2.4.1.0 (0x2410)

typedef struct USMC_Info_st{
	char serial[17];
	DWORD dwVersion;    
    char DevName[32];
	int CurPos, DestPos;
	float Speed;
	BOOL ErrState;

	BYTE Reserved[16];	// <Unused> File padding
} USMC_Info;

#pragma dll(C:\WINDOWS\system32\USMCDLL.dll)
#ifdef __cplusplus	// C++
extern "C" {
// 
//	 The USMC_Init function initializes driver and returns devices information
//
USMCDLL_API DWORD USMC_Init( USMC_Devices &Str);		// OUT - Array of structures describing all divices (may be NULL) MUST NOT be deleted

//
//	The USMC_GetState function returns structure representing current state of device
//
USMCDLL_API DWORD USMC_GetState( DWORD Device,				// IN - Device number
								 USMC_State &Str			// OUT - Structure representing divice state
								 );
//
//	The USMC_SaveParametersToFlash function saves current parameters of controller in static memory
//	so thay can be loaded at start up time
//
USMCDLL_API DWORD USMC_SaveParametersToFlash( DWORD Device	// IN - Device number
											 );
//
//	The USMC_SetCurrentPosition function sets current position of controller
//
USMCDLL_API DWORD USMC_SetCurrentPosition( DWORD Device,	// IN - Device number
										   int Position		// IN - New position
										   );
//
//	The USMC_GetMode function returns USMC_Mode structure last sent to device
//
USMCDLL_API DWORD USMC_GetMode( DWORD Device,				// IN - Device number
							    USMC_Mode &Str				// OUT - Structure representing some of divice parameters
								);
//
//	The USMC_SetMode function sets some of device parameters
//
USMCDLL_API DWORD USMC_SetMode( DWORD Device,				// IN - Device number
							    USMC_Mode &Str				// IN/OUT Structure representing some of divice parameters
								);
//
//	The USMC_GetParameters function returns USMC_Parameters structure last sent to device
//
USMCDLL_API DWORD USMC_GetParameters( DWORD Device,			// IN - Device number
									  USMC_Parameters &Str	// OUT - Structure representing some of divice parameters
									  );
//
//	The USMC_SetParameters function sets some of divice parameters
//
USMCDLL_API DWORD USMC_SetParameters( DWORD Device,			// IN - Device number
									  USMC_Parameters &Str	// IN/OUT Structure representing some of divice parameters
									  );
//
//	The USMC_GetStartParameters function returns USMC_StartParameters structure last sent to device
//
USMCDLL_API DWORD USMC_GetStartParameters( DWORD Device,	// IN - Device number
										   USMC_StartParameters &Str	// OUT - Structure representing start function parameters
										   );
//
//	The USMC_Start function sets start parameters and starts motion
//
USMCDLL_API DWORD USMC_Start( DWORD Device,					// IN - Device number
							  int DestPos,					// IN - Destination position
							  float &Speed,					// IN/OUT - Speed of rotation
							  USMC_StartParameters &Str		// IN/OUT - Structure representing start function parameters
							  );
//
//	The USMC_Stop function stops device
//
USMCDLL_API DWORD USMC_Stop( DWORD Device					// IN - Device number
							 );
//
//	The USMC_GetLastErr function return string representing last error
//
USMCDLL_API void USMC_GetLastErr( char *str,				// OUT - String buffer
								  size_t len				// IN - Lenght of that string buffer in bytes
								  );

//
//	The USMC_GetDllVersion function returnes version values of USMCDLL.dll
//
USMCDLL_API void USMC_GetDllVersion( DWORD &dwHighVersion,	// OUT - High Version Value
									 DWORD &dwLowVersion);	// OUT - Low Version Value

//
//	The USMC_Close function closes virtual driver window "microsmc.exe"
//
USMCDLL_API DWORD USMC_Close( void );

//
//	The USMC_RestoreCurPos function checks AReset bit and if it is TRUE
//  restores previous CurPos value
//
USMCDLL_API DWORD USMC_RestoreCurPos(DWORD Device					// IN - Device number
									 );

// New For Firmware Version 2.4.1.0 (0x2410)

//
//	The USMC_GetEncoderState function returns structure representing current position of encoder
//
USMCDLL_API DWORD USMC_GetEncoderState( DWORD Device,			// IN - Device number
										USMC_EncoderState &Str	// IN/OUT Structure containing encoder state
										);

// ~New For Firmware Version 2.4.1.0 (0x2410)

}	// extern "C"
#else	// C
DWORD USMC_Init( USMC_Devices *Str );
DWORD USMC_GetState( DWORD Device, USMC_State *Str );
DWORD USMC_SaveParametersToFlash( DWORD Device );
DWORD USMC_SetCurrentPosition( DWORD Device, int Position );
DWORD USMC_GetMode( DWORD Device, USMC_Mode *Str );
DWORD USMC_SetMode( DWORD Device, USMC_Mode *Str );
DWORD USMC_GetParameters( DWORD Device, USMC_Parameters *Str );
DWORD USMC_SetParameters( DWORD Device, USMC_Parameters *Str );
DWORD USMC_GetStartParameters( DWORD Device, USMC_StartParameters *Str );
DWORD USMC_Start( DWORD Device, int DestPos, float *Speed, USMC_StartParameters *Str);
DWORD USMC_Stop( DWORD Device );
void  USMC_GetLastErr( char *str, size_t len );
DWORD USMC_Close( void );
DWORD USMC_GetEncoderState( DWORD Device, USMC_EncoderState *Str);
#endif	// C/C++


Penn

China
644 Posts

Posted - 01/29/2012 :  9:39:59 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Mike,

We have checked the way you used, and it should be correct. I have noticed that you are using Origin 7.5 SR0, so, maybe you can upgrade to 7.5 SR6 from this page, and then have a try again.

Penn
Go to Top of Page

sakuracz

4 Posts

Posted - 01/30/2012 :  05:40:54 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thanks for the quick reply.

However updating it didn't really help. USMC_Init(&dev) still gives a "command error" statement during execution.

Oh, and I forgot totally that I'm running Win 7 instead of XP (I'm totally used to XP).
Go to Top of Page

Penn

China
644 Posts

Posted - 01/31/2012 :  03:44:02 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Mike,

Do you have a try by Microsoft Visual Studio? And is it fine?

By the way, the function body of USMC_Init is invisible, we cannot know what happen with this function when stop here. I am afraid that you need to ask the dll provider about what have been done in this function.


Penn

Edited by - Penn on 01/31/2012 03:56:15 AM
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000