Subversion Repositories f9daq

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
284 f9daq 1
Attribute VB_Name = "Module1"
2
Public NOD, Dev As Long
3
Public serial, version As String
4
 
5
 
6
Type USMCMode
7
    PMode As Long       'Turn off buttons (TRUE - buttons disabled)
8
    PReg As Long        'Current reduction regime (TRUE - regime is on)
9
    ResetD As Long      'Turn power off and make a whole step (TRUE - apply)
10
    EmReset As Long     'Quick power off
11
    Tr1T As Long        'Trailer 1 TRUE state (TRUE : +3/+5Â; FALSE : 0Â)
12
    Tr2T As Long        'Trailer 2 TRUE state (TRUE : +3/+5Â; FALSE : 0Â)
13
    RotTrT As Long      'Rotary Transducer TRUE state (TRUE : +3/+5Â; FALSE : 0Â)
14
    TrSwap As Long      'If TRUE, Trailers are treated to be swapped
15
    Tr1En As Long       'If TRUE Trailer 1 Operation Enabled
16
    Tr2En As Long       'If TRUE Trailer 2 Operation Enabled
17
    RotTeEn As Long     'If TRUE Rotary Transducer Operation Enabled
18
    RotTrOp As Long     'Rotary Transducer Operation Select (stop on error for TRUE)
19
    Butt1T As Long      'Button 1 TRUE state (TRUE : +3/+5Â; FALSE : 0Â)
20
    Butt2T As Long      'Button 2 TRUE state (TRUE : +3/+5Â; FALSE : 0Â)
21
    ResetRT As Long     'Reset Rotary Transducer Check Positions (need one full revolution before it can detect error)
22
    SyncOUTEn As Long   'If TRUE output syncronization enabled
23
    SyncOUTR As Long    'If TRUE output synchronization counter will be reset
24
    SyncINOp As Long    'Synchronization input mode:
25
                        'True - Step motor will move one time to the destination position
26
                        'False - Step motor will move multiple times by steps equal to the value destination position
27
    SyncCount As Long   'Number of steps after which synchronization output sygnal occures
28
    SyncInvert As Long  'Set to TRUE to invert output synchronization signal
29
End Type
30
 
31
Type USMCParameters
32
    AccelT As Single        'Acceleration time (in ms)
33
    DecelT As Single        'Deceleration time (in ms)
34
    PTimeout As Single      'Time (in ms) after which current will be reduced to 60% of normal
35
    BTimeout1 As Single     'Time (in ms) after which speed of step motor rotation will be equal to the one specified at
36
                            'BTO1P field (see below). (This parameter is used when controlling step motor using buttons)
37
    BTimeout2 As Single     '
38
    BTimeout3 As Single     '
39
    BTimeout4 As Single     '
40
    BTimeoutR As Single     'Time (in ms) after which reset command will be performed
41
    BTimeoutD As Single     'This field is reserved for future use
42
    MinP As Single          'Speed (steps/sec) while performing reset operation. (This parameter is used when controlling
43
                            'step motor using buttons)
44
    BTO1P As Single         'Speed (steps/sec) after BTIMEOUT 1 time have passed. (This parameter is used when controlling
45
                            'step motor using buttons)
46
    BTO2P As Single         '
47
    BTO3P As Single         '
48
    BTO4P As Single         '
49
    MaxLoft As Long         'Value in full steps that will be used performing backlash operation
50
    StartPos As Long        'This field is reserved for future use
51
    RTDelta As Integer      'Revolution distance – number of full steps per one full revolution
52
    RTMinErr As Integer     'Number of full steps missed to raise the error flag
53
    MaxTemp As Single       'Maximum allowed temperature (Celsius)
54
    SynOUTP As Long         'Duration of the output synchronization pulse
55
    LoftPeriod As Single    'Speed of the last phase of the backlash operation.
56
End Type
57
 
58
Type USMCStartParameters
59
    SDivisor As Long    'Step is divided by this factor (1,2,4,8)
60
    DefDir As Long      'Direction for backlash operation (relative)
61
    LoftEn As Long      'Enable automatic backlash operation (works if slow start/stop mode is off)
62
    SlStart As Long     'If TRUE slow start/stop mode enabled.
63
    WSyncIN As Long     'If TRUE controller will wait for input synchronization signal to start
64
    SyncOUTR As Long    'If TRUE output synchronization counter will be reset
65
    ForceLoft As Long   'If TRUE and destination position is equal to the current position backlash operation will be performed.
66
End Type
67
 
68
Type USMCState
69
    CurPos As Long      'Current position (in microsteps)
70
    Temp As Single      'Current temperature of the driver
71
    SDivisor As Long    'Step is divided by this factor
72
    Loft As Long        'Indicates backlash status
73
    FullPower As Long   'If TRUE then full power.
74
    CW_CCW As Long      'Current direction. Relatively!
75
    Power As Long       'If TRUE then Step Motor is ON.
76
    FullSpeed As Long   'If TRUE then full speed. Valid in "Slow Start" mode only.
77
    AReset As Long      'TRUE After Device reset, FALSE after "Set Position".
78
    RUN As Long         'Indicates if step motor is rotating
79
    SyncIN As Long      'Logical state directly from input synchronization PIN
80
    SyncOUT As Long     'Logical state directly from output synchronization PIN
81
    RotTr As Long       'Indicates current rotary transducer press state
82
    RotTrErr As Long    'Indicates rotary transducer error flag
83
    EmReset As Long     'Indicates state of emergency disable button (local control)
84
    Trailer1 As Long    'Indicates trailer 1 logical state.
85
    Trailer2 As Long    'Indicates trailer 2 logical state.
86
    Voltage As Single   'Input power source voltage (6-39V) -=24 version 0nly=-
87
End Type
88
 
89
Declare Sub USMCGetLastErr Lib "USMCVBDLL.dll" _
90
    Alias "_USMCVB_GetLastErr@8" (ByVal ErrStr As String, ByVal vlen As Long)
91
 
92
Declare Function USMCInit Lib "USMCVBDLL.dll" _
93
    Alias "_USMCVB_Init@20" (ByRef value As Long, ByVal versions As String, _
94
    ByVal vlen As Long, ByVal serials As String, ByVal slen As Long) As Long
95
 
96
Declare Function USMCGetState Lib "USMCVBDLL.dll" _
97
    Alias "_USMCVB_GetState@8" (ByVal Dev As Long, ByRef Str As USMCState) As Long
98
 
99
Declare Function USMCGetStartParameters Lib "USMCVBDLL.dll" _
100
    Alias "_USMCVB_GetStartParameters@8" (ByVal Dev As Long, ByRef Str As USMCStartParameters) As Long
101
Declare Function USMCStart Lib "USMCVBDLL.dll" _
102
    Alias "_USMCVB_Start@16" (ByVal Dev As Long, ByVal DestPos As Long, ByRef Speed As Single, _
103
                              ByRef Str As USMCStartParameters) As Long
104
 
105
Declare Function USMCStop Lib "USMCVBDLL.dll" _
106
    Alias "_USMCVB_Stop@4" (ByVal Dev As Long) As Long
107
 
108
Declare Function USMCGetMode Lib "USMCVBDLL.dll" _
109
    Alias "_USMCVB_GetMode@8" (ByVal Dev As Long, ByRef Str As USMCMode) As Long
110
Declare Function USMCSetMode Lib "USMCVBDLL.dll" _
111
    Alias "_USMCVB_SetMode@8" (ByVal Dev As Long, ByRef Str As USMCMode) As Long
112
 
113
Declare Function USMCGetParameters Lib "USMCVBDLL.dll" _
114
    Alias "_USMCVB_GetParameters@8" (ByVal Dev As Long, ByRef Str As USMCParameters) As Long
115
Declare Function USMCSetParameters Lib "USMCVBDLL.dll" _
116
    Alias "_USMCVB_SetParameters@8" (ByVal Dev As Long, ByRef Str As USMCParameters) As Long
117
 
118
Declare Function USMCSaveParametersToFlash Lib "USMCVBDLL.dll" _
119
    Alias "_USMCVB_SaveParametersToFlash@4" (ByVal Dev As Long) As Long
120
 
121
Declare Function USMCSetCurrentPosition Lib "USMCVBDLL.dll" _
122
    Alias "_USMCVB_SetCurrentPosition@8" (ByVal Dev As Long, ByRef Str As USMCParameters) As Long
123
 
124
 
125
Sub PrintDMode(mode As USMCMode)
126
    Dim out As String
127
    out = "Mode parameters:" & (Chr(13))
128
    out = out & "Buttons - "
129
    If mode.PMode <> 0 Then
130
        out = out & "Disabled" & (Chr(13))
131
    Else
132
        out = out & "Enabled" & (Chr(13)) & "Button 1 TRUE state - "
133
        If mode.Butt1T <> 0 Then
134
            out = out & "+3/+5 V" & (Chr(13))
135
        Else
136
            out = out & "0 V(GND)" & (Chr(13))
137
        End If
138
        out = out & "Button 2 TRUE state - "
139
        If mode.Butt2T <> 0 Then
140
            out = out & "+3/+5 V" & (Chr(13))
141
        Else
142
            out = out & "0 V(GND)" & (Chr(13))
143
        End If
144
    End If
145
    out = out & "Current reduction regime - "
146
    If mode.PReg <> 0 Then
147
        out = out & "Used" & (Chr(13))
148
    Else
149
        out = out & "Not Used" & (Chr(13))
150
    End If
151
 
152
    If mode.ResetD <> 0 Then
153
        out = out & "Power - "
154
        If mode.EmReset <> 0 Then
155
            out = out & "Emerjency Off" & (Chr(13))
156
        Else
157
            out = out & "Off" & (Chr(13))
158
        End If
159
    Else
160
        out = out & "Power - On" & (Chr(13))
161
    End If
162
    If mode.Tr1En <> 0 Or mode.Tr2En <> 0 Then
163
        out = out & "Trailers are - "
164
        If mode.TrSwap <> 0 Then
165
            out = out & "Swapped" & (Chr(13))
166
        Else
167
            out = out & "Direct" & (Chr(13))
168
        End If
169
    End If
170
    out = out & "Trailer 1 - "
171
    If mode.Tr1En <> 0 Then
172
        out = out & "Enabled" & (Chr(13)) & "Trailer 1 TRUE state - "
173
        If mode.Tr1T <> 0 Then
174
            out = out & "+3/+5 V" & (Chr(13))
175
        Else
176
            out = out & "0 V(GND)" & (Chr(13))
177
        End If
178
    Else
179
        out = out & "Disabled" & (Chr(13))
180
    End If
181
    out = out & "Trailer 2 - "
182
    If mode.Tr2En <> 0 Then
183
        out = out & "Enabled" & (Chr(13)) & "Trailer 2 TRUE state - "
184
        If mode.Tr2T <> 0 Then
185
            out = out & "+3/+5 V" & (Chr(13))
186
        Else
187
            out = out & "0 V(GND)" & (Chr(13))
188
        End If
189
    Else
190
        out = out & "Disabled" & (Chr(13))
191
    End If
192
    out = out & "Rotary Transducer - "
193
    If mode.RotTeEn <> 0 Then
194
        out = out & "Enabled" & (Chr(13)) & "Rotary Transducer TRUE state - "
195
        If mode.RotTrT <> 0 Then
196
            out = out & "+3/+5 V" & (Chr(13))
197
        Else
198
            out = out & "0 V(GND)" & (Chr(13))
199
        End If
200
        out = out & "Rotary Transducer Operation - "
201
        If mode.RotTrOp <> 0 Then
202
            out = out & "Stop on error" & (Chr(13))
203
        Else
204
            out = out & "Check and ignore error" & (Chr(13))
205
        End If
206
        out = out & "Reset Rotary Transducer Check Positions - "
207
        If mode.ResetRT <> 0 Then
208
            out = out & "Initiated" & (Chr(13))
209
        Else
210
            out = out & "No, why?" & (Chr(13))
211
        End If
212
    Else
213
        out = out & "Disabled" & (Chr(13))
214
    End If
215
    out = out & "Output Syncronization - "
216
    If mode.SyncOUTEn <> 0 Then
217
        out = out & "Enabled" & (Chr(13)) & "Reset Output Synchronization Counter - "
218
        If mode.SyncOUTR <> 0 Then
219
            out = out & "Initiated" & (Chr(13))
220
        Else
221
            out = out & "No, why?" & (Chr(13))
222
        End If
223
        out = out & "Number of steps after which synchronization output sygnal occures - " & mode.SyncCount & (Chr(13))
224
    Else
225
        out = out & "Disabled" & (Chr(13))
226
    End If
227
    out = out & "Synchronization input mode:" & (Chr(13))
228
    If mode.SyncINOp <> 0 Then
229
        out = out & "Step motor will move one time to the destination position" & (Chr(13))
230
    Else
231
        out = out & "Step motor will move multiple times by [destination position]" & (Chr(13))
232
    End If
233
    out = out & "Synchronization Output - "
234
    If mode.SyncInvert <> 0 Then
235
        out = out & "INVERTED" & (Chr(13))
236
    Else
237
        out = out & "NORMAL" & (Chr(13))
238
    End If
239
    MsgBox out, vbOKOnly, "USMC_SetMode Successful"
240
End Sub
241
 
242
Sub PrintDState(state As USMCState)
243
Dim out As String
244
With state
245
    out = "The state is:" & (Chr(13))
246
    out = out & "- Current Position in microsteps - " & Format(.CurPos) & (Chr(13))
247
    out = out & "- Temperature - " & Format(.Temp, "0.00") & (Chr(176)) & (Chr(67)) & (Chr(13))
248
    out = out & "- Step Divisor - " & Format(.SDivisor, "0") & (Chr(13))
249
    out = out & "- Loft State - "
250
    If .Loft <> 0 Then
251
        out = out & "Indefinite" & (Chr(13))
252
    Else
253
        out = out & "Fixed" & (Chr(13))
254
    End If
255
    out = out & "- Power - "
256
    If .Power <> 0 Then
257
        If .FullPower <> 0 Then
258
            out = out & "Full" & (Chr(13))
259
        Else
260
            out = out & "Half" & (Chr(13))
261
        End If
262
    Else
263
        out = out & "Off" & (Chr(13))
264
    End If
265
    If .RUN <> 0 Then
266
        out = out & "- Step Motor is Running in "
267
        If .CW_CCW <> 0 Then
268
            out = out & "CCW Direction "
269
        Else
270
            out = out & "CW Direction "
271
        End If
272
        If (.SDivisor = 1) And (.FullSpeed <> 0) Then
273
            out = out & "at Full Speed" & (Chr(13))
274
        Else
275
            out = out & (Chr(13))
276
        End If
277
    Else
278
        out = out & "- Step Motor is Not Running" & (Chr(13))
279
    End If
280
    out = out & "- Device "
281
    If .AReset <> 0 Then
282
        out = out & "is After Reset" & (Chr(13))
283
    Else
284
        out = out & "Position Already Set" & (Chr(13))
285
    End If
286
    out = out & "- Input Synchronization Logical Pin State - "
287
    If .SyncIN <> 0 Then
288
        out = out & "TRUE" & (Chr(13))
289
    Else
290
        out = out & "FALSE" & (Chr(13))
291
    End If
292
    out = out & "- Output Synchronization Logical Pin State - "
293
    If .SyncOUT <> 0 Then
294
        out = out & "TRUE" & (Chr(13))
295
    Else
296
        out = out & "FALSE" & (Chr(13))
297
    End If
298
    out = out & "- Rotary Transducer Logical Pin State - "
299
    If .RotTr <> 0 Then
300
        out = out & "TRUE" & (Chr(13))
301
    Else
302
        out = out & "FALSE" & (Chr(13))
303
    End If
304
    out = out & "- Rotary Transducer Error Flag - "
305
    If .RotTrErr <> 0 Then
306
        out = out & "Error" & (Chr(13))
307
    Else
308
        out = out & "Clear" & (Chr(13))
309
    End If
310
    out = out & "- Emergency Disable Button - "
311
    If .EmReset <> 0 Then
312
        out = out & "Pushed" & (Chr(13))
313
    Else
314
        out = out & "Unpushed" & (Chr(13))
315
    End If
316
    out = out & "- Trailer 1 Press State - "
317
    If .Trailer1 <> 0 Then
318
        out = out & "Pushed" & (Chr(13))
319
    Else
320
        out = out & "Unpushed" & (Chr(13))
321
    End If
322
    out = out & "- Trailer 2 Press State - "
323
    If .Trailer2 <> 0 Then
324
        out = out & "Pushed" & (Chr(13))
325
    Else
326
        out = out & "Unpushed" & (Chr(13))
327
    End If
328
    out = out & "- Input Voltage - "
329
    If .Voltage = 0 Then
330
        out = out & "Low" & (Chr(13))
331
    Else
332
        out = out & Format(.Voltage, "0.0") & (Chr(13))
333
    End If
334
    MsgBox out, vbOKOnly, "USMC_GetState Successful"
335
End With
336
End Sub
337
 
338
Sub PrintError()
339
    Dim out As String
340
    out = String(1000, 0)
341
    USMCGetLastErr out, 1000
342
    MsgBox out, vbOKOnly, "Error"
343
End Sub
344
 
345
Sub PrintDStartParameters(DPos As Long, Speed As Single, sp As USMCStartParameters)
346
With sp
347
    Dim out As String
348
    out = "Destination position - " & Format(DPos) & (Chr(13))
349
    out = out & "Speed - " & Format(Speed, "##.00") & " tacts/s" & (Chr(13))
350
    out = out & "Steps Divisor - " & Format(.SDivisor, "0") & (Chr(13))
351
    If .SDivisor = 1 Then
352
        out = out & "Slow start/stop mode - "
353
        If .SlStart <> 0 Then
354
            out = out & "Enabled" & (Chr(13))
355
        Else
356
            out = out & "Disabled" & (Chr(13))
357
        End If
358
    Else
359
        out = out & "Automatic backlash operation - "
360
        If .LoftEn <> 0 Then
361
            out = out & "Enabled" & (Chr(13))
362
            out = out & "Automatic backlash operation direction - "
363
            If .DefDir <> 0 Then
364
                out = out & "CCW" & (Chr(13))
365
            Else
366
                out = out & "CW" & (Chr(13))
367
            End If
368
            out = out & "Force automatic backlash operation - "
369
            If .ForceLoft <> 0 Then
370
                out = out & "TRUE" & (Chr(13))
371
            Else
372
                out = out & "FALSE" & (Chr(13))
373
            End If
374
        Else
375
            out = out & "Disabled" & (Chr(13))
376
        End If
377
    End If
378
    If .WSyncIN <> 0 Then
379
        out = out & "Controller will wait for input synchronization signal to start" & (Chr(13))
380
    Else
381
        out = out & "Input synchronization signal ignored" & (Chr(13))
382
    End If
383
    If .SyncOUTR <> 0 Then
384
        out = out & "Output synchronization counter will be reset" & (Chr(13))
385
    Else
386
        out = out & "Output synchronization counter will not be reset" & (Chr(13))
387
    End If
388
 
389
    MsgBox out, vbOKOnly, "USMC_Start Successful"
390
 
391
End With
392
End Sub
393
 
394
Sub PrintDParameters(Parameters As USMCParameters)
395
With Parameters
396
    Dim out As String
397
    out = "The parameters are:" & (Chr(13))
398
    out = out & "Full acceleration time - " & Format(.AccelT, "###0") & " ms" & (Chr(13))
399
    out = out & "Full deceleration time - " & Format(.DecelT, "###0") & " ms" & (Chr(13))
400
    out = out & "Power reduction timeout - " & Format(.PTimeout, "###0") & " ms" & (Chr(13))
401
    out = out & "Button speedup timeout 1 - " & Format(.BTimeout1, "###0") & " ms" & (Chr(13))
402
    out = out & "Button speed after timeout 1 - " & Format(.BTO1P, "###0.00") & " steps/s" & (Chr(13))
403
    out = out & "Button speedup timeout 2 - " & Format(.BTimeout2, "###0") & " ms" & (Chr(13))
404
    out = out & "Button speed after timeout 2 - " & Format(.BTO2P, "###0.00") & " steps/s" & (Chr(13))
405
    out = out & "Button speedup timeout 3 - " & Format(.BTimeout3, "###0") & " ms" & (Chr(13))
406
    out = out & "Button speed after timeout 3 - " & Format(.BTO3P, "###0.00") & " steps/s" & (Chr(13))
407
    out = out & "Button speedup timeout 4 - " & Format(.BTimeout4, "###0") & " ms" & (Chr(13))
408
    out = out & "Button speed after timeout 4 - " & Format(.BTO4P, "###0.00") & " steps/s" & (Chr(13))
409
    out = out & "Button reset timeout - " & Format(.BTimeoutR, "###0") & " ms" & (Chr(13))
410
    out = out & "Button reset operation speed - " & Format(.MinP, "###0.00") & " steps/s" & (Chr(13))
411
    out = out & "Backlash operation distance - " & Format(.MaxLoft) & " steps" & (Chr(13))
412
    out = out & "Revolution distance - " & Format(.RTDelta) & " steps" & (Chr(13))
413
    out = out & "Minimal revolution distance error - " & Format(.RTMinErr) & " steps" & (Chr(13))
414
    out = out & "Power off temperature - " & Format(.MaxTemp, "##0.00") & (Chr(176)) & (Chr(67)) & (Chr(13))
415
    out = out & "Duration of the output synchronization pulse - "
416
    If .SynOUTP = 0 Then
417
       out = out & "minimal" & (Chr(13))
418
    Else
419
       out = out & Format(.SynOUTP - 0.5, "##0.0") & " * [Tact Period]" & (Chr(13))
420
    End If
421
    out = out & "Speed of the last phase of the backlash operation - "
422
    If .LoftPeriod = 0 Then
423
       out = out & "normal" & (Chr(13))
424
    Else
425
       out = out & Format(.LoftPeriod - 0.5, "###0.00") & " steps/s" & (Chr(13))
426
    End If
427
    MsgBox out, vbOKOnly, "USMC_SetParameters Successful"
428
 
429
End With
430
End Sub