Reference Manual
Chapter
6
Ruler E
Examples
/// Allocate memory buffer to receive profiles in:
int
profiles, width;
ret = ruler->getProfilesPerBuffer(&profiles);
if
(ret != 0)
{
cout << "Ruler getProfilesPerBuffer() failed: " << ret << endl;
delete
ruler;
exit(1);
}
ret = ruler->getProfileWidth(&width);
if
(ret != 0)
{
cout << "Ruler getProfilesPerBuffer() failed: " << ret << endl;
delete
ruler;
exit(1);
}
int
*status =
new
int
[profiles];
int
*mark =
new
int
[profiles];
int
*id =
new
int
[profiles];
float
*x =
new
float
[profiles*width];
float
*range =
new
float
[profiles*width];
unsigned
char
*intensity =
new
unsigned
char
[profiles*width];
unsigned
char
*scatter =
new
unsigned
char
[profiles*width];
/// Start acquisition of profiles.
ret = ruler->start();
if
(ret != 0)
{
cout << "Ruler start() failed: " << ret << endl;
delete
ruler;
exit(1);
}
int
count = 0;
while
(!_kbhit())
{
ret = ruler->requestDataSeparate(profiles, profiles*width,
id, status, mark,
x, range, intensity, scatter);
if
((ret != Ruler::Ruler::ErrorCodes::E_ALL_OK)
&& (ret != Ruler::Ruler::ErrorCodes::E_TIMEOUT))
{
cout << "Ruler requestDataSeparate() failed: " << ret << endl;
delete
ruler;
exit(1);
}
if
(ret == Ruler::Ruler::ErrorCodes::E_ALL_OK)
{
// Here we can do image processing of the data.
/// Every 10 seconds we output statistics.
if
((GetTickCount() % 10000) == 0)
{
cout << ":" << count*profiles/10 << "Hz (total)" << endl;
count = 0;
}
if
(ret == Ruler::Ruler::ErrorCodes::E_ALL_OK)
count++;
}
}
ruler->stop();
if
(ret != 0)
{
cout << "Ruler stop() failed: " << ret << endl;
delete
ruler;
exit(1);
}
ruler->close();
SICK IVP • Industrial Sensors • www.sickivp.com • All rights reserved
49