
Then add in the same manner the
yapi.dll
DLL, located in the
Sources/dll
directory
4
. Then,
from the
Solution Explorer
window, right click on the DLL, select
Properties
and in the
Properties
panel, set the
Copy to output folder
to
always
. You are now ready to use your Yoctopuce modules
from Visual Studio.
In order to keep them simple, all the examples provided in this documentation are console
applications. Naturally, the libraries function in a strictly identical manner if you integrate them in an
application with a graphical interface.
13.3. Control of the RangeFinder function
A few lines of code are enough to use a Yocto-RangeFinder. Here is the skeleton of a C# code
snipplet to use the RangeFinder function.
[
...
]
string
errmsg =
""
;
YRangeFinder rangefinder;
// Get access to your device, connected locally on USB for instance
YAPI.
RegisterHub
(
"usb"
, errmsg
)
;
rangefinder = YRangeFinder.
FindRangeFinder
(
"YRNGFND1-123456.rangeFinder"
)
;
// Hot-plug is easy: just check that the device is online
if
(
rangefinder.
isOnline
())
{
// Use rangefinder.get_currentValue(); ...
}
Let's look at these lines in more details.
YAPI.RegisterHub
The
YAPI.RegisterHub
function initializes the Yoctopuce API and indicates where the modules
should be looked for. When used with the parameter
"usb"
, it will use the modules locally
connected to the computer running the library. If the initialization does not succeed, this function
returns a value different from
YAPI.SUCCESS
and
errmsg
contains the error message.
YRangeFinder.FindRangeFinder
The
YRangeFinder.FindRangeFinder
function allows you to find a range finder from the
serial number of the module on which it resides and from its function name. You can use logical
names as well, as long as you have initialized them. Let us imagine a Yocto-RangeFinder module
with serial number
YRNGFND1-123456
which you have named "
MyModule
", and for which you have
given the
rangeFinder
function the name "
MyFunction
". The following five calls are strictly equivalent,
as long as "
MyFunction
" is defined only once.
rangefinder = YRangeFinder.
FindRangeFinder
(
"YRNGFND1-123456.rangeFinder"
)
;
rangefinder = YRangeFinder.
FindRangeFinder
(
"YRNGFND1-123456.MyFunction"
)
;
rangefinder = YRangeFinder.
FindRangeFinder
(
"MyModule.rangeFinder"
)
;
rangefinder = YRangeFinder.
FindRangeFinder
(
"MyModule.MyFunction"
)
;
rangefinder = YRangeFinder.
FindRangeFinder
(
"MyFunction"
)
;
YRangeFinder.FindRangeFinder
returns an object which you can then use at will to control
the range finder.
isOnline
The
isOnline()
method of the object returned by
YRangeFinder.FindRangeFinder
allows
you to know if the corresponding module is present and in working order.
4
Remember to change the filter of the selection window, otherwise the DLL will not show.
13. Using Yocto-RangeFinder with C#
78
www.yoctopuce.com
Summary of Contents for Yocto-RangeFinder
Page 1: ...Yocto RangeFinder User s guide...
Page 2: ......
Page 18: ...12 www yoctopuce com...
Page 26: ...20 www yoctopuce com...
Page 42: ...36 www yoctopuce com...
Page 70: ...gcc lyocto lm lpthread lusb 1 0 lstdc 10 Using Yocto RangeFinder with C 64 www yoctopuce com...
Page 90: ...84 www yoctopuce com...
Page 120: ...114 www yoctopuce com...
Page 130: ...124 www yoctopuce com...
Page 484: ...478 www yoctopuce com...
Page 488: ...482 www yoctopuce com...
Page 490: ...23 Characteristics 484 www yoctopuce com...
Page 491: ......
Page 492: ......