1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
| #include <stdio.h>
#include <C:/Program Files/Phidgets/Phidget22/phidget22.h>
//Declare any event handlers here. These will be called every time the associated event occurs.
static void CCONV onAttach(PhidgetHandle ch, void * ctx)
{
int channel;
//Getting the channel number to distinguish between Phidgets
Phidget_getChannel(ch, &channel);
printf("Attach [%d]!\n\n", channel);
}
static void CCONV onDetach(PhidgetHandle ch, void * ctx)
{
int channel;
//Getting the channel number to distinguish between Phidgets
Phidget_getChannel(ch, &channel);
printf("Detach [%d]!\n\n", channel);
}
int set_HV_State(channel,relayStatus)
{
PhidgetDigitalOutput_setState(channel, relayStatus);
return relayStatus;
}
int main()
{
int hvState = 0;
//Declare your Phidget channels and other variables
PhidgetDigitalOutputHandle digitalOutput0;
//Create your Phidget channels
PhidgetDigitalOutput_create(&digitalOutput0);
//Set addressing parameters to specify which channel to open (if any)
Phidget_setDeviceSerialNumber((PhidgetHandle)digitalOutput0, 502246);
//Assign any event handlers you need before calling open so that no events are missed.
Phidget_setOnAttachHandler((PhidgetHandle)digitalOutput0, onAttach, NULL);
Phidget_setOnDetachHandler((PhidgetHandle)digitalOutput0, onDetach, NULL);
//Open your Phidgets and wait for attachment
Phidget_openWaitForAttachment((PhidgetHandle)digitalOutput0, 5000);
//Do stuff with your Phidgets here or in your event handlers.
hvState = 1;
set_HV_State(digitalOutput0,hvState);
//Wait until Enter has been pressed before exiting
getchar();
//Close your Phidgets once the program is done.
Phidget_close((PhidgetHandle)digitalOutput0);
PhidgetDigitalOutput_delete(&digitalOutput0);
} |
Partager