VisionBox Interface Library  1.7.13.0 (2025-08-27)
Loading...
Searching...
No Matches
First Test example source code

Linux SDK location: /opt/ImagoTechnologies/SDK/examples/FirstTest_Linux/src/FirstTest.cpp
Windows SDK location: <SDK installation folder>\examples\C++\FirstTest\FirstTest.cpp

1#ifdef _WIN32
2 #include <windows.h> //for Sleep()
3 #define usleep(us) Sleep(us / 1000)
4#else
5 #include <unistd.h> //for usleep()
6#endif
7#include <stdio.h> //for getchar
8#include <stdexcept> //for std::runtime_error
9#include <vector> //for std::vector
10
11#include "VIB_Interface.h" //the VIB Interface header file
12
13
14// Helper function for error handling:
15// Checks the result of a library function, reads the error message and throws
16// an exception.
18void TestRes(bool result)
19{
20 char ErrText[512];
21
22 // was the function call successful?
23 if (result)
24 return;
25
26 // read error string
27 VIB::VIBSystem::GetLastErrorString(*ErrText, sizeof(ErrText));
28
29 throw std::runtime_error(ErrText);
30}
32
33
34int main()
35{
37 VIB::VIBSystem *pVIBSystem = NULL;
38 VIB::Service *pService = NULL;
39
40 try
41 {
42 // open the factory for the mainboard
43 TestRes(VIB::VIBSystem::CreateInstance(&pVIBSystem));
44 // -> is the same as:
45 // VIB::VIBSystem::CreateInstance(&pVIBSystem, VIB::SYST_BASEBOARD, 0);
46
47 // read out version string
48 std::vector<char>pstText(4096);
49 TestRes(pVIBSystem->GetVersionString(&pstText[0], 4096));
50 printf("Version numbers ==>\n%s\n", &pstText[0]);
52
53
55 // open the Service device by using the factory
56 TestRes(pVIBSystem->OpenDevice(pService));
58
59 // read and print the serial number
60 char serialnumber[32];
61 TestRes(pService->GetSerialNumber(serialnumber));
62 printf("\nSerial number: '%s'\n", serialnumber);
63
64
66 // === try to open the first DigitalOutput device ===
67 VIB::DigitalOutput digitalOutput;
68 if (digitalOutput.Open(0))
69 {
70 printf("\nFound Digital Output device\n");
72
74 printf(" Setting output signals...\n");
75
76 // turn all outputs on (up to 16)
77 TestRes(digitalOutput.Set(0xffff));
78
79 // turn output signals off one after another
80 unsigned int outputSignals;
81 TestRes(digitalOutput.GetNumberOfOutputs(outputSignals));
82 for (unsigned int signal = 0; signal < outputSignals; signal++)
83 {
84 usleep(100*1000);
85 TestRes(digitalOutput.SetBit(signal, false));
86 }
88 }
89
91 // the device 'digitalOutput' is automatically closed by the destructor
92 }
94 catch (std::runtime_error &err)
95 {
96 printf("\n==============================================\n");
97 printf("Error:\n %s\n", err.what());
98 printf("\n==============================================\n");
99 }
100 catch (...)
101 {
102 printf("\n==============================================\n");
103 printf("Error: ???\n");
104 printf("\n==============================================\n");
105 }
106
107
109 if (pVIBSystem != NULL)
110 {
111 printf("\nClosing devices...\n");
112
113 if (pService != NULL)
114 pVIBSystem->CloseDevice(pService);
115
117 }
119
120 printf("\nPress ENTER to exit.\n");
121 getchar();
122
123 return 0;
124}
Header file for this library.
This class controls a group of digital output signals.
Definition VIB_Interface.h:473
bool Set(unsigned int Val)
Sets the state of the digital output signals.
Definition DigitalOutput.cpp:122
bool GetNumberOfOutputs(unsigned int &NumberOfOutputs)
Returns number of output channels.
Definition DigitalOutput.cpp:93
bool SetBit(unsigned int BitIndex, bool OnOff)
Sets the state of the specified digital output.
Definition DigitalOutput.cpp:135
This class contains functions associated with the hardware component (serial number,...
Definition VIB_Interface.h:583
bool GetSerialNumber(char pSerialnumber[32])
Returns the serial number for the hardware component.
Definition Service.cpp:525
The factory for devices.
Definition VIB_Interface.h:223
bool OpenDevice(eDeviceType Type, int Index, iDevice **ppNewDevice)
Opens a device and returns a new device object.
Definition VIBSystem.cpp:455
bool GetVersionString(char *pText, unsigned int MaxStringSize)
Returns a string with version data from all components. (DLL, driver, FPGA, ...)
Definition VIBSystem.cpp:937
static bool DeleteInstance(VIBSystem *pObj)
Releases the device object.
Definition VIBSystem.cpp:199
bool CloseDevice(iDevice *pDevice)
Closes a device.
Definition VIBSystem.cpp:856
static bool CreateInstance(VIBSystem **ppVIBSystem)
Creates a factory instance for the mainboard.
Definition VIBSystem.cpp:105
static void GetLastErrorString(char &pText, unsigned int MaxStringSize)
Returns the last error message.
Definition VIBSystem.cpp:233
bool Open(unsigned int Index=0)
Opens a device.
Definition iDevice.cpp:109