6.1.1. Working with controller in Visual Studio

Download VisualStudio examples from the Software page.

Development kit also contains precompiled examples: testapp and testappeasy as 32 and 64-bit applications for Windows and 64-bit application for OSX, test_CSharp, test_VBNET - 32-bit only. Programming guide can be found at this link.

6.1.1.1. Visual C++

Examples writed on C language is located at “examples/test_C” directory.

The compiled version of the library contains already compiled examples, you can simply run them. Extract the archive and run, for example, “testapp” program.

Also examples can be built using <example_name>.sln. Library must be compiled with MS Visual C++ too, mingw-library isn’t supported.
Make sure that Microsoft Visual C++ Redistributable Package 2013 is installed.
For example, open solution examples/testapp/testapp.sln, build and run from the IDE.

6.1.1.1.1. What does the testapp program do?

../../../_images/testapp.png

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.

Important

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

6.1.1.1.2. What does the testappeasy program do?

The “testappeasy” program isn`t so much different from the “testapp” program. Open solution examples/testappeasy/testappeasy.sln, build and run from the IDE.

../../../_images/testappeasy.png

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.

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, 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.

Note

C-profiles. C-profiles are header files distributed with the libximc library. They enable one to set all controller settings for any of the supported stages with a single function call in a C/C++ program. You may see how to use C-profiles in “testcprofile” example directory.

6.1.1.2. .NET (C# and Visual Basic)

C# test projects is located at “examples/test_CSharp”, VB.NET - “examples/test_VBNET”. Wrapper assembly for libximc.dll is wrappers/csharp/ximcnet.dll. It is provided with two different architectures and depends on .NET 2.0.

Test .NET applications for Visual Studio 2013 is located at testcs (for C#) and testvbnet (for VB.NET) respectively. Open solutions and build.