
// Get access to your device, through the VirtualHub running locally
yRegisterHub
(
'http://127.0.0.1:4444/'
,$errmsg
)
;
$rangefinder = yFindRangeFinder
(
"YRNGFND1-123456.rangeFinder"
)
;
// Check that the module is online to handle hot-plug
if(
rangefinder->
isOnline
())
{
// Use rangefinder->get_currentValue(), ...
}
Let's look at these lines in more details.
yocto_api.php and yocto_rangefinder.php
These two PHP includes provides access to the functions allowing you to manage Yoctopuce
modules.
yocto_api.php
must always be included,
yocto_rangefinder.php
is necessary
to manage modules containing a range finder, such as Yocto-RangeFinder.
yRegisterHub
The
yRegisterHub
function allows you to indicate on which machine the Yoctopuce modules are
located, more precisely on which machine the VirtualHub software is running. In our case, the
127.0.0.1:4444
address indicates the local machine, port
4444
(the standard port used by
Yoctopuce). You can very well modify this address, and enter the address of another machine on
which the VirtualHub software is running.
yFindRangeFinder
The
yFindRangeFinder
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 = yFindRangeFinder
(
"YRNGFND1-123456.rangeFinder"
)
;
$rangefinder = yFindRangeFinder
(
"YRNGFND1-123456.MyFunction"
)
;
$rangefinder = yFindRangeFinder
(
"MyModule.rangeFinder"
)
;
$rangefinder = yFindRangeFinder
(
"MyModule.MyFunction"
)
;
$rangefinder = yFindRangeFinder
(
"MyFunction"
)
;
yFindRangeFinder
returns an object which you can then use at will to control the range finder.
isOnline
The
isOnline()
method of the object returned by
yFindRangeFinder
allows you to know if
the corresponding module is present and in working order.
get_currentValue
The
get_currentValue()
method of the object returned by
yFindRangeFinder
allows you
to obtain the distance measured by the sensor, in mm or in inches depending on the sensor
configuration.
A real example
Open your preferred text editor
4
, copy the code sample below, save it with the Yoctopuce library files
in a location which is accessible to you web server, then use your preferred web browser to access
this page. The code is also provided in the directory
Examples/Doc-GettingStarted-Yocto-
RangeFinder
of the Yoctopuce library.
In this example, you will recognize the functions explained above, but this time used with all side
materials needed to make it work nicely as a small demo.
4
If you do not have a text editor, use Notepad rather than Microsoft Word.
9. Using Yocto-RangeFinder with PHP
48
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: ......