CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jun 2009
    Posts
    18

    error extern "C"

    me in the Console application works.
    In Form Aplications to report an error, the "extern", in header "USMCDLL.h"

    Declaration in Motor.cpp:

    // Motory.cpp : main project file.
    #pragma warning(disable : 4996) // Disable warnings about some functions in VS 2005
    #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers

    #include "stdafx.h"
    #include <stdio.h>
    #include <tchar.h>
    #include <conio.h>
    #include <process.h>
    #include "USMCDLL.h"
    #include "Form1.h"

    using namespace System;
    using namespace Motory;




    Declaration in USMCDLL.h :

    #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
    .
    .
    .
    .
    .(Code)
    .
    .
    .
    .
    .(functions in the following error occurs) (Error is reflected in all of these features)
    .
    #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++






    !!!!! (I give only one message that error.)!!!!!
    ERROR:

    Motory.obj : error LNK2031: unable to generate p/invoke for "extern "C" unsigned long __clrcall USMC_GetEncoderState(unsigned long,struct USMC_EncoderState_st &)" (?USMC_GetEncoderState@@$$J0YMKKAAUUSMC_EncoderState_st@@@Z); calling convention missing in metadata
    .
    .
    .
    Motory.obj : error LNK2028: unresolved token (0A00000B) "int __clrcall Exit(void)" (?Exit@@$$FYMHXZ) referenced in function "void __clrcall Start(void)" (?Start@@$$FYMXXZ)
    .
    .
    .
    Motory.obj : error LNK2019: unresolved external symbol "void __clrcall zapisListBox1(unsigned long,char *,char *)" (?zapisListBox1@@$$FYMXKPAD0@Z) referenced in function "void __clrcall PrintDevices(struct USMC_Devices_st &)" (?PrintDevices@@$$FYMXAAUUSMC_Devices_st@@@Z)



    Thank you for your help!

  2. #2
    Join Date
    Jul 2002
    Posts
    2,543

    Re: error extern "C"

    Where is the code which is not compiled? And where is USMC_EncoderState structure declaration?

  3. #3
    Join Date
    Jun 2009
    Posts
    18

    Re: error extern "C"

    Quote Originally Posted by Alex F View Post
    Where is the code which is not compiled? And where is USMC_EncoderState structure declaration?
    That is all in the head USMCDLL.h.
    The header I have USMCDLL.lib and USMCDLL.dll. This need never be declared?
    Errors occur when the translation function ( USMC_Init (USMC_Devices & Str) , USMC_GetState( DWORD Device, USMC_State &Str) ,...... )

    The entire code in the header is:

    #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&#37; 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&#194;; FALSE : 0&#194
    BOOL Tr2T; // Trailer 2 TRUE state (TRUE : +3/+5&#194;; FALSE : 0&#194
    BOOL RotTrT; // Rotary Transducer TRUE state (TRUE : +3/+5&#194;; FALSE : 0&#194
    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&#194;; FALSE : 0&#194
    BOOL Butt2T; // Button 2 TRUE state (TRUE : +3/+5&#194;; FALSE : 0&#194
    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[8]; // <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[8]; // <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[8]; // <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;


    #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++
    Last edited by Lubaaa; July 6th, 2009 at 04:29 AM.

  4. #4
    Join Date
    Jul 2002
    Posts
    2,543

    Re: error extern "C"

    Read MSDN topic "Linker Tools Error LNK2031" Possibly you need to declare USMC_GetEncoderState function as __cdecl explicitly. Error message contains __clrcall, which is default when managed code is compiled.

    http://msdn.microsoft.com/en-us/library/ms173734.aspx

  5. #5
    Join Date
    Jun 2009
    Posts
    18

    Re: error extern "C"

    Quote Originally Posted by Alex F View Post
    Read MSDN topic "Linker Tools Error LNK2031" Possibly you need to declare USMC_GetEncoderState function as __cdecl explicitly. Error message contains __clrcall, which is default when managed code is compiled.

    http://msdn.microsoft.com/en-us/library/ms173734.aspx

    Thanks it works. I wrote it this way:

    // 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[8]; // <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[8]; // <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[8]; // <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;


    #ifdef __cplusplus // C++
    extern "C" {
    //
    // The USMC_Init function initializes driver and returns devices information
    //
    USMCDLL_API DWORD __cdecl 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 __cdecl 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 __cdecl USMC_SaveParametersToFlash( DWORD Device // IN - Device number
    );
    //
    // The USMC_SetCurrentPosition function sets current position of controller
    //
    USMCDLL_API DWORD __cdecl 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 __cdecl 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 __cdecl 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 __cdecl 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 __cdecl 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 __cdecl 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 __cdecl 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 __cdecl USMC_Stop( DWORD Device // IN - Device number
    );
    //
    // The USMC_GetLastErr function return string representing last error
    //
    USMCDLL_API void __cdecl 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 __cdecl 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 __cdecl USMC_Close( void );

    //
    // The USMC_RestoreCurPos function checks AReset bit and if it is TRUE
    // restores previous CurPos value
    //
    USMCDLL_API DWORD __cdecl 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 __cdecl 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++


    Perhaps the code is good and not just a coincidence?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured