
exit
(
1
)
;
}
int
main
(
int
argc,
const
char
* argv
[])
{
string
errmsg;
// Setup the API to use local USB devices
if(
yRegisterHub
(
"usb"
, errmsg
)
!= YAPI_SUCCESS
)
{
cerr
<<
"RegisterHub error: "
<< errmsg <<
endl
;
return
1
;
}
if(
argc <
2
)
usage
(
argv
[
0
])
;
YModule *module = yFindModule
(
argv
[
1
])
;
// use serial or logical name
if
(
module->
isOnline
())
{
if
(
argc >=
3
)
{
string
newname = argv
[
2
]
;
if
(
!yCheckLogicalName
(
newname
))
{
cerr
<<
"Invalid name ("
<< newname <<
")"
<<
endl
;
usage
(
argv
[
0
])
;
}
module->
set_logicalName
(
newname
)
;
module->
saveToFlash
()
;
}
cout
<<
"Current name: "
<< module->
get_logicalName
()
<<
endl
;
}
else
{
cout
<< argv
[
1
]
<<
" not connected (check identification and USB cable)"
<<
endl
;
}
yFreeAPI
()
;
return
0
;
}
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.
#include <iostream>
#include "yocto_api.h"
using
namespace
std;
int
main
(
int
argc,
const
char
* argv
[])
{
string
errmsg;
// Setup the API to use local USB devices
if(
YAPI::
RegisterHub
(
"usb"
, errmsg
)
!= YAPI_SUCCESS
)
{
cerr
<<
"RegisterHub error: "
<< errmsg <<
endl
;
return
1
;
}
cout
<<
"Device list: "
<<
endl
;
YModule *module = YModule::
FirstModule
()
;
while
(
module !=
NULL
)
{
cout
<< module->
get_serialNumber
()
<<
" "
;
cout
<< module->
get_productName
()
<<
endl
;
module = module->
nextModule
()
;
}
10. Using Yocto-RangeFinder with C++
www.yoctopuce.com
61
Содержание Yocto-RangeFinder
Страница 1: ...Yocto RangeFinder User s guide...
Страница 2: ......
Страница 18: ...12 www yoctopuce com...
Страница 26: ...20 www yoctopuce com...
Страница 42: ...36 www yoctopuce com...
Страница 70: ...gcc lyocto lm lpthread lusb 1 0 lstdc 10 Using Yocto RangeFinder with C 64 www yoctopuce com...
Страница 90: ...84 www yoctopuce com...
Страница 120: ...114 www yoctopuce com...
Страница 130: ...124 www yoctopuce com...
Страница 158: ...21 High level API Reference On failure throws an exception or returns a negative error code 152 www yoctopuce com...
Страница 484: ...478 www yoctopuce com...
Страница 488: ...482 www yoctopuce com...
Страница 490: ...23 Characteristics 484 www yoctopuce com...
Страница 491: ......
Страница 492: ......