browser favori. Vous trouverez aussi ce code dans le répertoire Examples/Doc-GettingStarted-
Yocto-IO de la librairie Yoctopuce.
Vous reconnaîtrez dans cet exemple l'utilisation des fonctions expliquées ci-dessus, cette fois
utilisées avec le décorum nécessaire à en faire un petit programme d'exemple concret.
<HTML>
<HEAD>
<TITLE>Hello World</TITLE>
</HEAD>
<BODY>
<FORM
name='myform' method='get'>
<?php
include('yocto_api.php');
include('yocto_digitalio.php');
// Use explicit error handling rather than exceptions
YAPI::DisableExceptions();
// Setup the API to use the VirtualHub on local machine
if(YAPI::RegisterHub('http://127.0.0.1:4444/',$errmsg) != YAPI::SUCCESS) {
die("Cannot contact VirtualHub on
}
@$serial
= $_GET['serial'];
if
($serial
!= '')
{
// Check if a specified module is available online
$io
= YDigitalIO::FindDigitalIO("$serial.digitalIO");
if (!$io->isOnline()) {
die("Module not connected (check serial and USB
}
} else
{
// or use any connected module suitable for the demo
// (note that the order of enumeration may vary)
$io
= YDigitalIO::FirstDigitalIO();
if(is_null($io)) {
die("No module connected (check USB
}
$serial
= $io->module()->get_serialnumber();
}
// make sure the device is here
if (!$io->isOnline())
die("Module not connected (check identification and USB
// lets configure the channels direction
// bits 0..1 as output
// bits 2..3 as input
$io->set_portDirection(0x03);
$io->set_portPolarity(0);
$io->set_portOpenDrain(0);
@$outputdata
= intVal($_GET['outputdata']);
$outputdata
=
($outputdata
$io->set_portState($outputdata);
ySleep(50, $errmsg);
$inputdata
= $io->get_portState();
$line
= "";
// display port value as binary
for
($i
= 0;
$i
if
(($inputdata
Print("Module to use: <input name='serial'
Print("<input type='hidden' name='outputdata'
YAPI::FreeAPI();
// trigger auto-refresh after one second
Print("<script language='javascript1.5'
Print("setTimeout('window.myform.submit()',1000);");
Print("</script>\n");
?>
<p>
Channels 0..1 are configured as outputs and channels 2..3
are configred as inputs, you can connect some inputs to
ouputs and see what happens
</p>
www.yoctopuce.com
// polarity set to regular
// No open drain
+ 1) % 4;
// We could have used set_bitState as well
// make sure the set is
// read port values
< 4; $i++)
&
(8
>> $i))>0)
$line
127.0.0.1");
cable)");
cable)");
// cycle ouput 0..3
processed before the get
=
$line
. '1'; else
value='$serial'><br>");
value='$outputdata'><br>");
type='text/JavaScript'>\n");
15. Utilisation du Yocto-IO en PHP
cable)");
$line
=
$line
. '0';
115