
Each property
xxx
of the module can be read thanks to a method of type
YModule.get_xxxx()
,
and properties which are not read-only can be modified with the help of the
YModule.set_xxx()
method. For more details regarding the used functions, refer to the API chapters.
Changing the module settings
When you want to modify the settings of a module, you only need to call the corresponding
YModule.set_xxx()
function. However, this modification is performed only in the random access
memory (RAM) of the module: if the module is restarted, the modifications are lost. To memorize
them persistently, it is necessary to ask the module to save its current configuration in its permanent
memory. To do so, use the
YModule.saveToFlash()
method. Inversely, it is possible to force
the module to forget its current settings by using the
YModule.revertFromFlash()
method.
The short example below allows you to modify the logical name of a module.
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Text
;
namespace
ConsoleApplication1
{
class
Program
{
static
void
usage
()
{
string
execname =
System
.
AppDomain
.
CurrentDomain
.
FriendlyName
;
Console
.
WriteLine
(
"Usage:"
)
;
Console
.
WriteLine
(
"usage: demo <serial or logical name> <new logical name>"
)
;
System.
Threading
.
Thread
.
Sleep
(
2500
)
;
Environment
.
Exit
(
0
)
;
}
static
void
Main
(
string
[]
args
)
{
YModule m;
string
errmsg =
""
;
string
newname;
if
(
args.
Length
!=
2
)
usage
()
;
if
(
YAPI.
RegisterHub
(
"usb"
,
ref
errmsg
)
!= YAPI.
SUCCESS
)
{
Console
.
WriteLine
(
"RegisterHub error: "
+ errmsg
)
;
Environment
.
Exit
(
0
)
;
}
m = YModule.
FindModule
(
args
[
0
])
;
// use serial or logical name
if
(
m.
isOnline
())
{
newname = args
[
1
]
;
if
(
!YAPI.
CheckLogicalName
(
newname
))
{
Console
.
WriteLine
(
"Invalid name ("
+ n
")"
)
;
Environment
.
Exit
(
0
)
;
}
m.
set_logicalName
(
newname
)
;
m.
saveToFlash
()
;
// do not forget this
Console
.
Write
(
"Module: serial= "
+ m.
get_serialNumber
())
;
Console
.
WriteLine
(
" / name= "
+ m.
get_logicalName
())
;
}
else
{
Console
.
Write
(
"not connected (check identification and USB cable"
)
;
}
YAPI.
FreeAPI
()
;
}
}
}
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
YModule.saveToFlash()
function only 100000 times in the life of the module.
Make sure you do not call this function within a loop.
13. Using Yocto-RangeFinder with C#
www.yoctopuce.com
81
Содержание 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: ......