How to build and run the first example program
IMAGO delivers the VisionBox with a pre-installed Windows OS including the IMAGO SDK and the required drivers. The SDK provides the DLLs, import libraries and header files for building the example program.
The example program FirstTest demonstrates the use of the library. The source code is available in the following SDK directory:
<SDK installation folder>\examples\C++\FirstTest
Note that the SDK installation folder is also stored in the Windows system environment variable IMAGO_AGEX_BASEPATH
.
The example folder contains a solution file for Microsoft Visual Studio: FirstTest.sln
The Visual Studio project already contains the correct compiler options.
Using other compilers is also possible. The following compiler and linker settings are required to build the program:
\include
\lib\VIB_Interface.lib
\lib\VIB_Interface_amd64.lib
Depending on the hardware, the console output of the program should look similar to this:
This document requires the user to have successfully walked through the "Getting Started Guide" for logging into the command line of the device. A basic understanding of using the Linux command line is also required.
IMAGO delivers the VisionBox, VisionCam and VisionSensor with a pre-installed Debian Linux root filesystem including development tools like the GNU GCC compiler and the Make utility. Additionally, the IMAGO SDK package provides the required kernel modules and libraries. In order to build and run the example program, there is no need to install or configure anything else.
The example program FirstTest demonstrates the use of the library. It can be executed on all supported platforms. The source code is located at the following SDK directory:
/opt/ImagoTechnologies/SDK/examples/FirstTest_Linux
The example directory contains a Makefile which uses the required library and compiler settings for building the program:
-I/opt/ImagoTechnologies/SDK/include
-L/opt/ImagoTechnologies/SDK/lib/
-lVIBInterface
In order to build the program, login to the device and copy the source code to your home directory. Then, build the project by executing 'make':
After successful build, the program can be started:
Depending on the hardware, the console output should look similar to this:
The FirstTest example source code is the same for the Linux and Windows SDK: FirstTest.cpp
All library functions return a Boolean result which indicates the success of the function call. To keep the example clear, we add a little helper function to test the result of every library call. In case of an error, the helper function reads out the error message of the library and throws an exception:
Now, we can put all library function calls in a try / catch block and use the helper function as follows:
The first step in the main()
function is to create a VIB::VIBSystem factory object for the mainboard hardware entity. This allows us to acquire and print version information about the libraries and the firmware:
The example opens two devices using different methods:
The VIB::Service device is opened by using the factory function VIBSystem::OpenDevice(), see page Device Factory for a description:
Depending on the device class, the overloaded OpenDevice() function has an Index
parameter which selects the component on the hardware entity if multiple of the same type are present.
The VIB::DigitalOutput device is opened by using the device object's member function Open(), see page Open devices using the Open() method for a description:
This method doesn't require a factory for opening the device. The Index
parameter specifies the component for the given device type across all hardware entities. Depending on the actual hardware configuration of the system, the DigitalOutput device may not be available and the function returns an error.
After a device is opened, we can start using the device.
Each device class has its own set of member functions. Refer to the device class documentation for a detailed description. See also Devices for a list of supported devices.
All device objects have to be closed before they can be used again.
In the example, the DigitalOutput device automatically gets closed when the object is destructed, but it could also be closed manually by using the function Close().
The Service device is closed by using the factory again. Then, the factory itself is also closed: