#import <Foundation/Foundation.h>
#import "yocto_api.h"
#import "yocto_genericsensor.h"
static void
usage(void)
{
NSLog(@"usage: demo <serial_number>
NSLog(@"
demo
NSLog(@"
demo any
exit(1);
}
int main(int
argc,
{
NSError
*error;
YGenericSensor
if
(argc <
2) {
usage();
}
@autoreleasepool {
NSString
*target
// Setup the API to use local USB devices
if([YAPI
RegisterHub:@"usb": &error] != YAPI_SUCCESS) {
NSLog(@"RegisterHub error:
return
1;
}
if
([target
isEqualToString:@"any"]) {
// retreive any generic sensor
sensor
=
[YGenericSensor
if
(sensor
== NULL) {
NSLog(@"No module connected (check USB
return
1;
}
} else {
sensor
=
[YGenericSensor
}
// we need to retreive both DC and AC current from the device.
if
(![sensor
isOnline])
NSLog(@"No module connected (check USB
return
1;
}
YModule
*m
=
[sensor module];
sensor1
=
[YGenericSensor
@".genericSensor1"]];
while([m
isOnline]) {
NSLog(@"Value: %f
NSLog(@"
(press Ctrl-C to
[YAPI
Sleep:1000:NULL];
}
NSLog(@"Module not connected (check identification and USB
[YAPI
FreeAPI];
}
return
0;
}
19.2. Contrôle de la partie module
Chaque module peut-être contrôlé d'une manière similaire, vous trouverez ci dessous un simple
programme d'exemple affichant les principaux paramètres d'un module et permettant d'activer la
balise de localisation.
#import <Foundation/Foundation.h>
#import "yocto_api.h"
static void usage(const char
{
NSLog(@"usage: %s <serial or logical name>
www.yoctopuce.com
");
<logical_name>");
const char
* argv[])
*sensor, *sensor1;
=
[NSString
stringWithUTF8String:argv[1]];
%@", [error localizedDescription]);
FirstGenericSensor];
FindGenericSensor:target];
{
FindGenericSensor:[m.serialNumber
%@", [sensor1 currentValue], [sensor1 get_unit]);
exit)");
*exe)
19. Utilisation du Yocto-milliVolt-Rx-BNC en Objective-C
(use any discovered
device)");
cable)");
cable)");
[ON/OFF]\n", exe);
stringByAppendingString:
cable)");
151