
get_currentValue
The
get_currentValue()
method
of
the
object
returned
by
YRangeFinder.FindRangeFinder
allows you to obtain the distance measured by the sensor,
in mm or in inches depending on the sensor configuration.
A real example
Launch Microsoft Visual C# and open the corresponding sample project provided in the directory
Examples/Doc-GettingStarted-Yocto-RangeFinder
of the Yoctopuce library.
In this example, you will recognize the functions explained above, but this time used with all side
materials needed to make it work nicely as a small demo.
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
(
ex
" <serial_number>"
)
;
Console
.
WriteLine
(
ex
" <logical_name>"
)
;
Console
.
WriteLine
(
ex
" any "
)
;
Environment
.
Exit
(
0
)
;
}
static
void
Main
(
string
[]
args
)
{
string
errmsg =
""
;
string
target;
YRangeFinder rf;
YLightSensor ir;
YTemperature tmp;
if
(
args.
Length
<
1
)
usage
()
;
target = args
[
0
]
.
ToUpper
()
;
// Setup the API to use local USB devices
if
(
YAPI.
RegisterHub
(
"usb"
,
ref
errmsg
)
!= YAPI.
SUCCESS
)
{
Console
.
WriteLine
(
"RegisterHub error: "
+ errmsg
)
;
Environment
.
Exit
(
0
)
;
}
if
(
target ==
"ANY"
)
{
rf = YRangeFinder.
FirstRangeFinder
()
;
if
(
rf ==
null
)
{
Console
.
WriteLine
(
"No module connected (check USB cable) "
)
;
Environment
.
Exit
(
0
)
;
}
target = rf.
get_module
()
.
get_serialNumber
()
;
}
else
rf = YRangeFinder.
FindRangeFinder
(
".rangefinder1"
)
;
if
(
!rf.
isOnline
())
{
Console
.
WriteLine
(
"Module not connected (check identification and USB cable)"
)
;
Environment
.
Exit
(
0
)
;
}
ir = YLightSensor.
FindLightSensor
(
".lightSensor1"
)
;
tmp = YTemperature.
FindTemperature
(
".temperature1"
)
;
while
(
rf.
isOnline
())
{
Console
.
WriteLine
(
"Distance : "
+ rf.
get_currentValue
()
.
ToString
())
;
Console
.
WriteLine
(
"Ambiant IR : "
+ ir.
get_currentValue
()
.
ToString
())
;
Console
.
WriteLine
(
"Temperature : "
+ tmp.
get_currentValue
()
.
ToString
())
;
Console
.
WriteLine
(
" (press Ctrl-C to exit)"
)
;
YAPI.
Sleep
(
1000
,
ref
errmsg
)
;
}
YAPI.
FreeAPI
()
;
}
13. Using Yocto-RangeFinder with C#
www.yoctopuce.com
79
Содержание 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: ......