Chapter
6
Reference Manual
Ruler E
Examples
if
(ret != 0)
{
cout << "Ruler close() failed: " << ret << endl;
}
delete
ruler;
return
0;
}
6.2
RulerNetConsoleExample
This example shows how to write a simple application using VB.Net and the RulerNet API.
The program goes through the following steps:
$
Create a Ruler object and sets the object’s properties
$
Connect to the Ruler by calling the
InitRuler()
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 in an infinite loop.
' Import the Ruler namespace
Imports
Ruler.RulerNet
Module
Module1
Sub
Main()
' Create a new Ruler and give it a name
Dim
ruler
As
New
Ruler.RulerNet("MyRuler")
Dim
res
As
ErrorCodes
Dim
points, profiles
As
Integer
' Set the timeout for requesting data to 10 milliseconds.
ruler.Timeout = 10
' Set the IP address of the Ruler unit we want to connect to.
ruler.CameraAddress = "192.168.0.43"
' Each buffer received from the Ruler will contain 10 profiles.
ruler.ProfilesPerBuffer = 10
' Tell the ruler to work in measurement mode.
ruler.RulerMode = "Measurement"
' Initialize the Ruler unit with the above settings.
res = ruler.InitRuler()
If
res <> ErrorCodes.E_ALL_OK
Then
Console.WriteLine("Error connecting to Ruler: " & res.ToString())
End
If
' Get the array sizes.
points = ruler.ProfileWidth
profiles = ruler.ProfilesPerBuffer
' Create the arrays.
Dim
x(points * profiles - 1)
As
Single
Dim
range(points * profiles - 1)
As
Single
Dim
intensity(points * profiles - 1)
As
Byte
Dim
scatter(points * profiles - 1)
As
Byte
Dim
id(profiles - 1)
As
Integer
Dim
status(profiles - 1)
As
Integer
Dim
mark(profiles - 1)
As
Integer
50
SICK IVP • Industrial Sensors • www.sickivp.com • All rights reserved