#include "yocto_api.h"
#include "yocto_relay.h"
#include <iostream>
#include <ctype.h>
#include <stdlib.h>
using namespace
std;
static void
usage(void)
{
cout
<<
"usage: demo <serial_number>
cout
<<
"
cout
<<
"
u64
now
= YAPI::GetTickCount();
while (YAPI::GetTickCount() -
// wait 3 sec to show the message
}
exit(1);
}
int main(int
argc,
{
string
errmsg;
string
target;
YRelay
*relay;
char
state;
if
(argc
< 3) {
usage();
}
target
= (string) argv[1];
state
= toupper(argv[2][0]);
// Setup the API to use local USB devices
if
(YAPI::RegisterHub("usb",
cerr
<<
"RegisterHub error: "
return 1;
}
if
(target
== "any") {
relay
= YRelay::FirstRelay();
if
(relay
== NULL) {
cout
<<
"No module connected (check USB cable)"
return 1;
}
} else {
relay
=
YRelay::FindRelay(target
}
if (relay->isOnline()) {
relay->set_state(state
} else {
cout
<<
"Module not connected (check identification and USB cable)"
}
YAPI::FreeAPI();
return 0;
}
8.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.
#include <iostream>
#include <stdlib.h>
#include "yocto_api.h"
using namespace
std;
static void usage(const char
www.yoctopuce.com
demo <logical_name> [ A | B ]"
demo any [ A | B ]"
<< endl;
now
< 3000) {
const char
* argv[])
errmsg) != YAPI::SUCCESS) {
<<
errmsg
+ ".relay1");
==
'A'
?
Y_STATE_A
*exe)
8. Utilisation du Yocto-PowerRelay-V2 en C++
[ A | B ]"
<< endl;
<< endl;
<< endl;
<< endl;
: Y_STATE_B);
<< endl;
39