
<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"
);
}
@
$serial
=
$_GET
[
'serial'
];
if
(
$serial
!=
''
)
{
// Check if a specified module is available online
$module
=
yFindModule
(
"
$serial
"
);
if
(!
$module
->
isOnline
())
{
die
(
"Module not connected (check serial and USB cable)"
);
}
}
else
{
// or use any connected module suitable for the demo
$module
=
yFirstModule
();
if(
$module
)
{
// skip VirtualHub
$module
=
$module
->
nextModule
();
}
if(
is_null
(
$module
))
{
die
(
"No module connected (check USB cable)"
);
}
else
{
$serial
=
$module
->
get_serialnumber
();
}
}
Print(
"Module to use: <input name='serial' value='
$serial
'><br>"
);
if
(
isset
(
$_GET
[
'newname'
])){
$newname
=
$_GET
[
'newname'
];
if
(!
yCheckLogicalName
(
$newname
))
die
(
'Invalid name'
);
$module
->
set_logicalName
(
$newname
);
$module
->
saveToFlash
();
}
printf
(
"Current name:
%s
<br>"
,
$module
->
get_logicalName
());
print(
"New name: <input name='newname' value='' maxlength=19><br>"
);
yFreeAPI
();
?>
<input type='submit'>
</FORM>
</BODY>
</HTML>
Warning: the number of write cycles of the nonvolatile memory of the module is limited. When this
limit is reached, nothing guaranties that the saving process is performed correctly. This limit, linked to
the technology employed by the module micro-processor, is located at about 100000 cycles. In short,
you can use the
saveToFlash()
function only 100000 times in the life of the module. Make sure
you do not call this function within a loop.
Listing the modules
Obtaining the list of the connected modules is performed with the
yFirstModule()
function which
returns the first module found. Then, you only need to call the
nextModule()
function of this
object to find the following modules, and this as long as the returned value is not
NULL
. Below a
short example listing the connected modules.
<HTML>
<HEAD>
<TITLE>inventory</TITLE>
</HEAD>
<BODY>
<H1>Device list</H1>
<TT>
<?php
include(
'yocto_api.php'
);
yRegisterHub
(
"http://127.0.0.1:4444/"
);
$module
=
yFirstModule
();
10. Using Yocto-Display with PHP
www.yoctopuce.com
51
Содержание Yocto-Display
Страница 1: ...Yocto Display User Manual...
Страница 2: ......
Страница 40: ...34 www yoctopuce com...
Страница 52: ...46 www yoctopuce com...
Страница 84: ...78 www yoctopuce com...
Страница 92: ...86 www yoctopuce com...
Страница 130: ...124 www yoctopuce com...
Страница 158: ...22 High level API Reference 152 www yoctopuce com On failure throws an exception or returns a negative error code...
Страница 422: ...416 www yoctopuce com...
Страница 424: ...24 Characteristics 418 www yoctopuce com...