Chapter
6
Reference Manual
Ruler E
Examples
6
Examples
This section shows two programs that are examples on how the APIs could be used retreiv-
ing data from a Ruler. These programs are also delivered on the CD in complied versions
ready for test.
6.1
ruler_ex
This example shows how to write a simple application using the Ruler C++ API.
The program goes through the following steps:
$
Create a Ruler object and sets the object’s properties using
set()
methods
$
Connect to the Ruler by calling the
init()
method
$
Allocate the arrays needed for retrieving the profiles sent by the Ruler
$
Start the Ruler
$
Retrieve the profiles using the
requestDataSeparate()
method, one buffer at a
time, and print out some statistics about the measurement speed.
The program will run until any key is pressed on the keyboard.
When compiling this program, make sure that you link with the
icon2.lib
library.
#include
<string>
/// For _kbhit()
#include
<conio.h>
/// For GetTickCount()
#include
"windows.h"
/// For Ruler C++ API
#include
"ruler_api.h"
using
namespace
std;
int
_tmain(
int
argc, _TCHAR* argv[])
{
cout << "Ruler E example program. " << endl;
const
char
*ip = "192.168.0.43";
Ruler::Ruler *ruler = Ruler::Ruler::createRuler("MyRuler");
ruler->setCameraAddress(ip);
ruler->setRulerMode("Measurement");
ruler->setProfilesPerBuffer(100);
ruler->setTimeout(10);
ruler->setParameterFile("MyParameterFile_RulerE.PRM");
/// Connect to the ruler and transfer all settings.
int
ret = ruler->init();
if
(ret != 0)
{
cout << "Ruler init() failed: " << ret << endl;
delete
ruler;
exit(1);
}
48
SICK IVP • Industrial Sensors • www.sickivp.com • All rights reserved