Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 284 | f9daq | 1 | program Delphi_test; |
| 2 | |||
| 3 | {$APPTYPE CONSOLE} |
||
| 4 | |||
| 5 | uses |
||
| 6 | SysUtils, |
||
| 7 | Windows, |
||
| 8 | ST_function in 'ST_function.pas'; |
||
| 9 | |||
| 10 | var |
||
| 11 | Dev: Longword; |
||
| 12 | DVS: TUSMC_Devices; |
||
| 13 | StandaClass: TStandaClass; |
||
| 14 | SMPower:boolean = FALSE; |
||
| 15 | |||
| 16 | procedure Cls; |
||
| 17 | var |
||
| 18 | buffer: TConsoleScreenBufferInfo; |
||
| 19 | i: integer; |
||
| 20 | begin |
||
| 21 | GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE),buffer); |
||
| 22 | for i:=0 to buffer.dwSize.y do writeln; |
||
| 23 | end; |
||
| 24 | |||
| 25 | // Function that prints information about connected devices to console |
||
| 26 | procedure PrintDevices(DVS: TUSMC_Devices); |
||
| 27 | var |
||
| 28 | i: integer; |
||
| 29 | Serial,Version:array of PChar; |
||
| 30 | begin |
||
| 31 | Serial:=DVS.Serial; |
||
| 32 | SetLength(Serial,DVS.NOD); |
||
| 33 | Version:=DVS.Version; |
||
| 34 | SetLength(Version,DVS.NOD); |
||
| 35 | for i:=0 to DVS.NOD-1 do |
||
| 36 | begin |
||
| 37 | writeln( Format('Device - %d,'+#9+'Serial Number - %.16s,'+#9+'Version - %.4s', [i+1, Serial[i], Version[i]] )); |
||
| 38 | end; |
||
| 39 | end; |
||
| 40 | |||
| 41 | // Function that prints last error information |
||
| 42 | procedure PrintError; |
||
| 43 | var |
||
| 44 | err: array[0..100] of Char; |
||
| 45 | p_err: PChar; |
||
| 46 | begin |
||
| 47 | err:=''; |
||
| 48 | p_err:=err; |
||
| 49 | StandaClass.USMC_GetLastErr(p_err,100); |
||
| 50 | writeln(''); |
||
| 51 | write(p_err); |
||
| 52 | end; |
||
| 53 | |||
| 54 | // Function that prints information about device state to console |
||
| 55 | procedure PrintDState(const State: TUSMC_State); |
||
| 56 | var |
||
| 57 | s,ss: string; |
||
| 58 | begin |
||
| 59 | writeln( 'The state is:' ); |
||
| 60 | writeln( Format('- Current Position in microsteps - %d', [State.CurPos] )); |
||
| 61 | writeln( Format('- Temperature - %.2f'+#248+#67, [State.Temp] )); |
||
| 62 | writeln( Format('- Step Divisor - %d', [State.SDivisor])); |
||
| 63 | if (State.Loft) then s:='Indefinite' else s:='Fixed'; |
||
| 64 | writeln( Format('- Loft State - %s', [s] )); |
||
| 65 | if (State.Power) then |
||
| 66 | begin |
||
| 67 | if (State.FullPower) then s:='Full' else s:='Half'; |
||
| 68 | end |
||
| 69 | else s:='Off'; |
||
| 70 | writeln( Format( '- Power - %s', [s] )); |
||
| 71 | if State.RUN then |
||
| 72 | begin |
||
| 73 | if State.CW_CCW then s:='CCW' else s:='CW'; |
||
| 74 | if ((State.SDivisor=1) and State.FullSpeed) then ss:='at Full Speed' else ss:=''; |
||
| 75 | writeln( Format('- Step Motor is Running in %s Direction %s', [s,ss])); |
||
| 76 | end |
||
| 77 | else writeln( '- Step Motor is Not Running' ); |
||
| 78 | if State.AReset then s:='is After Reset' else s:='Position Already Set'; |
||
| 79 | writeln( Format('- Device %s', [s])); |
||
| 80 | if State.SyncIN then s:='TRUE' else s:='FALSE'; |
||
| 81 | writeln( Format('- Input Synchronization Logical Pin State - %s', [s])); |
||
| 82 | if State.SyncOUT then s:='TRUE' else s:='FALSE'; |
||
| 83 | writeln( Format('- Output Synchronization Logical Pin State - %s', [s])); |
||
| 84 | if State.RotTr then s:='TRUE' else s:='FALSE'; |
||
| 85 | writeln( Format('- Rotary Transducer Logical Pin State - %s', [s])); |
||
| 86 | if State.RotTrErr then s:='Error' else s:='Clear'; |
||
| 87 | writeln( Format('- Rotary Transducer Error Flag - %s', [s])); |
||
| 88 | if State.EmReset then s:='Pushed' else s:='Unpushed'; |
||
| 89 | writeln( Format('- Emergency Disable Button - %s', [s])); |
||
| 90 | if State.Trailer1 then s:='Pushed' else s:='Unpushed'; |
||
| 91 | writeln( Format('- Trailer 1 Press State - %s', [s])); |
||
| 92 | if State.Trailer2 then s:='Pushed' else s:='Unpushed'; |
||
| 93 | writeln( Format('- Trailer 2 Press State - %s', [s])); |
||
| 94 | if State.Voltage = 0.0 then |
||
| 95 | writeln( '- Input Voltage - Low' ) |
||
| 96 | else |
||
| 97 | writeln( Format('- Input Voltage - %.1fV', [State.Voltage])); |
||
| 98 | |||
| 99 | end; |
||
| 100 | |||
| 101 | // Function that scans start parameters |
||
| 102 | procedure ScanDStartParameters(var DPos: integer; var Speed:single; var SP: TUSMC_StartParameters); |
||
| 103 | var |
||
| 104 | s:string; |
||
| 105 | begin |
||
| 106 | // Defaults |
||
| 107 | Speed:= 2000.0; |
||
| 108 | DPos:= 0; |
||
| 109 | SP.SDivisor:= 8; |
||
| 110 | |||
| 111 | write( 'Destination position:' ); |
||
| 112 | readln(s); |
||
| 113 | DPos:= StrToIntDef(s,DPos); |
||
| 114 | write( 'Speed (in tacts):' ); |
||
| 115 | readln(s); |
||
| 116 | Speed:= StrToFloatDef(s,Speed); |
||
| 117 | write( 'Steps Divisor:' ); |
||
| 118 | readln(s); |
||
| 119 | SP.SDivisor:= StrToIntDef(s,SP.SDivisor); |
||
| 120 | end; |
||
| 121 | |||
| 122 | // Function that prints information about device start parameters to console |
||
| 123 | procedure PrintDStartParameters(DPos:integer; Speed:single; const SP:TUSMC_StartParameters); |
||
| 124 | var |
||
| 125 | s:string; |
||
| 126 | begin |
||
| 127 | writeln( Format('Destination position - %d', [DPos])); |
||
| 128 | writeln( Format('Speed - %.2f tacts/s', [Speed] )); |
||
| 129 | writeln( Format('Steps Divisor - %d', [SP.SDivisor] )); |
||
| 130 | if SP.SDivisor = 1 then |
||
| 131 | begin |
||
| 132 | if SP.SlStart then s:='Enabled' else s:='Disabled'; |
||
| 133 | writeln( Format( 'Slow start/stop mode - %s', [s] )); |
||
| 134 | end |
||
| 135 | else if SP.LoftEn then |
||
| 136 | begin |
||
| 137 | writeln('Automatic backlash operation - Enabled' ); |
||
| 138 | if SP.DefDir then s:='CCW' else s:='CW'; |
||
| 139 | writeln(Format('Automatic backlash operation direction - %s', [s])); |
||
| 140 | |||
| 141 | if SP.ForceLoft then s:='TRUE' else s:='FALSE'; |
||
| 142 | writeln(Format('Force automatic backlash operation - %s', [s])); |
||
| 143 | end |
||
| 144 | else |
||
| 145 | begin |
||
| 146 | writeln('Automatic backlash operation - Disabled'); |
||
| 147 | end; |
||
| 148 | if SP.WSyncIN then |
||
| 149 | writeln('Controller will wait for input synchronization signal to start' ) |
||
| 150 | else |
||
| 151 | writeln('Input synchronization signal ignored' ); |
||
| 152 | if SP.SyncOUTR then s:='' else s:='not '; |
||
| 153 | writeln(Format('Output synchronization counter will %sbe reset', [s])); |
||
| 154 | end; |
||
| 155 | |||
| 156 | // Function that prints information about device "mode" parameters to console |
||
| 157 | procedure PrintDMode(const Mode:TUSMC_Mode); |
||
| 158 | var |
||
| 159 | s:string; |
||
| 160 | begin |
||
| 161 | writeln('Mode parameters:' ); |
||
| 162 | write('Buttons - '); |
||
| 163 | if Mode.PMode then |
||
| 164 | writeln('Disabled') |
||
| 165 | else |
||
| 166 | begin |
||
| 167 | writeln('Enabled'); |
||
| 168 | if Mode.Butt1T then s:='+3/+5 V' else s:='0 V(GND)'; |
||
| 169 | writeln('Button 1 TRUE state - '+s); |
||
| 170 | if Mode.Butt2T then s:='+3/+5 V' else s:='0 V(GND)'; |
||
| 171 | writeln('Button 2 TRUE state - '+s); |
||
| 172 | end; |
||
| 173 | if Mode.PReg then s:='Used' else s:='Not Used'; |
||
| 174 | writeln('Current reduction regime - '+s); |
||
| 175 | |||
| 176 | if Mode.ResetD then |
||
| 177 | begin |
||
| 178 | if Mode.EMReset then s:='Emerjency Off' else s:='Off'; |
||
| 179 | writeln('Power - '+s); |
||
| 180 | end |
||
| 181 | else |
||
| 182 | writeln('Power - On' ); |
||
| 183 | |||
| 184 | if (Mode.Tr1En or Mode.Tr2En) then |
||
| 185 | begin |
||
| 186 | if Mode.TrSwap then s:='Swapped' else s:='Direct'; |
||
| 187 | writeln('Trailers are - '+s); |
||
| 188 | end; |
||
| 189 | |||
| 190 | write( 'Trailer 1 - '); |
||
| 191 | if Mode.Tr1En then |
||
| 192 | begin |
||
| 193 | if Mode.Tr1T then s:='+3/+5 V' else s:='0 V(GND)'; |
||
| 194 | writeln('Enabled'); |
||
| 195 | writeln('Trailer 1 TRUE state - '+s); |
||
| 196 | end |
||
| 197 | else |
||
| 198 | writeln('Disabled'); |
||
| 199 | |||
| 200 | write( 'Trailer 2 - '); |
||
| 201 | if Mode.Tr2En then |
||
| 202 | begin |
||
| 203 | if Mode.Tr2T then s:='+3/+5 V' else s:='0 V(GND)'; |
||
| 204 | writeln('Enabled'); |
||
| 205 | writeln('Trailer 2 TRUE state - '+s); |
||
| 206 | end |
||
| 207 | else |
||
| 208 | writeln('Disabled'); |
||
| 209 | |||
| 210 | if Mode.EncoderEn then |
||
| 211 | begin |
||
| 212 | writeln( 'Encoder - Enabled'); |
||
| 213 | if Mode.EncoderInv then s:='Inverted' else s:='Direct'; |
||
| 214 | writeln( Format('Encoder Position Counter is %s', [s])); |
||
| 215 | writeln( 'Rotary Transducer and Input Syncronisation are'); |
||
| 216 | writeln( 'Disabled Because of Encoder'); |
||
| 217 | end |
||
| 218 | else |
||
| 219 | begin |
||
| 220 | writeln( 'Encoder - Disabled'); |
||
| 221 | write( 'Rotary Transducer - '); |
||
| 222 | if Mode.RotTeEn then |
||
| 223 | begin |
||
| 224 | writeln('Enabled'); |
||
| 225 | if Mode.RotTrT then s:='+3/+5 V' else s:='0 V(GND)'; |
||
| 226 | writeln('Rotary Transducer TRUE state - '+s); |
||
| 227 | if Mode.RotTrOp then s:='Stop on error' else s:='Check and ignore error'; |
||
| 228 | writeln('Rotary Transducer Operation - '+s); |
||
| 229 | if Mode.ResetRT then s:='Initiated' else s:='No, why?'; |
||
| 230 | writeln('Reset Rotary Transducer Check Positions - '+s); |
||
| 231 | end |
||
| 232 | else writeln('Disabled'); |
||
| 233 | writeln('Synchronization input mode:'); |
||
| 234 | if Mode.SyncINOp then writeln('Step motor will move one time to the destination position') |
||
| 235 | else writeln('Step motor will move multiple times by [destination position]'); |
||
| 236 | end; |
||
| 237 | |||
| 238 | write( 'Output Syncronization - '); |
||
| 239 | if Mode.SyncOUTEn then |
||
| 240 | begin |
||
| 241 | if Mode.SyncOUTR then s:='Initiated' else s:='No, why?'; |
||
| 242 | writeln('Enabled'); |
||
| 243 | writeln('Reset Output Synchronization Counter - '+s); |
||
| 244 | writeln(Format('Number of steps after which synchronization output sygnal occures - %u', [Mode.SyncCount] )); |
||
| 245 | end |
||
| 246 | else writeln('Disabled'); |
||
| 247 | |||
| 248 | writeln('Synchronization input mode:'); |
||
| 249 | if Mode.SyncINOp then |
||
| 250 | writeln('Step motor will move one time to the destination position') |
||
| 251 | else |
||
| 252 | writeln('Step motor will move multiple times by [destination position]'); |
||
| 253 | write('Synchronization Output is '); |
||
| 254 | if Mode.SyncInvert then |
||
| 255 | writeln('INVERTED') |
||
| 256 | else |
||
| 257 | writeln('NORMAL'); |
||
| 258 | end; |
||
| 259 | |||
| 260 | procedure PrintEnState(EnState:TUSMC_EncoderState;up:TUSMC_Parameters); |
||
| 261 | begin |
||
| 262 | writeln('The encoder state is:'); |
||
| 263 | writeln(Format('- Current Position in microsteps - %.2f', [EnState.ECurPos/up.EncMult] )); |
||
| 264 | writeln(Format('- Encoder Position in microsteps - %.2f', [EnState.EncoderPos/up.EncMult] )); |
||
| 265 | writeln(''); |
||
| 266 | writeln(Format('- Current Position in "Half of Encoder Step" - %d', [EnState.ECurPos] )); |
||
| 267 | writeln(Format('- Encoder Position in "Half of Encoder Step" - %d', [EnState.EncoderPos] )); |
||
| 268 | end; |
||
| 269 | |||
| 270 | // Function that prints information about device parameters to console |
||
| 271 | procedure PrintDParameters(Parameters:TUSMC_Parameters); |
||
| 272 | begin |
||
| 273 | writeln('The parameters are:' ); |
||
| 274 | writeln(Format('Full acceleration time - %.0f ms', [ Parameters.AccelT] )); |
||
| 275 | writeln(Format('Full deceleration time - %.0f ms', [Parameters.DecelT] )); |
||
| 276 | writeln(Format('Power reduction timeout - %.0f ms', [ Parameters.PTimeout] ) ); |
||
| 277 | writeln(Format('Button speedup timeout 1 - %.0f ms', [ Parameters.BTimeout1] ) ); |
||
| 278 | writeln(Format('Button speed after timeout 1 - %.2f steps/s', [ Parameters.BTO1P] ) ); |
||
| 279 | writeln(Format('Button speedup timeout 2 - %.0f ms', [ Parameters.BTimeout2] ) ); |
||
| 280 | writeln(Format('Button speed after timeout 2 - %.2f steps/s', [ Parameters.BTO2P] ) ); |
||
| 281 | writeln(Format('Button speedup timeout 3 - %.0f ms', [ Parameters.BTimeout3] ) ); |
||
| 282 | writeln(Format('Button speed after timeout 3 - %.2f steps/s', [ Parameters.BTO3P] ) ); |
||
| 283 | writeln(Format('Button speedup timeout 4 - %.0f ms', [ Parameters.BTimeout4] ) ); |
||
| 284 | writeln(Format('Button speed after timeout 4 - %.2f steps/s', [ Parameters.BTO4P] ) ); |
||
| 285 | writeln(Format('Button reset timeout - %.0f ms', [ Parameters.BTimeoutR] ) ); |
||
| 286 | writeln(Format('Button reset operation speed - %.2f steps/s', [ Parameters.MinP] ) ); |
||
| 287 | writeln(Format('Backlash operation distance - %d steps', [ Parameters.MaxLoft] ) ); |
||
| 288 | writeln(Format('Revolution distance - %d steps', [ Parameters.RTDelta] ) ); |
||
| 289 | writeln(Format('Minimal revolution distance error - %d steps', [ Parameters.RTMinError] ) ); |
||
| 290 | writeln(Format('Power off temperature - %.2f'+#248+#67, [Parameters.MaxTemp] ) ); |
||
| 291 | write('Duration of the output synchronization pulse - '); |
||
| 292 | if (Parameters.SynOUTP=0) then |
||
| 293 | writeln('minimal') |
||
| 294 | else |
||
| 295 | writeln(Format('%.1f * [Tact Period]', [Parameters.SynOUTP - 0.5])); |
||
| 296 | write('Speed of the last phase of the backlash operation - '); |
||
| 297 | if(Parameters.LoftPeriod = 0) then |
||
| 298 | writeln('normal' ) |
||
| 299 | else |
||
| 300 | writeln(Format('%.2f steps/s', [Parameters.LoftPeriod] )); |
||
| 301 | writeln(Format('<Angular Encoder Step> Equals <Angular Step Motor Step>/<%.2f>', [Parameters.EncMult])); |
||
| 302 | end; |
||
| 303 | |||
| 304 | function Menu: integer; |
||
| 305 | var |
||
| 306 | Speed: single; |
||
| 307 | DestPos:integer; |
||
| 308 | s:string; |
||
| 309 | State: TUSMC_State; |
||
| 310 | StPrms: TUSMC_StartParameters; |
||
| 311 | Prms: TUSMC_Parameters; |
||
| 312 | Mode: TUSMC_Mode; |
||
| 313 | EnState: TUSMC_EncoderState; |
||
| 314 | newCurPos: integer; |
||
| 315 | begin |
||
| 316 | Speed:=2000; |
||
| 317 | |||
| 318 | writeln('Menu:'); |
||
| 319 | writeln('1 - Get device state'); |
||
| 320 | writeln('2 - START'); |
||
| 321 | writeln('3 - STOP'); |
||
| 322 | writeln('4 - Set Parameters (can be changed only in curret example code)'); |
||
| 323 | writeln('5 - Set Mode (can be changed only in curret example code)'); |
||
| 324 | writeln('6 - Set Current Position (can be changed only in curret example code)'); |
||
| 325 | |||
| 326 | writeln('7 - Turn Off and Save Current Position to Flash'); |
||
| 327 | writeln('r - Revert Start Position to 0'); |
||
| 328 | writeln('8 - Get Encoder State'); |
||
| 329 | writeln(''); |
||
| 330 | if SMPower then s:='Off' |
||
| 331 | else s:='On'; |
||
| 332 | writeln(Format('p - Turn %s Power',[s])); |
||
| 333 | writeln(''); |
||
| 334 | writeln('9 - Select other device'); |
||
| 335 | writeln('0 - Exit'); |
||
| 336 | writeln('Choose:'); |
||
| 337 | |||
| 338 | readln(s); |
||
| 339 | if s='' then s:=' '; |
||
| 340 | case s[1] of |
||
| 341 | '1': |
||
| 342 | begin |
||
| 343 | if StandaClass.USMC_GetState(Dev, State)>0 then |
||
| 344 | begin |
||
| 345 | PrintError(); |
||
| 346 | result:=0; |
||
| 347 | exit; |
||
| 348 | end; |
||
| 349 | Cls; |
||
| 350 | PrintDState(State); |
||
| 351 | writeln(''); |
||
| 352 | end; |
||
| 353 | '2': |
||
| 354 | begin |
||
| 355 | if StandaClass.USMC_GetStartParameters(Dev, StPrms)>0 then |
||
| 356 | begin |
||
| 357 | PrintError(); |
||
| 358 | result:=0; |
||
| 359 | exit; |
||
| 360 | end; |
||
| 361 | Cls; |
||
| 362 | ScanDStartParameters(DestPos, Speed, StPrms); |
||
| 363 | if StandaClass.USMC_Start(Dev, DestPos, Speed, StPrms) >0 then |
||
| 364 | begin |
||
| 365 | PrintError(); |
||
| 366 | result:=0; |
||
| 367 | exit; |
||
| 368 | end; |
||
| 369 | Cls; |
||
| 370 | PrintDStartParameters(DestPos, Speed, StPrms); |
||
| 371 | writeln(''); |
||
| 372 | end; |
||
| 373 | '3': |
||
| 374 | begin |
||
| 375 | if StandaClass.USMC_Stop(Dev)>0 then |
||
| 376 | begin |
||
| 377 | PrintError(); |
||
| 378 | result:=0; |
||
| 379 | exit; |
||
| 380 | end; |
||
| 381 | Cls; |
||
| 382 | end; |
||
| 383 | '4': |
||
| 384 | begin |
||
| 385 | if StandaClass.USMC_GetParameters(Dev, Prms)>0 then |
||
| 386 | begin |
||
| 387 | PrintError(); |
||
| 388 | result:=0; |
||
| 389 | exit; |
||
| 390 | end; |
||
| 391 | // Set anything you want here |
||
| 392 | Prms.MaxTemp:= 70.0; |
||
| 393 | //Prms.LoftPeriod:= 0.0; |
||
| 394 | Prms.BTimeout1:= 500.0; |
||
| 395 | Prms.BTimeout2:= 500.0; |
||
| 396 | Prms.BTimeout3:= 500.0; |
||
| 397 | Prms.BTimeout4:= 500.0; |
||
| 398 | Prms.BTO1P:= 200.0; |
||
| 399 | Prms.BTO2P:= 300.0; |
||
| 400 | Prms.BTO3P:= 400.0; |
||
| 401 | Prms.BTO4P:= 500.0; |
||
| 402 | Prms.AccelT:= 200.0; |
||
| 403 | Prms.DecelT:= 200.0; |
||
| 404 | Prms.BTimeoutR:= 500.0; |
||
| 405 | Prms.LoftPeriod:= 500.0; |
||
| 406 | Prms.RTDelta:= 200; |
||
| 407 | Prms.RTMinError:= 15; |
||
| 408 | Prms.EncMult:= 2.5; |
||
| 409 | Prms.MaxLoft:= 32; |
||
| 410 | Prms.PTimeout:= 100.0; |
||
| 411 | Prms.SynOUTP:= 1; |
||
| 412 | |||
| 413 | if StandaClass.USMC_SetParameters( Dev, Prms )>0 then |
||
| 414 | begin |
||
| 415 | PrintError(); |
||
| 416 | result:=0; |
||
| 417 | exit; |
||
| 418 | end; |
||
| 419 | |||
| 420 | if StandaClass.USMC_SaveParametersToFlash( Dev )>0 then |
||
| 421 | begin |
||
| 422 | PrintError(); |
||
| 423 | result:=0; |
||
| 424 | exit; |
||
| 425 | end; |
||
| 426 | |||
| 427 | Cls; |
||
| 428 | PrintDParameters( Prms ); |
||
| 429 | writeln(''); |
||
| 430 | writeln('These Parameters are Saved to Flash'); |
||
| 431 | writeln('Press Enter to exit'); |
||
| 432 | readln(s); |
||
| 433 | Cls; |
||
| 434 | end; |
||
| 435 | '5': |
||
| 436 | begin |
||
| 437 | if StandaClass.USMC_GetMode(Dev, Mode)>0 then |
||
| 438 | begin |
||
| 439 | PrintError; |
||
| 440 | result:=0; |
||
| 441 | exit; |
||
| 442 | end; |
||
| 443 | |||
| 444 | // Set anything you want here |
||
| 445 | Mode.SyncInvert:= not Mode.SyncInvert; |
||
| 446 | Mode.EncoderEn:= TRUE; |
||
| 447 | Mode.RotTrOp:= FALSE; |
||
| 448 | Mode.ResetRT:= TRUE; |
||
| 449 | // Set anything you want here |
||
| 450 | |||
| 451 | if StandaClass.USMC_SetMode(Dev, Mode)>0 then |
||
| 452 | begin |
||
| 453 | PrintError; |
||
| 454 | result:=0; |
||
| 455 | exit; |
||
| 456 | end; |
||
| 457 | Cls; |
||
| 458 | PrintDMode(Mode); |
||
| 459 | writeln(''); |
||
| 460 | writeln('Press Enter to exit'); |
||
| 461 | readln(s); |
||
| 462 | Cls; |
||
| 463 | end; |
||
| 464 | //Set_Current_Position |
||
| 465 | '6': |
||
| 466 | begin |
||
| 467 | newCurPos:= 1000; |
||
| 468 | if StandaClass.USMC_SetCurrentPosition(Dev, newCurPos)>0 then |
||
| 469 | begin |
||
| 470 | PrintError; |
||
| 471 | result:=0; |
||
| 472 | exit; |
||
| 473 | end; |
||
| 474 | Cls; |
||
| 475 | writeln(Format('SetCurrentPosition executed with argument %d',[newCurPos])); |
||
| 476 | writeln('Press Enter to exit'); |
||
| 477 | readln(s); |
||
| 478 | Cls; |
||
| 479 | end; |
||
| 480 | '7': |
||
| 481 | begin |
||
| 482 | //Turn_Off_and_Save_Current_Position_to_Flash |
||
| 483 | // Initialize structures (in case this function runs first) |
||
| 484 | if StandaClass.USMC_GetParameters(Dev, Prms)>0 then |
||
| 485 | begin |
||
| 486 | PrintError; |
||
| 487 | result:=0; |
||
| 488 | exit; |
||
| 489 | end; |
||
| 490 | if StandaClass.USMC_GetMode(Dev, Mode)>0 then |
||
| 491 | begin |
||
| 492 | PrintError; |
||
| 493 | result:=0; |
||
| 494 | exit; |
||
| 495 | end; |
||
| 496 | // Go to Full Step (automaticaly), then Turn Off |
||
| 497 | Mode.ResetD:= TRUE; |
||
| 498 | if StandaClass.USMC_SetMode(Dev, Mode)>0 then |
||
| 499 | begin |
||
| 500 | PrintError; |
||
| 501 | result:=0; |
||
| 502 | exit; |
||
| 503 | end; |
||
| 504 | // Wait until Previous Comand is Done |
||
| 505 | repeat |
||
| 506 | Sleep(50); |
||
| 507 | if StandaClass.USMC_GetState(Dev, State)>0 then |
||
| 508 | begin |
||
| 509 | PrintError; |
||
| 510 | result:=0; |
||
| 511 | exit; |
||
| 512 | end; |
||
| 513 | until State.Power<>TRUE; |
||
| 514 | // Remember CurPos in Parameters Only While State.Power - FALSE |
||
| 515 | Prms.StartPos:= State.CurPos; |
||
| 516 | if StandaClass.USMC_SetParameters( Dev, Prms )>0 then |
||
| 517 | begin |
||
| 518 | PrintError; |
||
| 519 | result:=0; |
||
| 520 | exit; |
||
| 521 | end; |
||
| 522 | // Then of Course You Need to SaveToFlash |
||
| 523 | if StandaClass.USMC_SaveParametersToFlash( Dev )>0 then |
||
| 524 | begin |
||
| 525 | PrintError; |
||
| 526 | result:=0; |
||
| 527 | exit; |
||
| 528 | end; |
||
| 529 | // Now You Can Unplug ME |
||
| 530 | Cls; |
||
| 531 | writeln(Format('The Position "%d" is Saved to Flash',[Prms.StartPos])); |
||
| 532 | writeln('When Controller is Powered Up Next Time'); |
||
| 533 | writeln('It Will Start From This Position'); |
||
| 534 | writeln('Press Enter to exit'); |
||
| 535 | readln(s); |
||
| 536 | Cls; |
||
| 537 | end; |
||
| 538 | // Initialize structures (in case this function runs first) |
||
| 539 | 'r': |
||
| 540 | begin |
||
| 541 | if StandaClass.USMC_GetParameters(Dev, Prms)>0 then |
||
| 542 | begin |
||
| 543 | PrintError; |
||
| 544 | result:=0; |
||
| 545 | exit; |
||
| 546 | end; |
||
| 547 | Prms.StartPos:= 0; |
||
| 548 | if StandaClass.USMC_SetParameters( Dev, Prms )>0 then |
||
| 549 | begin |
||
| 550 | PrintError; |
||
| 551 | result:=0; |
||
| 552 | exit; |
||
| 553 | end; |
||
| 554 | // Then of Course You Need to SaveToFlash |
||
| 555 | if StandaClass.USMC_SaveParametersToFlash( Dev )>0 then |
||
| 556 | begin |
||
| 557 | PrintError; |
||
| 558 | result:=0; |
||
| 559 | exit; |
||
| 560 | end; |
||
| 561 | Cls; |
||
| 562 | writeln('Start Position is Reset to 0'); |
||
| 563 | writeln('Press Enter to exit'); |
||
| 564 | readln(s); |
||
| 565 | Cls; |
||
| 566 | end; |
||
| 567 | '8': |
||
| 568 | begin |
||
| 569 | if StandaClass.USMC_GetEncoderState(Dev, EnState)>0 then |
||
| 570 | begin |
||
| 571 | PrintError; |
||
| 572 | result:=0; |
||
| 573 | exit; |
||
| 574 | end; |
||
| 575 | if StandaClass.USMC_GetParameters(Dev, Prms)>0 then |
||
| 576 | begin |
||
| 577 | PrintError; |
||
| 578 | result:=0; |
||
| 579 | exit; |
||
| 580 | end; |
||
| 581 | Cls; |
||
| 582 | PrintEnState(EnState, Prms); |
||
| 583 | writeln(''); |
||
| 584 | writeln('Press Enter to exit'); |
||
| 585 | readln(s); |
||
| 586 | Cls; |
||
| 587 | end; |
||
| 588 | 'p','P': |
||
| 589 | begin |
||
| 590 | if StandaClass.USMC_GetMode(Dev, Mode)>0 then |
||
| 591 | begin |
||
| 592 | PrintError; |
||
| 593 | result:=0; |
||
| 594 | exit; |
||
| 595 | end; |
||
| 596 | |||
| 597 | SMPower:= not SMPower; |
||
| 598 | Mode.ResetD:= not SMPower; |
||
| 599 | |||
| 600 | if StandaClass.USMC_SetMode(Dev, Mode)>0 then |
||
| 601 | begin |
||
| 602 | PrintError; |
||
| 603 | result:=0; |
||
| 604 | exit; |
||
| 605 | end; |
||
| 606 | Cls; |
||
| 607 | if Mode.ResetD then writeln('Now, Power is Off') |
||
| 608 | else writeln('Now, Power is On'); |
||
| 609 | writeln(''); |
||
| 610 | writeln('Press Enter to exit'); |
||
| 611 | readln(s); |
||
| 612 | Cls; |
||
| 613 | end; |
||
| 614 | '9': |
||
| 615 | begin |
||
| 616 | result:=1; |
||
| 617 | exit; |
||
| 618 | end; |
||
| 619 | '0': |
||
| 620 | begin |
||
| 621 | writeln(''); |
||
| 622 | result:=0; |
||
| 623 | exit; |
||
| 624 | end; |
||
| 625 | else |
||
| 626 | Cls; |
||
| 627 | end; |
||
| 628 | result:=2; |
||
| 629 | end; |
||
| 630 | |||
| 631 | function SelectMenu: integer; |
||
| 632 | var |
||
| 633 | ret: integer; |
||
| 634 | s: string; |
||
| 635 | begin |
||
| 636 | Dev:= High(Longword); |
||
| 637 | while Dev>DVS.NOD do |
||
| 638 | begin |
||
| 639 | Cls; |
||
| 640 | PrintDevices( DVS ); |
||
| 641 | writeln(''); |
||
| 642 | writeln(#9+'0'+#9+'Exit'); |
||
| 643 | writeln(#9+'x'+#9+'ReInitialize'); |
||
| 644 | writeln(#9+'xx'+#9+'Close Driver Window and Exit'); |
||
| 645 | writeln(''); |
||
| 646 | write('Select:'); |
||
| 647 | readln(s); |
||
| 648 | if s='x' then |
||
| 649 | begin |
||
| 650 | //// Perform "Refresh" of Driver |
||
| 651 | if StandaClass.USMC_Init( DVS )>0 then |
||
| 652 | begin |
||
| 653 | PrintError(); |
||
| 654 | result:=0; |
||
| 655 | end; |
||
| 656 | end |
||
| 657 | else if s='xx' then |
||
| 658 | begin |
||
| 659 | //// Close the MicroSMC.exe process |
||
| 660 | if StandaClass.USMC_Close()>0 then |
||
| 661 | begin |
||
| 662 | PrintError(); |
||
| 663 | result:=0; |
||
| 664 | end; |
||
| 665 | result:=0; |
||
| 666 | exit; |
||
| 667 | end; |
||
| 668 | Dev:=StrToIntDef(s,High(Longword)); |
||
| 669 | if Dev=0 then |
||
| 670 | begin |
||
| 671 | result:=0; |
||
| 672 | exit; |
||
| 673 | end; |
||
| 674 | end; |
||
| 675 | |||
| 676 | dec(Dev); |
||
| 677 | Cls; |
||
| 678 | repeat |
||
| 679 | ret:=Menu; |
||
| 680 | until ret<>2; |
||
| 681 | result:=ret; |
||
| 682 | end; |
||
| 683 | |||
| 684 | procedure D_Exit(s:string); |
||
| 685 | var |
||
| 686 | ss:string; |
||
| 687 | begin |
||
| 688 | writeln(''); |
||
| 689 | writeln(s); |
||
| 690 | writeln('Press Enter to exit'); |
||
| 691 | readln(ss); |
||
| 692 | end; |
||
| 693 | |||
| 694 | begin |
||
| 695 | Cls; |
||
| 696 | StandaClass:=TStandaClass.Create; |
||
| 697 | if StandaClass = nil then |
||
| 698 | begin |
||
| 699 | D_Exit('Error: Can`t create object with DLL function'); |
||
| 700 | exit; |
||
| 701 | end; |
||
| 702 | if not StandaClass.bDllLoadOK then |
||
| 703 | begin |
||
| 704 | StandaClass.Destroy; |
||
| 705 | D_Exit('Error: Can`t load DLL'); |
||
| 706 | exit; |
||
| 707 | end; |
||
| 708 | if(StandaClass.USMC_Init( DVS ) > 0 ) then |
||
| 709 | begin |
||
| 710 | PrintError(); |
||
| 711 | StandaClass.Destroy; |
||
| 712 | D_Exit(''); |
||
| 713 | exit; |
||
| 714 | end; |
||
| 715 | while(SelectMenu>0) do ; |
||
| 716 | {***************************** Memory free ***************} |
||
| 717 | // when DVS.Serial is Pointer we comment this string |
||
| 718 | // We add this string when DVS.Serial is array of PChar |
||
| 719 | // Finalize(DVS); |
||
| 720 | {***************************** Memory free ***************} |
||
| 721 | StandaClass.Destroy; |
||
| 722 | D_Exit(''); |
||
| 723 | end. |