6.1.2. Working with controller in Delphi

Download Delphi example from the Software page.

Note

Wrapper for libximc.dll is a unit wrappers/delphi/ximc.pas Console test application for is it located at “testdelphi”. Tested with Delphi 6 and only 32-bit version. Just compile, place DLL near the executable and run the program.

Warning

To work this example copy files ximc.pas, libximc.dll, xiwrapper.dll, bindy.dll from ximc folder next to “testdelphi.dpr” and run “testdelphi.dpr” with your Delphi IDE.

To run compiled example without IDE (through the command line), copy all files (libximc.dll, bindy.dll … etc) in “compiled-win32” directory and run “testdelphi.exe”

Open solution examples/testdelphi/testdelphi.dpr, build and run from the IDE.

Extract the archive and run “testdelphi.exe” program.

../../../_images/testdelphi.png

The command prompt opens. You will see a message: “Hello”

The demo program “testdelphi” uses the command “result_t XIMC_API get_status (device_t id, status_t ,status)” to output the current state of the device to the command prompt. Also “testdelphi” program indicates which port it holds.

Using the “open_device” command, “testdelphi” program opens the device in exclusive access mode.

Warning

Libximc library opens the controller in exclusive access mode. Any controller opened with libximc (XiLab also uses this library) needs to be closed before it may be used by another process.

After opening the device, the program reads the data fields from the “status_t” structure reference.

rpm int CurSpeed Motor shaft speed
pos float CurPosition Current position
flags unsigned int Flags Status flags

Function result_t XIMC_API get_engine_settings (device_t id, engine_settings_t *engine settings) Read engine settings

After, the “testdelphi” program executes the command “command_right”. The “command_right” command is successfully executed, the “command_stop” command is called.

The comand “calibration.A = 0.1;” - Setting calibration constant to 0.1 (one controller step equals this many units)

The command “calibration.MicrostepMode = engine_settings.MicrostepMode;” - To set microstep mode to convert microsteps to calibrated units correctly.

After the “testdelphi” program reads calibrated device status from a device.

Warning

At the end of the program, the command “close_device” must be called.