Contrôle De La Partie Module - Yoctopuce Yocto-IO Mode D'emploi

Table des Matières

Publicité

NSLog(@"
demo
NSLog(@"
demo any
exit(1);
}
int main(int
argc,
{
NSError
*error;
@autoreleasepool {
YDigitalIO
*io;
// Setup the API to use local USB devices
if([YAPI
RegisterHub:@"usb": &error] != YAPI_SUCCESS) {
NSLog(@"RegisterHub error:
return
1;
}
if
(argc >
1
NSString
*target
io
=
[YDigitalIO
} else {
io
=
[YDigitalIO
}
// make sure the device is here
if
(![io
isOnline]) {
NSLog(@"No module connected (check USB
usage();
}
// lets configure the channels direction
// bits 0..1 as output
// bits 2..3 as input
[io set_portDirection:0x03];
[io set_portPolarity:0];
[io set_portOpenDrain:0];
NSLog(@"Channels 0..1 are configured as outputs and channels
NSLog(@"are configred as inputs, you can connect some inputs
NSLog(@"ouputs and see what
int
outputdata
while
([io
isOnline]) {
outputdata
=
[io set_portState:outputdata];
[YAPI
Sleep:1000:&error];
int
inputdata
char
line[5];
for
(int
i
=
if
(inputdata
line[i] =
else
line[i] =
}
line[4] =
0;
NSLog(@"port value =
}
NSLog(@"Module
[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"
www.yoctopuce.com
<logical_name>");
(use any discovered
const char
* argv[])
%@", [error localizedDescription]);
&&
strcmp(argv[1],
"any")) {
=
[NSString
stringWithUTF8String:argv[1]];
FindDigitalIO:[NSString
FirstDigitalIO];
// polarity set to regular
// No open drain
happens");
=
0;
(outputdata
+ 1) %
4;
// We could have used set_bitState as well
=
[io get_portState];
// display part state value as binary
0; i <
4
;
i++) {
&
(8
>>
i))
'1';
'0';
%s", line);
disconnected");
device)");
stringWithFormat:@"%@.digitalIO", target]];
cable)");
// cycle ouput 0..3
// read port values
19. Utilisation du Yocto-IO en Objective-C
2..3");
to");
149

Publicité

Table des Matières
loading

Table des Matières