
<HTML>
<HEAD>
<TITLE>Hello World</TITLE>
</HEAD>
<BODY>
<?php
include(
'yocto_api.php'
)
;
include(
'yocto_rangefinder.php'
)
;
include(
'yocto_lightsensor.php'
)
;
include(
'yocto_temperature.php'
)
;
// Use explicit error handling rather than exceptions
yDisableExceptions
()
;
// Setup the API to use the VirtualHub on local machine
if
(
yRegisterHub
(
'http://127.0.0.1:4444/'
, $errmsg
)
!= YAPI_SUCCESS
)
{
die
(
"Cannot contact VirtualHub on 127.0.0.1"
)
;
}
@$serial = $_GET
[
'serial'
]
;
if
(
$serial !=
''
)
{
// Check if a specified module is available online
$rf = yFindRangeFinder
(
"
$serial
.rangeFinder1"
)
;
if
(
!$rf->
isOnline
())
{
die
(
"Module not connected (check serial and USB cable)"
)
;
}
}
else
{
// or use any connected module suitable for the demo
$rf = yFirstRangeFinder
()
;
if
(
is_null
(
$rf
))
{
die
(
"No module connected (check USB cable)"
)
;
}
else
{
$serial = $rf->
module
()
->
get_serialnumber
()
;
}
}
$ir = yFindLightSensor
(
"
$serial
.lightSensor1"
)
;
$tmp = yFindTemperature
(
"
$serial
.temperature1"
)
;
Print(
"Module to use: <input name='serial' value='
$serial
'><br>"
)
;
Print(
"Distance: {
$rf->get_currentValue
()} <br>"
)
;
Print(
"Ambient IR: {
$ir->get_currentValue
()} <br>"
)
;
Print(
"Temperature: {
$tmp->get_currentValue
()} <br>"
)
;
yFreeAPI
()
;
// trigger auto-refresh after one second
Print(
"<script language='javascript1.5' type='text/JavaScript'>
\n
"
)
;
Print(
"setTimeout('window.location.reload()',1000);"
)
;
Print(
"</script>
\n
"
)
;
?>
</BODY>
</HTML>
9.3. Control of the module part
Each module can be controlled in a similar manner, you can find below a simple sample program
displaying the main parameters of the module and enabling you to activate the localization beacon.
<HTML>
<HEAD>
<TITLE>Module Control</TITLE>
</HEAD>
<BODY>
<FORM method='get'>
<?php
include(
'yocto_api.php'
)
;
// Use explicit error handling rather than exceptions
yDisableExceptions
()
;
// Setup the API to use the VirtualHub on local machine
if(
yRegisterHub
(
'http://127.0.0.1:4444/'
,$errmsg
)
!= YAPI_SUCCESS
)
{
die
(
"Cannot contact VirtualHub on 127.0.0.1 : "
.$errmsg
)
;
9. Using Yocto-RangeFinder with PHP
www.yoctopuce.com
49
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: ......