desarrollosconsejeria/placaSiatic/1.0-0/redrelaylibrary.cpp @ b9655064
b9655064 | Elisa | #include "redrelaylibrary.h"
|
|
bool RedRelayLibrary::ConnectRelay(){
|
|||
hid_device_info *info = hid_enumerate(0x16c0, 0x05df);
|
|||
if (info == NULL) return false;
|
|||
dev = hid_open_path(info->path);
|
|||
return dev != NULL;
|
|||
}
|
|||
void RedRelayLibrary::SetRelayState(RelayState State, RelayPort Port){
|
|||
// Simple as send the specific feature to the relay...
|
|||
char package[] = { 0x00,State,Port+1,0x00,0x00,0x00,0x00,0x00,0x00 };
|
|||
#ifndef _WIN32
|
|||
hid_write(dev, (unsigned char*) &package, sizeof(package));
|
|||
#else
|
|||
hid_send_feature_report(dev, (unsigned char*) &package, sizeof(package));
|
|||
#endif
|
|||
}
|
|||
RelayState RedRelayLibrary::GetRelayState(RelayPort Port)
|
|||
{
|
|||
unsigned char buffer[10];
|
|||
memset(&buffer, 0, 10);
|
|||
hid_get_feature_report(dev, (unsigned char*) buffer, 9);
|
|||
// We get the relay state with a bitset
|
|||
unsigned char state = buffer[8];
|
|||
std::bitset<CHAR_BIT> b(state);
|
|||
b = b.flip();
|
|||
return b[Port] == 1 ? ON : OFF;
|
|||
}
|
|||
void RedRelayLibrary::DisconnectRelay(){
|
|||
hid_close(dev);
|
|||
}
|