int manager_simple() { //Declare an Manager handle CPhidgetManagerHandle man = 0; CPhidget_enableLogging(PHIDGET_LOG_VERBOSE, NULL); //create the Manager object CPhidgetManager_create(&man); //Set the handlers to be run when the device is plugged in or opened from software, unplugged or closed from software, or generates an error. CPhidgetManager_set_OnAttach_Handler(man, AttachHandler, man); CPhidgetManager_set_OnDetach_Handler(man, DetachHandler, man); CPhidgetManager_set_OnError_Handler(man, ErrorHandler, NULL); //open the Manager for device connections CPhidgetManager_open(man); //end simulation printf("Press any key to end\n"); getchar(); //since user input has been read, this is a signal to terminate the program so we will close the phidget and delete the object we created printf("Closing...\n"); CPhidgetManager_close(man); CPhidgetManager_delete(man); //all done, exit return 0; }
JNIEXPORT void JNICALL Java_com_phidgets_Phidget_nativeEnableLogging(JNIEnv *env, jclass cls, jint level, jstring file) { int error; jboolean iscopy; const char *textString = file ? (*env)->GetStringUTFChars( env, file, &iscopy) : NULL; if ((error = CPhidget_enableLogging(level, (char *)textString))) PH_THROW(error); (*env)->ReleaseStringUTFChars(env, file, textString); }
bool attach( CPhidgetInterfaceKitHandle &phid, int serial_number) { CPhidget_enableLogging(PHIDGET_LOG_VERBOSE, "/home/motters/Desktop/phidgets.log"); //create the object CPhidgetInterfaceKit_create(&phid); //Set the handlers to be run when the device is plugged in or opened from software, unplugged or closed from software, or generates an error. CPhidget_set_OnAttach_Handler((CPhidgetHandle)phid, AttachHandler, NULL); CPhidget_set_OnDetach_Handler((CPhidgetHandle)phid, DetachHandler, NULL); CPhidget_set_OnError_Handler((CPhidgetHandle)phid, ErrorHandler, NULL); //Registers a callback that will run if an input changes. //Requires the handle for the Phidget, the function that will be called, and an arbitrary pointer that will be supplied to the callback function (may be NULL). CPhidgetInterfaceKit_set_OnInputChange_Handler (phid, InputChangeHandler, NULL); //Registers a callback that will run if the sensor value changes by more than the OnSensorChange trig-ger. //Requires the handle for the IntefaceKit, the function that will be called, and an arbitrary pointer that will be supplied to the callback function (may be NULL). CPhidgetInterfaceKit_set_OnSensorChange_Handler (phid, SensorChangeHandler, NULL); //Registers a callback that will run if an output changes. //Requires the handle for the Phidget, the function that will be called, and an arbitrary pointer that will be supplied to the callback function (may be NULL). CPhidgetInterfaceKit_set_OnOutputChange_Handler (phid, OutputChangeHandler, NULL); //open the device for connections CPhidget_open((CPhidgetHandle)phid, serial_number); //get the program to wait for an interface kit device to be attached if (serial_number == -1) { ROS_INFO("Waiting for Interface Kit Phidget to be attached...."); } else { ROS_INFO("Waiting for Interface Kit Phidget %d to be attached....", serial_number); } int result; if((result = CPhidget_waitForAttachment((CPhidgetHandle)phid, 10000))) { const char *err; CPhidget_getErrorDescription(result, &err); ROS_ERROR("Problem waiting for attachment: %s", err); return false; } else return true; }
int test_interfacekit() { int numInputs, numOutputs, numSensors; int err; CPhidgetInterfaceKitHandle IFK = 0; CPhidget_enableLogging(PHIDGET_LOG_VERBOSE, NULL); CPhidgetInterfaceKit_create(&IFK); CPhidgetInterfaceKit_set_OnInputChange_Handler(IFK, IFK_InputChangeHandler, NULL); CPhidgetInterfaceKit_set_OnOutputChange_Handler(IFK, IFK_OutputChangeHandler, NULL); CPhidgetInterfaceKit_set_OnSensorChange_Handler(IFK, IFK_SensorChangeHandler, NULL); CPhidget_set_OnAttach_Handler((CPhidgetHandle)IFK, IFK_AttachHandler, NULL); CPhidget_set_OnDetach_Handler((CPhidgetHandle)IFK, IFK_DetachHandler, NULL); CPhidget_set_OnError_Handler((CPhidgetHandle)IFK, IFK_ErrorHandler, NULL); CPhidget_open((CPhidgetHandle)IFK, -1); //wait 5 seconds for attachment if((err = CPhidget_waitForAttachment((CPhidgetHandle)IFK, 0)) != EPHIDGET_OK ) { const char *errStr; CPhidget_getErrorDescription(err, &errStr); printf("Error waiting for attachment: (%d): %s\n",err,errStr); goto exit; } display_generic_properties((CPhidgetHandle)IFK); CPhidgetInterfaceKit_getOutputCount((CPhidgetInterfaceKitHandle)IFK, &numOutputs); CPhidgetInterfaceKit_getInputCount((CPhidgetInterfaceKitHandle)IFK, &numInputs); CPhidgetInterfaceKit_getSensorCount((CPhidgetInterfaceKitHandle)IFK, &numSensors); CPhidgetInterfaceKit_setOutputState((CPhidgetInterfaceKitHandle)IFK, 0, 1); printf("Sensors:%d Inputs:%d Outputs:%d\n", numSensors, numInputs, numOutputs); //err = CPhidget_setDeviceLabel((CPhidgetHandle)IFK, "test"); while(1) { sleep(1); } while(1) { CPhidgetInterfaceKit_setOutputState(IFK, 7, 1); CPhidgetInterfaceKit_setOutputState(IFK, 7, 0); } CPhidgetInterfaceKit_setOutputState(IFK, 0, 1); sleep(1); CPhidgetInterfaceKit_setOutputState(IFK, 0, 0); sleep(1); CPhidgetInterfaceKit_setOutputState(IFK, 0, 1); sleep(1); CPhidgetInterfaceKit_setOutputState(IFK, 0, 0); sleep(5); exit: CPhidget_close((CPhidgetHandle)IFK); CPhidget_delete((CPhidgetHandle)IFK); return 0; }