Subversion Repositories f9daq

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
7 f9daq 1
#ifndef _USMCDLL_H
2
#define _USMCDLL_H
3
 
4
 
5
#include        <stdlib.h>
6
 
7
 
8
#define         USMC_ERROR_REF_DEV_DISCONNECTED         0x14141413
9
#define         USMC_ERROR_NOT_INITIALIZED              0x14141414
10
#define         USMC_ERROR_NO_DEVICES_CONNECTED         0x14141415
11
#define         USMC_SUCCESS                            0
12
#define         TRUE                                    1
13
#define         FALSE                                   0
14
 
15
 
16
typedef         unsigned char   BYTE;
17
typedef         unsigned int    DWORD;
18
typedef         unsigned short  WORD;
19
typedef         unsigned int    BOOL;
20
typedef         void *          PVOID;
21
 
22
 
23
typedef struct  _USMC_Devices
24
{
25
        DWORD   NOD;     // Number of devices connected to computer.
26
        char ** Serial;  // Array of pointers to 16√byte ASCII strings of length √ NOD.
27
        char ** Version; // Array of pointers to 4√byte ASCII strings of length √ NOD.
28
} USMC_Devices, * PUSMC_Devices, * LPUSMC_Devices;
29
 
30
 
31
typedef struct  _USMC_Parameters
32
{
33
        float AccelT;     // Acceleration time (in ms).
34
        float DecelT;     // Deceleration time (in ms).
35
        float PTimeout;   // Time (in ms) after which current will be reduced to 60% of normal.
36
        float BTimeout1;  // Time (in ms) after which speed of step motor rotation will be equal to the one specified at BTO1P field in this structure.
37
        float BTimeout2;  // Time (in ms) after which speed of step motor rotation will be equal to the one specified at BTO2P field in this structure.
38
        float BTimeout3;  // Time (in ms) after which speed of step motor rotation will be equal to the one specified at BTO3P field in this structure.
39
        float BTimeout4;  // Time (in ms) after which speed of step motor rotation will be equal to the one specified at BTO4P field in this structure.
40
        float BTimeoutR;  // Time (in ms) after which reset command will be performed.
41
        float BTimeoutD;  // This field is reserved for future use.
42
        float MinP;               // Speed (steps/sec) while performing reset operation.
43
        float BTO1P;      // Speed (steps/sec) after BTIMEOUT1 time has passed.
44
        float BTO2P;      // Speed (steps/sec) after BTIMEOUT2 time has passed.
45
        float BTO3P;      // Speed (steps/sec) after BTIMEOUT3 time has passed.
46
        float BTO4P;      // Speed (steps/sec) after BTIMEOUT4 time has passed.
47
        WORD  MaxLoft;    // Value in full steps that will be used performing backlash operation.
48
        DWORD StartPos;   // Current Position saved to FLASH.
49
        WORD  RTDelta;    // Revolution distance √ number of full steps per one full revolution.
50
        WORD  RTMinError; // Number of full steps missed to raise the error flag.
51
        float MaxTemp;    // Maximum allowed temperature (centigrade degrees).
52
        BYTE  SynOUTP;    // Duration of the output synchronization pulse.
53
        float LoftPeriod; // Speed (steps/sec) of the last phase of the backlash operation.
54
        float EncMult;    // Encoder step multiplier. Should be <Encoder Steps per Evolution> / <SM Steps per Evolution> and should be integer multiplied by 0.25.
55
} USMC_Parameters, * PUSMC_Parameters, * LPUSMC_Parameters;
56
 
57
 
58
typedef struct  _USMC_StartParameters
59
{
60
        BYTE SDivisor;  // Step is divided by this factor (1,2,4,8).
61
        BOOL DefDir;    // Direction for backlash operation (relative).
62
        BOOL LoftEn;    // Enable automatic backlash operation (works if slow start/stop mode is off).
63
        BOOL SlStart;   // If TRUE slow start/stop mode enabled.
64
        BOOL WSyncIN;   // If TRUE controller will wait for input synchronization signal to start.
65
        BOOL SyncOUTR;  // If TRUE output synchronization counter will be reset.
66
        BOOL ForceLoft; // If TRUE and destination position is equal to the current position backlash operation will be performed.
67
} USMC_StartParameters, * PUSMC_StartParameters, * LPUSMC_StartParameters;
68
 
69
 
70
typedef struct  _USMC_Mode
71
{                                               // Masked               Saved To Flash          Description:
72
        BOOL  PMode;            //              √                     YES                                     Turn off buttons (TRUE - buttons disabled).
73
        BOOL  PReg;                     //              √                     YES                                     Current reduction regime (TRUE - regime is on).
74
        BOOL  ResetD;           //              √                     YES                                     Turn power off and make a whole step (TRUE - apply).
75
        BOOL  EMReset;          //              √                     √                                     Quick power off.
76
        BOOL  Tr1T;                     //              √                     YES                                     Trailer 1 TRUE state (TRUE : +3/+5б; FALSE : 0б).
77
        BOOL  Tr2T;                     //              √                     YES                                     Trailer 2 TRUE state (TRUE : +3/+5б; FALSE : 0б).
78
        BOOL  RotTrT;           //              √                     YES                                     Rotary Transducer TRUE state (TRUE : +3/+5б; FALSE : 0б).
79
        BOOL  TrSwap;           //              √                     YES                                     If TRUE, Trailers are treated to be swapped.
80
        BOOL  Tr1En;            //              √                     YES                                     If TRUE Trailer 1 Operation Enabled.
81
        BOOL  Tr2En;            //              √                     YES                                     If TRUE Trailer 2 Operation Enabled.
82
        BOOL  RotTeEn;          //              √                     YES                                     If TRUE Rotary Transducer Operation Enabled.
83
        BOOL  RotTrOp;          //              √                     YES                                     Rotary Transducer Operation Select (stop on error if TRUE).
84
        BOOL  Butt1T;           //              √                     YES                                     Button 1 TRUE state (TRUE : +3/+5б; FALSE : 0б).
85
        BOOL  Butt2T;           //              √                     YES                                     Button 2 TRUE state (TRUE : +3/+5б; FALSE : 0б).
86
        BOOL  ResetRT;          //              YES                     √                                     Reset Rotary Transducer Check Positions (need one full revolution before it can detect error).
87
        BOOL  SyncOUTEn;        //              √                     YES                                     If TRUE output synchronization enabled.
88
        BOOL  SyncOUTR;         //              YES                     √                                     If TRUE output synchronization counter will be reset.
89
        BOOL  SyncINOp;         //              √                     YES                                     Synchronization input mode: 
90
                                                //                                                                              TRUE - Step motor will move one time to the DestPos 
91
                                                //                                                                              FALSE - Step motor will move multiple times by DestPos microsteps as distance.
92
        DWORD SyncCount;        //              √                     YES                                     Number of steps after which synchronization output signal occurs.
93
        BOOL  SyncInvert;       //              √                     YES                                     Set this bit to TRUE to invert output synchronization polarity.
94
        BOOL  EncoderEn;        //              √                     YES                                     Enable Encoder on pins {SYNCIN,ROTTR} - disables Synchronization input and Rotary Transducer.
95
        BOOL  EncoderInv;       //              √                     YES                                     Invert Encoder Counter Direction.
96
        BOOL  ResBEnc;          //              YES                     √                                     Reset <EncoderPos> and <ECurPos> to 0.
97
        BOOL  ResEnc;           //              YES                     √                                     Reset <ECurPos> to <EncoderPos>.
98
} USMC_Mode, * PUSMC_Mode, * LPUSMC_Mode;
99
 
100
 
101
typedef struct  _USMC_State
102
{
103
        int CurPos;             // Current position (in 1/8 steps).
104
        float Temp;             // Current temperature of the power driver.
105
        BYTE SDivisor;  // Step is divided by this factor.
106
        BOOL Loft;              // Indicates backlash status.
107
        BOOL FullPower; // Full power if TRUE.
108
        BOOL CW_CCW;    // Current direction of rotation (relatively to some direction √ dependent on step motor circuits connection and on its construction).
109
        BOOL Power;             // If TRUE then Step Motor power is ON.
110
        BOOL FullSpeed; // If TRUE then full speed. Valid in "Slow Start" mode only.
111
        BOOL AReset;    // TRUE After Device reset, FALSE after "Set Position".
112
        BOOL RUN;               // TRUE if step motor is rotating.
113
        BOOL SyncIN;    // Logical state directly from input synchronization PIN (pulses treated as positive).
114
        BOOL SyncOUT;   // Logical state directly from output synchronization PIN (pulses are positive).
115
        BOOL RotTr;             // Indicates current rotary transducer logical press state.
116
        BOOL RotTrErr;  // Indicates rotary transducer error flag (reset by USMC_SetMode function with ResetRT bit √ TRUE).
117
        BOOL EmReset;   // Indicates state of emergency disable button (TRUE √ Step motor power off).
118
        BOOL Trailer1;  // Indicates trailer 1 logical press state.
119
        BOOL Trailer2;  // Indicates trailer 2 logical press state.
120
        float Voltage;  // Input power source voltage (6-39V) -= 24 version 0nly=-.
121
} USMC_State, * PUSMC_State, * LPUSMC_State;
122
 
123
 
124
typedef struct  _USMC_EncoderState
125
{
126
        int EncoderPos; // Current position measured by encoder.
127
        int ECurPos;    // Current position (in Encoder Steps) - Synchronized with request call.
128
} USMC_EncoderState, * PUSMC_EncoderState, * LPUSMC_EncoderState;
129
 
130
 
131
typedef USMC_Devices const * PCUSMC_Devices;
132
typedef USMC_Devices const * LPCUSMC_Devices;
133
typedef USMC_Parameters const * PCUSMC_Parameters;
134
typedef USMC_Parameters const * LPCUSMC_Parameters;
135
typedef USMC_StartParameters const * PCUSMC_StartParameters;
136
typedef USMC_StartParameters const * LPCUSMC_StartParameters;
137
typedef USMC_Mode const * PCUSMC_Mode;
138
typedef USMC_Mode const * LPCUSMC_Mode;
139
typedef USMC_State const * PCUSMC_State;
140
typedef USMC_State const * LPCUSMC_State;
141
typedef USMC_EncoderState const * PCUSMC_EncoderState;
142
typedef USMC_EncoderState const * LPCUSMC_EncoderState;
143
 
144
 
145
DWORD USMC_Init ( USMC_Devices * Str );
146
DWORD USMC_GetState ( DWORD Device, USMC_State * Str );
147
DWORD USMC_SaveParametersToFlash ( DWORD Device );
148
DWORD USMC_GetMode ( DWORD Device, USMC_Mode * Str );
149
DWORD USMC_SetMode ( DWORD Device, USMC_Mode * Str );
150
DWORD USMC_GetParameters ( DWORD Device, USMC_Parameters * Str );
151
DWORD USMC_SetParameters ( DWORD Device, USMC_Parameters * Str );
152
DWORD USMC_GetStartParameters ( DWORD Device, USMC_StartParameters * Str );
153
DWORD USMC_Start ( DWORD Device, int DestPos,
154
                                   float * Speed,
155
                                   USMC_StartParameters * Str );
156
DWORD USMC_Stop ( DWORD Device );
157
DWORD USMC_SetCurrentPosition ( DWORD Device, int Position );
158
DWORD USMC_GetEncoderState ( DWORD Device, USMC_EncoderState * Str );
159
void  USMC_GetLastErr ( char * str, ssize_t len );
160
DWORD USMC_Close ( void );
161
#endif  // _USMCDLL_H