
The YSensor class is the parent class for all Yoctopuce sensors, and can provide access to any
sensor, regardless of its type. It includes methods to access all common functions. This makes it
easier to create applications that use many different sensors. Moreover, if you create an application
based on YSensor, it will work with all Yoctopuce sensors, even those which do no yet exist.
Programmation
In the Yoctopuce API, priority was put on the ease of access to the module functions by offering the
possibility to make abstractions of the modules implementing them. Therefore, it is quite possible to
work with a set of functions without ever knowing exactly which module are hosting them at the
hardware level. This tremendously simplifies programming projects with a large number of modules.
From the programming stand point, your Yocto-RangeFinder is viewed as a module hosting a given
number of functions. In the API, these functions are objects which can be found independently, in
several ways.
Access to the functions of a module
Access by logical name
Each function can be assigned an arbitrary and persistent logical name: this logical name is stored in
the flash memory of the module, even if this module is disconnected. An object corresponding to an
Xxx
function to which a logical name has been assigned can then be directly found with this logical
name and the
YXxx.FindXxx
method. Note however that a logical name must be unique among all
the connected modules.
Access by enumeration
You can enumerate all the functions of the same type on all the connected modules with the help of
the classic enumeration functions
FirstXxx
and
nextXxxx
available for each
YXxx
class.
Access by hardware name
Each module function has a hardware name, assigned at the factory and which cannot be modified.
The functions of a module can also be found directly with this hardware name and the
YXxx.FindXxx
function of the corresponding class.
Difference between
Find
and
First
The
YXxx.FindXxxx
and
YXxx.FirstXxxx
methods do not work exactly the same way. If there is no
available module,
YXxx.FirstXxxx
returns a null value. On the opposite, even if there is no
corresponding module,
YXxx.FindXxxx
returns a valid object, which is not online but which could
become so if the corresponding module is later connected.
Function handling
When the object corresponding to a function is found, its methods are available in a classic way.
Note that most of these subfunctions require the module hosting the function to be connected in
order to be handled. This is generally not guaranteed, as a USB module can be disconnected after
the control software has started. The
isOnline
method, available in all the classes, is then very
helpful.
Access to the modules
Even if it is perfectly possible to build a complete project while making a total abstraction of which
function is hosted on which module, the modules themselves are also accessible from the API. In
fact, they can be handled in a way quite similar to the functions. They are assigned a serial number
at the factory which allows you to find the corresponding object with
YModule.Find()
. You can also
assign arbitrary logical names to the modules to make finding them easier. Finally, the
YModule
class contains the
YModule.FirstModule()
and
nextModule()
enumeration methods allowing you to list
the connected modules.
6. Programming, general concepts
22
www.yoctopuce.com
Summary of Contents for Yocto-RangeFinder
Page 1: ...Yocto RangeFinder User s guide...
Page 2: ......
Page 18: ...12 www yoctopuce com...
Page 26: ...20 www yoctopuce com...
Page 42: ...36 www yoctopuce com...
Page 70: ...gcc lyocto lm lpthread lusb 1 0 lstdc 10 Using Yocto RangeFinder with C 64 www yoctopuce com...
Page 90: ...84 www yoctopuce com...
Page 120: ...114 www yoctopuce com...
Page 130: ...124 www yoctopuce com...
Page 484: ...478 www yoctopuce com...
Page 488: ...482 www yoctopuce com...
Page 490: ...23 Characteristics 484 www yoctopuce com...
Page 491: ......
Page 492: ......