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 ("
+
newname
+
")"
);
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.
Listing the modules
Obtaining the list of the connected modules is performed with the
YModule.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.
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Text
;
namespace
ConsoleApplication1
{
class
Program
{
static
void
Main
(
string
[]
args
)
{
YModule
m
;
string
errmsg
=
""
;
if
(
YAPI
.
RegisterHub
(
"usb"
,
ref
errmsg
)
!=
YAPI
.
SUCCESS
)
{
Console
.
WriteLine
(
"RegisterHub error: "
+
errmsg
);
Environment
.
Exit
(
0
);
}
Console
.
WriteLine
(
"Device list"
);
m
=
YModule
.
FirstModule
();
while
(
m
!=
null)
{
Console
.
WriteLine
(
m
.
get_serialNumber
()
+
" ("
+
m
.
get_productName
()
+
")"
);
m
=
m
.
nextModule
();
}
YAPI
.
FreeAPI
();
}
}
}
14. Using Yocto-Display with C#
84
www.yoctopuce.com
Содержание 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...