6.1.1. Working with controller in Visual Studio¶
Download VisualStudio example from the Software page.
Testapp can be built using testapp.sln. Library must be compiled with MS Visual C++ too. Make sure that Microsoft Visual C++ Redistributable Package 2013 is installed.
Open solution examples/testapp/testapp.sln, build and run from the IDE.
Extract the archive and run “testapp” program.
The command prompt opens. You will see a message: “Hello! I`m a stupid test program!”
The program reports the version of the library used, as well as its bit depth. Also “testapp” program indicates which port it holds.
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|
|upwr||int Upwr||Power supply voltage, tens of mV|
|ipwr||int Ipwr||Engine current|
|flags||unsigned int Flags||Status flags|
|mvsts||unsigned int MvCmdSts||Move command state|
Function result_t XIMC_API get_device_information (device_t id, device_information_t *device information) - Return device information
Function result_t XIMC_API get_engine_settings (device_t id, engine_settings_t *engine settings) - Read engine settings
engine_settings_calb_t Struct Reference - result_t XIMC_API set_engine_settings_calb (device_t id, const engine_settings_calb_t *engine_settings - calb, const calibration_t *calibration)
After, the testapp program executes the command “command_left” for 2 seconds. The “command_left” command is successfully executed, the “command_stop” command is called.
At the end of the program, the command “close_device” must be called.
The “testappeasy” program isn`t so much different from the “testapp” program. Open solution examples/testappeasy/testappeasy.sln, build and run from the IDE.
The command prompt opens. You will see a message: “This is a ximc test program.”
The program reports the version of the library used.
Using the “open_device” command, “testappeasy” program opens the device in exclusive access mode.
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, the testappeasy program executes the command “command_left” for 3 seconds. The “command_left” 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 “testappeasy” program reads calibrated device status from a device.
At the end, a “command_stop” command is sent to the device. The “close_device” - closes the specified device.