aboutsummaryrefslogtreecommitdiffstats
path: root/labview
diff options
context:
space:
mode:
authorJonathan McCrohan <jmccrohan@gmail.com>2012-04-14 12:56:48 +0100
committerJonathan McCrohan <jmccrohan@gmail.com>2012-04-14 12:56:48 +0100
commit0b624384cd52be20e61284551d832b499d7b7707 (patch)
tree6f95a4bbef47abc9720b96c0722e8f632aef228a /labview
downloadlibphidget21-0b624384cd52be20e61284551d832b499d7b7707.tar.gz
Imported Upstream version 2.1.8.20120216upstream/2.1.8.20120216
Diffstat (limited to 'labview')
-rw-r--r--labview/phidget_labview.c429
-rw-r--r--labview/phidget_labview.h642
2 files changed, 1071 insertions, 0 deletions
diff --git a/labview/phidget_labview.c b/labview/phidget_labview.c
new file mode 100644
index 0000000..380915b
--- /dev/null
+++ b/labview/phidget_labview.c
@@ -0,0 +1,429 @@
+#include "stdafx.h"
+
+#include "cphidget.h"
+#include "cphidgetmanager.h"
+#include "cphidgetdictionary.h"
+#include "cphidgetaccelerometer.h"
+#include "cphidgetadvancedservo.h"
+#include "cphidgetanalog.h"
+#include "cphidgetbridge.h"
+#include "cphidgetencoder.h"
+#include "cphidgetfrequencycounter.h"
+#include "cphidgetgps.h"
+#include "cphidgetinterfacekit.h"
+#include "cphidgetir.h"
+#include "cphidgetmanager.h"
+#include "cphidgetled.h"
+#include "cphidgetmotorcontrol.h"
+#include "cphidgetphsensor.h"
+#include "cphidgetrfid.h"
+#include "cphidgetservo.h"
+#include "cphidgetspatial.h"
+#include "cphidgetstepper.h"
+#include "cphidgettemperaturesensor.h"
+#include "cphidgettextlcd.h"
+#include "cphidgettextled.h"
+#include "cphidgetweightsensor.h"
+
+#include "csocket.h"
+
+#ifdef COMPILE_PHIDGETS_LABVIEW
+
+#include "phidget_labview.h"
+
+LV_CFHANDLE_0(, Attach, lvNothing)
+LV_CFHANDLE_0(, Detach, lvNothing)
+LV_CFHANDLE_0(, ServerConnect, lvNothing)
+LV_CFHANDLE_0(, ServerDisconnect, lvNothing)
+LV_CFHANDLE_BODY(, Error, lvError, void *userPtr, int val1, const char *val2)
+ data->val1 = val1;
+ data->val2=(LStrHandle)DSNewHandle(sizeof(int32)+255*sizeof(char));
+ memset(LStrBuf(*data->val2),'\0',255);
+ snprintf((char*)LStrBuf(*data->val2),255,"%s",val2);
+ LStrLen(*data->val2)=strlen(val2);
+
+ ret = PostLVUserEvent(ev, data);
+
+ DSDisposeHandle(data->val2);
+ DSDisposePtr(data);
+ return EPHIDGET_OK;
+}
+
+LV_CFHANDLE_2(Accelerometer, AccelerationChange, lvIndexedDouble, int, double)
+
+LV_CFHANDLE_2(AdvancedServo, PositionChange, lvIndexedDouble, int, double)
+LV_CFHANDLE_2(AdvancedServo, VelocityChange, lvIndexedDouble, int, double)
+LV_CFHANDLE_2(AdvancedServo, CurrentChange, lvIndexedDouble, int, double)
+
+LV_CFHANDLE_2(Bridge, BridgeData, lvIndexedDouble, int, double)
+
+LV_CFHANDLE_2(Encoder, InputChange, lvIndexedInt32, int, int)
+LV_CFHANDLE_3(Encoder, PositionChange, lvIndexedInt32Int32, int, int, int)
+
+LV_CFHANDLE_3(FrequencyCounter, Count, lvIndexedInt32Int32, int, int, int)
+
+LV_CFHANDLE_3(GPS, PositionChange, lvDoubleDoubleDouble, double, double, double)
+LV_CFHANDLE_1(GPS, PositionFixStatusChange, lvInt32, int)
+
+LV_CFHANDLE_2(InterfaceKit, InputChange, lvIndexedInt32, int, int)
+LV_CFHANDLE_2(InterfaceKit, OutputChange, lvIndexedInt32, int, int)
+LV_CFHANDLE_2(InterfaceKit, SensorChange, lvIndexedInt32, int, int)
+
+LV_CFHANDLE_BODY(IR, Code, lvIRCode, void *userPtr, unsigned char *val1, int val2, int val3, int val4)
+ data->val1=(lvArrUInt8DH)DSNewHandle(sizeof(int32)+val2*sizeof(uInt8));
+ (*(data->val1))->length = val2;
+ memcpy((*(data->val1))->data, val1, val2 * sizeof(uInt8));
+ data->val2 = val3;
+ data->val3 = val4;
+
+ ret = PostLVUserEvent(ev, data);
+
+ DSDisposeHandle(data->val1);
+ DSDisposePtr(data);
+ return EPHIDGET_OK;
+}
+LV_CFHANDLE_BODY(IR, RawData, lvInt32Array, void *userPtr, int *val1, int val2)
+ data->val1=(lvArrInt32DH)DSNewHandle(sizeof(int32)+val2*sizeof(int32));
+ (*(data->val1))->length = val2;
+ memcpy((*(data->val1))->data, val1, val2 * sizeof(int32));
+
+ ret = PostLVUserEvent(ev, data);
+
+ DSDisposeHandle(data->val1);
+ DSDisposePtr(data);
+ return EPHIDGET_OK;
+}
+LV_CFHANDLE_BODY(IR, Learn, lvIRLearn, void *userPtr, unsigned char *val1, int val2, CPhidgetIR_CodeInfoHandle val3)
+ data->val1=(lvArrUInt8DH)DSNewHandle(sizeof(int32)+val2*sizeof(uInt8));
+ (*(data->val1))->length = val2;
+ memcpy((*(data->val1))->data, val1, val2 * sizeof(uInt8));
+ data->val2 = *val3;
+
+ ret = PostLVUserEvent(ev, data);
+
+ DSDisposeHandle(data->val1);
+ DSDisposePtr(data);
+ return EPHIDGET_OK;
+}
+
+LV_CFHANDLE_2(MotorControl, InputChange, lvIndexedInt32, int, int)
+LV_CFHANDLE_2(MotorControl, VelocityChange, lvIndexedDouble, int, double)
+LV_CFHANDLE_2(MotorControl, CurrentChange, lvIndexedDouble, int, double)
+LV_CFHANDLE_3(MotorControl, EncoderPositionChange, lvIndexedInt32Int32, int, int, int)
+LV_CFHANDLE_2(MotorControl, EncoderPositionUpdate, lvIndexedInt32, int, int)
+LV_CFHANDLE_2(MotorControl, BackEMFUpdate, lvIndexedDouble, int, double)
+LV_CFHANDLE_2(MotorControl, SensorUpdate, lvIndexedInt32, int, int)
+LV_CFHANDLE_2(MotorControl, CurrentUpdate, lvIndexedDouble, int, double)
+
+LV_CFHANDLE_1(PHSensor, PHChange, lvDouble, double)
+
+LV_CFHANDLE_2(RFID, OutputChange, lvIndexedInt32, int, int)
+LV_CFHANDLE_BODY(RFID, Tag, lvUInt8Array, void *userPtr, unsigned char *val1)
+ data->val1=(lvArrUInt8DH)DSNewHandle(sizeof(int32)+5*sizeof(uInt8));
+ (*(data->val1))->length = 5;
+ memcpy((*(data->val1))->data, val1, 5 * sizeof(uInt8));
+
+ ret = PostLVUserEvent(ev, data);
+
+ DSDisposeHandle(data->val1);
+ DSDisposePtr(data);
+ return EPHIDGET_OK;
+}
+LV_CFHANDLE_BODY(RFID, TagLost, lvUInt8Array, void *userPtr, unsigned char *val1)
+ data->val1=(lvArrUInt8DH)DSNewHandle(sizeof(int32)+5*sizeof(uInt8));
+ (*(data->val1))->length = 5;
+ memcpy((*(data->val1))->data, val1, 5 * sizeof(uInt8));
+
+ ret = PostLVUserEvent(ev, data);
+
+ DSDisposeHandle(data->val1);
+ DSDisposePtr(data);
+ return EPHIDGET_OK;
+}
+LV_CFHANDLE_BODY(RFID, RawData, lvInt32Array, void *userPtr, int *val1, int val2)
+ data->val1=(lvArrInt32DH)DSNewHandle(sizeof(int32)+val2*sizeof(int32));
+ (*(data->val1))->length = val2;
+ memcpy((*(data->val1))->data, val1, val2 * sizeof(int32));
+
+ ret = PostLVUserEvent(ev, data);
+
+ DSDisposeHandle(data->val1);
+ DSDisposePtr(data);
+ return EPHIDGET_OK;
+}
+LV_CFHANDLE_BODY(RFID, TagAdvanced, lvRFIDTagAdvanced, void *userPtr, char *val1, CPhidgetRFID_TagInfoHandle val2)
+ data->val1=(LStrHandle)DSNewHandle(sizeof(int32)+255*sizeof(char));
+ memset(LStrBuf(*data->val1),'\0',255);
+ snprintf((char*)LStrBuf(*data->val1),255,"%s",val1);
+ LStrLen(*data->val1)=strlen(val1);
+ data->val2 = *val2;
+
+ ret = PostLVUserEvent(ev, data);
+
+ DSDisposeHandle(data->val1);
+ DSDisposePtr(data);
+ return EPHIDGET_OK;
+}
+LV_CFHANDLE_BODY(RFID, TagLostAdvanced, lvRFIDTagAdvanced, void *userPtr, char *val1, CPhidgetRFID_TagInfoHandle val2)
+ data->val1=(LStrHandle)DSNewHandle(sizeof(int32)+255*sizeof(char));
+ memset(LStrBuf(*data->val1),'\0',255);
+ snprintf((char*)LStrBuf(*data->val1),255,"%s",val1);
+ LStrLen(*data->val1)=strlen(val1);
+ data->val2 = *val2;
+
+ ret = PostLVUserEvent(ev, data);
+
+ DSDisposeHandle(data->val1);
+ DSDisposePtr(data);
+ return EPHIDGET_OK;
+}
+
+LV_CFHANDLE_2(Servo, PositionChange, lvIndexedDouble, int, double)
+
+LV_CFHANDLE_BODY(Spatial,SpatialData,lvSpatialData,void *userPtr,CPhidgetSpatial_SpatialEventDataHandle *val1,int val2)
+ DSDisposePtr(data);
+ {
+ int i;
+ for(i=0;i<val2;i++)
+ {
+ data = (lvSpatialData *)DSNewPtr(sizeof(lvSpatialData));
+ data->nothing = (int32)phid;
+#if 0
+ data->acceleration0 = val1[i]->acceleration[0];
+ data->acceleration1 = val1[i]->acceleration[1];
+ data->acceleration2 = val1[i]->acceleration[2];
+ data->angularRate0 = val1[i]->angularRate[0];
+ data->angularRate1 = val1[i]->angularRate[1];
+ data->angularRate2 = val1[i]->angularRate[2];
+ data->magneticField0 = val1[i]->magneticField[0];
+ data->magneticField1 = val1[i]->magneticField[1];
+ data->magneticField2 = val1[i]->magneticField[2];
+ data->microseconds = val1[i]->timestamp.microseconds;
+ data->seconds = val1[i]->timestamp.seconds;
+#else
+ data->val1 = *val1[i];
+#endif
+ ret = PostLVUserEvent(ev, data);
+ DSDisposePtr(data);
+ }
+ }
+ return EPHIDGET_OK;
+}
+
+LV_CFHANDLE_2(Stepper, InputChange, lvIndexedInt32, int, int)
+LV_CFHANDLE_2(Stepper, PositionChange, lvIndexedInt64, int, __int64)
+LV_CFHANDLE_2(Stepper, PositionChange32, lvIndexedInt32, int, int)
+LV_CFHANDLE_2(Stepper, VelocityChange, lvIndexedDouble, int, double)
+LV_CFHANDLE_2(Stepper, CurrentChange, lvIndexedDouble, int, double)
+
+LV_CFHANDLE_2(TemperatureSensor, TemperatureChange, lvIndexedDouble, int, double)
+
+LV_CFHANDLE_1(WeightSensor, WeightChange, lvDouble, double)
+
+//Manager
+
+int CCONV CPhidgetManager_OnAttach_LaviewHandler(CPhidgetHandle phid, void *userPtr);
+LABVIEW_EXPORT int CCONV CPhidgetManager_set_OnAttach_LabviewHandler(CPhidgetManagerHandle phidA, LVUserEventRef *lvEventRef)
+{
+ CPhidgetManagerHandle phid = (CPhidgetManagerHandle)phidA;
+ TESTPTR(phid);
+ if(!lvEventRef || !*lvEventRef)
+ {
+ phid->fptrAttachChange = NULL;
+ phid->fptrAttachChange = NULL;
+ }
+ else
+ {
+ phid->fptrAttachChangeptr = CPhidgetManager_OnAttach_LaviewHandler;
+ phid->fptrAttachChangeptr = lvEventRef;
+ }
+ return EPHIDGET_OK;
+}
+int CCONV CPhidgetManager_OnAttach_LaviewHandler(CPhidgetHandle phid, void *userPtr)
+{
+ LVUserEventRef ev = *(LVUserEventRef *)userPtr;
+ MgErr ret = 0;
+ lvManager *data;
+ data = (lvManager *)DSNewPtr(sizeof(lvManager));
+ data->val1 = (size_t)phid;
+ LV_CFHANDLE_END
+
+int CCONV CPhidgetManager_OnDetach_LaviewHandler(CPhidgetHandle phid, void *userPtr);
+LABVIEW_EXPORT int CCONV CPhidgetManager_set_OnDetach_LabviewHandler(CPhidgetManagerHandle phidA, LVUserEventRef *lvEventRef)
+{
+ CPhidgetManagerHandle phid = (CPhidgetManagerHandle)phidA;
+ TESTPTR(phid);
+ if(!lvEventRef || !*lvEventRef)
+ {
+ phid->fptrDetachChange = NULL;
+ phid->fptrDetachChange = NULL;
+ }
+ else
+ {
+ phid->fptrDetachChangeptr = CPhidgetManager_OnDetach_LaviewHandler;
+ phid->fptrDetachChangeptr = lvEventRef;
+ }
+ return EPHIDGET_OK;
+}
+int CCONV CPhidgetManager_OnDetach_LaviewHandler(CPhidgetHandle phid, void *userPtr)
+{
+ LVUserEventRef ev = *(LVUserEventRef *)userPtr;
+ MgErr ret = 0;
+ lvManager *data;
+ data = (lvManager *)DSNewPtr(sizeof(lvManager));
+ data->val1 = (size_t)phid;
+ LV_CFHANDLE_END
+
+LV_CFHANDLE_0(Manager, ServerConnect, lvNothing)
+LV_CFHANDLE_0(Manager, ServerDisconnect, lvNothing)
+LV_CFHANDLE_BODY(Manager, Error, lvError, void *userPtr, int val1, const char *val2)
+ data->val1 = val1;
+ data->val2=(LStrHandle)DSNewHandle(sizeof(int32)+255*sizeof(char));
+ memset(LStrBuf(*data->val2),'\0',255);
+ snprintf((char*)LStrBuf(*data->val2),255,"%s",val2);
+ LStrLen(*data->val2)=strlen(val2);
+
+ ret = PostLVUserEvent(ev, data);
+
+ DSDisposeHandle(data->val2);
+ DSDisposePtr(data);
+ return EPHIDGET_OK;
+}
+
+//Dictionary
+
+int CCONV CPhidgetDictionary_OnKeyChange_LaviewHandler(CPhidgetDictionaryHandle dict, void *userPtr, const char *key, const char *value, CPhidgetDictionary_keyChangeReason reason);
+LABVIEW_EXPORT int CCONV CPhidgetDictionary_set_OnKeyChange_LabviewHandler(CPhidgetDictionaryHandle dict, CPhidgetDictionaryListenerHandle *listen, const char *pattern, LVUserEventRef *lvEventRef)
+{
+ TESTPTR(dict);
+ if(lvEventRef && *lvEventRef)
+ CPhidgetDictionary_set_OnKeyChange_Handler(dict, listen, pattern, CPhidgetDictionary_OnKeyChange_LaviewHandler, lvEventRef);
+ else
+ return EPHIDGET_INVALIDARG;
+ return EPHIDGET_OK;
+}
+int CCONV CPhidgetDictionary_OnKeyChange_LaviewHandler(CPhidgetDictionaryHandle dict, void *userPtr, const char *key, const char *value, CPhidgetDictionary_keyChangeReason reason)
+{
+ LVUserEventRef ev = *(LVUserEventRef *)userPtr;
+ MgErr ret = 0;
+ lvDictionary *data;
+
+ data = (lvDictionary *)DSNewPtr(sizeof(lvDictionary));
+
+ //key
+ data->val1=(LStrHandle)DSNewHandle(sizeof(int32)+(strlen(key)+1)*sizeof(char));
+ memset(LStrBuf(*data->val1),'\0',(strlen(key)+1)*sizeof(char));
+ snprintf((char*)LStrBuf(*data->val1),(strlen(key)+1)*sizeof(char),"%s",key);
+ LStrLen(*data->val1)=strlen(key);
+
+ //value
+ data->val2=(LStrHandle)DSNewHandle(sizeof(int32)+(strlen(value)+1)*sizeof(char));
+ memset(LStrBuf(*data->val2),'\0',(strlen(value)+1)*sizeof(char));
+ snprintf((char*)LStrBuf(*data->val2),(strlen(value)+1)*sizeof(char),"%s",value);
+ LStrLen(*data->val2)=strlen(value);
+
+ data->val3 = reason;
+
+ ret = PostLVUserEvent(ev, data);
+
+ DSDisposeHandle(data->val1);
+ DSDisposeHandle(data->val2);
+ DSDisposePtr(data);
+
+ return EPHIDGET_OK;
+}
+LV_CFHANDLE_0(Dictionary, ServerConnect, lvNothing)
+LV_CFHANDLE_0(Dictionary, ServerDisconnect, lvNothing)
+LV_CFHANDLE_BODY(Dictionary, Error, lvError, void *userPtr, int val1, const char *val2)
+ data->val1 = val1;
+ data->val2=(LStrHandle)DSNewHandle(sizeof(int32)+255*sizeof(char));
+ memset(LStrBuf(*data->val2),'\0',255);
+ snprintf((char*)LStrBuf(*data->val2),255,"%s",val2);
+ LStrLen(*data->val2)=strlen(val2);
+
+ ret = PostLVUserEvent(ev, data);
+
+ DSDisposeHandle(data->val2);
+ DSDisposePtr(data);
+ return EPHIDGET_OK;
+}
+
+#else
+//On WindowsCE, we need stubs because they are in the exports.def file
+
+#define LV_NULL_FUNC(pname,param) int CCONV CPhidget##pname##_set_On##param##_LabviewHandler(CPhidget##pname##Handle phidA, void *lvEventRef) { return EPHIDGET_UNSUPPORTED; }
+
+LV_NULL_FUNC(, Attach)
+LV_NULL_FUNC(, Detach)
+LV_NULL_FUNC(, ServerConnect)
+LV_NULL_FUNC(, ServerDisconnect)
+LV_NULL_FUNC(, Error)
+
+LV_NULL_FUNC(Accelerometer, AccelerationChange)
+
+LV_NULL_FUNC(AdvancedServo, PositionChange)
+LV_NULL_FUNC(AdvancedServo, VelocityChange)
+LV_NULL_FUNC(AdvancedServo, CurrentChange)
+
+LV_NULL_FUNC(Bridge, BridgeData)
+
+LV_NULL_FUNC(Encoder, InputChange)
+LV_NULL_FUNC(Encoder, PositionChange)
+
+LV_NULL_FUNC(FrequencyCounter, Count)
+
+LV_NULL_FUNC(GPS, PositionChange)
+LV_NULL_FUNC(GPS, PositionFixStatusChange)
+
+LV_NULL_FUNC(InterfaceKit, InputChange)
+LV_NULL_FUNC(InterfaceKit, OutputChange)
+LV_NULL_FUNC(InterfaceKit, SensorChange)
+
+LV_NULL_FUNC(IR, Code)
+LV_NULL_FUNC(IR, RawData)
+LV_NULL_FUNC(IR, Learn)
+
+LV_NULL_FUNC(MotorControl, InputChange)
+LV_NULL_FUNC(MotorControl, VelocityChange)
+LV_NULL_FUNC(MotorControl, CurrentChange)
+LV_NULL_FUNC(MotorControl, EncoderPositionChange)
+LV_NULL_FUNC(MotorControl, EncoderPositionUpdate)
+LV_NULL_FUNC(MotorControl, BackEMFUpdate)
+LV_NULL_FUNC(MotorControl, SensorUpdate)
+LV_NULL_FUNC(MotorControl, CurrentUpdate)
+
+LV_NULL_FUNC(PHSensor, PHChange)
+
+LV_NULL_FUNC(RFID, OutputChange)
+LV_NULL_FUNC(RFID, Tag)
+LV_NULL_FUNC(RFID, TagLost)
+LV_NULL_FUNC(RFID, RawData)
+LV_NULL_FUNC(RFID, TagAdvanced)
+LV_NULL_FUNC(RFID, TagLostAdvanced)
+
+LV_NULL_FUNC(Servo, PositionChange)
+
+LV_NULL_FUNC(Spatial,SpatialData)
+
+LV_NULL_FUNC(Stepper, InputChange)
+LV_NULL_FUNC(Stepper, PositionChange)
+LV_NULL_FUNC(Stepper, PositionChange32)
+LV_NULL_FUNC(Stepper, VelocityChange)
+LV_NULL_FUNC(Stepper, CurrentChange)
+
+LV_NULL_FUNC(TemperatureSensor, TemperatureChange)
+
+LV_NULL_FUNC(WeightSensor, WeightChange)
+
+LV_NULL_FUNC(Manager, Attach)
+LV_NULL_FUNC(Manager, Detach)
+LV_NULL_FUNC(Manager, ServerConnect)
+LV_NULL_FUNC(Manager, ServerDisconnect)
+LV_NULL_FUNC(Manager, Error)
+
+LV_NULL_FUNC(Dictionary, KeyChange)
+LV_NULL_FUNC(Dictionary, ServerConnect)
+LV_NULL_FUNC(Dictionary, ServerDisconnect)
+LV_NULL_FUNC(Dictionary, Error)
+
+#endif
diff --git a/labview/phidget_labview.h b/labview/phidget_labview.h
new file mode 100644
index 0000000..fa96571
--- /dev/null
+++ b/labview/phidget_labview.h
@@ -0,0 +1,642 @@
+#ifndef __PHLABVIEW
+#define __PHLABVIEW
+#include "cphidget.h"
+
+#ifndef EXTERNALPROTO
+
+#ifdef _WINDOWS
+#include "windows/extcode.h"
+#elif _LINUX
+#include "extcode.h"
+#elif _MACOSX
+#include "macos/2010/extcode.h"
+#endif
+
+#else
+typedef unsigned int LVUserEventRef;
+#endif
+
+#ifdef _WINDOWS
+
+#define LABVIEW_STRUCT_PACK 1
+//#define LABVIEW_EXPORT __declspec(dllexport)
+#define LABVIEW_EXPORT
+
+#pragma pack(push)
+#pragma pack(show)
+
+#else
+
+#define LABVIEW_STRUCT_PACK 4
+#define LABVIEW_EXPORT
+
+#endif
+
+#define LV_CFHANDLE_BODY(pname,param,structtype, ...) \
+int CCONV CPhidget##pname##_On##param##_LaviewHandler(CPhidget##pname##Handle phid, __VA_ARGS__ ); \
+LABVIEW_EXPORT int CCONV CPhidget##pname##_set_On##param##_LabviewHandler(CPhidget##pname##Handle phidA, LVUserEventRef *lvEventRef) \
+{ \
+ CPhidget##pname##Handle phid = (CPhidget##pname##Handle)phidA; \
+ TESTPTR(phid); \
+ if(!lvEventRef || !*lvEventRef) \
+ { \
+ phid->fptr##param = NULL; \
+ phid->fptr##param##ptr = NULL; \
+ } \
+ else \
+ { \
+ phid->fptr##param = CPhidget##pname##_On##param##_LaviewHandler; \
+ phid->fptr##param##ptr = lvEventRef; \
+ } \
+ return EPHIDGET_OK; \
+} \
+int CCONV CPhidget##pname##_On##param##_LaviewHandler(CPhidget##pname##Handle phid, __VA_ARGS__ ) \
+{ \
+ LVUserEventRef ev = *(LVUserEventRef *)userPtr; \
+ MgErr ret = 0; \
+ structtype *data; \
+ data = (structtype *)DSNewPtr(sizeof(structtype)); \
+ data->nothing = (int32)phid; \
+
+#define LV_CFHANDLE_END \
+ ret = PostLVUserEvent(ev, data); \
+ DSDisposePtr(data); \
+ return EPHIDGET_OK; \
+}
+
+#define LV_CFHANDLE_0(pname,param,structtype) \
+ LV_CFHANDLE_BODY(pname,param,structtype,void *userPtr) \
+ LV_CFHANDLE_END
+
+#define LV_CFHANDLE_1(pname,param,structtype,datatype1) \
+ LV_CFHANDLE_BODY(pname,param,structtype,void *userPtr,datatype1 val1) \
+ data->val1 = val1; \
+ LV_CFHANDLE_END
+
+#define LV_CFHANDLE_2(pname,param,structtype,datatype1,datatype2) \
+ LV_CFHANDLE_BODY(pname,param,structtype,void *userPtr,datatype1 val1,datatype2 val2) \
+ data->val1 = val1; \
+ data->val2 = val2; \
+ LV_CFHANDLE_END
+
+#define LV_CFHANDLE_3(pname,param,structtype,datatype1,datatype2,datatype3) \
+ LV_CFHANDLE_BODY(pname,param,structtype,void *userPtr,datatype1 val1,datatype2 val2,datatype3 val3) \
+ data->val1 = val1; \
+ data->val2 = val2; \
+ data->val3 = val3; \
+ LV_CFHANDLE_END
+
+#define LV_CFHANDLE_4(pname,param,structtype,datatype1,datatype2,datatype3,datatype4) \
+ LV_CFHANDLE_BODY(pname,param,structtype,void *userPtr,datatype1 val1,datatype2 val2,datatype3 val3,datatype4 val4) \
+ data->val1 = val1; \
+ data->val2 = val2; \
+ data->val3 = val3; \
+ data->val4 = val4; \
+ LV_CFHANDLE_END
+
+#define LV_CHDREVENT(pname,param) LABVIEW_EXPORT int CCONV CPhidget##pname##_set_On##param##_LabviewHandler(CPhidget##pname##Handle phid, LVUserEventRef *lvEventRef);
+
+/** \defgroup phidlabview Phidget Labview Functions
+ * Calls specific to the Phidget Labview Support.
+ * @{
+ */
+
+/**
+ * Labview 1D int32 Array
+ */
+typedef struct {
+ int32 length; // Length of array
+ int32 data[1]; // Array
+} lvArrInt32, *lvArrInt32H, **lvArrInt32DH;
+
+/**
+ * Labview 1D uInt8 Array
+ */
+typedef struct {
+ int32 length; // Length of array
+ uInt8 data[1]; // Array
+} lvArrUInt8, *lvArrUInt8H, **lvArrUInt8DH;
+
+
+/* pack all of the following structures on Windows
+ * Note: Labview 64-bit seems to want double to be 8-byte aligned,
+ * but 32-bit wants them packed to presumably 4-byte
+ * ints, etc. need to be packed in close.
+ * mac/linux don't need anything special.
+ * http://zone.ni.com/reference/en-XX/help/371361G-01/lvconcepts/how_labview_stores_data_in_memory/
+ */
+#ifdef _WINDOWS
+#pragma pack(LABVIEW_STRUCT_PACK)
+#pragma pack(show)
+#endif
+
+/**
+ * Used for Labview events where only the event sender is returned
+ */
+typedef struct _lvNothing {
+ int32 nothing; /**< Not Used */
+} lvNothing;
+
+/**
+ * Used for Labview events that return an error code/string
+ */
+typedef struct _lvError {
+ int32 nothing; /**< Not Used */
+ int32 val1; /**< Error Code */
+ LStrHandle val2; /**< Error String */
+} lvError;
+
+/**
+ * Used for Labview events that return a double
+ */
+typedef struct _lvDouble {
+//Labview 64-bit windows wants doubles on 8-byte boundaries
+#ifdef _WINDOWS
+ size_t nothing; /**< Not Used */
+#else
+ int32 nothing; /**< Not Used */
+#endif
+ double val1; /**< Value */
+} lvDouble;
+
+/**
+ * Used for Labview events that return 3 doubles
+ */
+typedef struct _lvDoubleDoubleDouble {
+//Labview 64-bit windows wants doubles on 8-byte boundaries
+#ifdef _WINDOWS
+ size_t nothing; /**< Not Used */
+#else
+ int32 nothing; /**< Not Used */
+#endif
+ double val1; /**< Value 1 */
+ double val2; /**< Value 2 */
+ double val3; /**< Value 3 */
+} lvDoubleDoubleDouble;
+
+/**
+ * Used for Labview events that return an int32
+ */
+typedef struct _lvInt32 {
+ int32 nothing; /**< Not Used */
+ int32 val1; /**< Value */
+} lvInt32;
+
+/**
+ * Used for Labview events that return an indexed double
+ */
+typedef struct _lvIndexedDouble {
+ int32 nothing; /**< Not Used */
+ int32 val1; /**< Index */
+ double val2; /**< Value */
+} lvIndexedDouble;
+
+/**
+ * Used for Labview events that return an indexed int32
+ */
+typedef struct _lvIndexedInt32 {
+ int32 nothing; /**< Not Used */
+ int32 val1; /**< Index */
+ int32 val2; /**< Value */
+} lvIndexedInt32;
+
+/**
+ * Used for Labview events that return two indexed int32s
+ */
+typedef struct _lvIndexedInt32Int32 {
+ int32 nothing; /**< Not Used */
+ int32 val1; /**< Index */
+ int32 val2; /**< Value 1 */
+ int32 val3; /**< Value 2 */
+} lvIndexedInt32Int32;
+
+/**
+ * Used for Labview events that return an indexed int64
+ */
+typedef struct _lvIndexedInt64 {
+ int32 nothing; /**< Not Used */
+ int32 val1; /**< Index */
+ int64 val2; /**< Value */
+} lvIndexedInt64;
+
+/**
+ * Used for Labview events that return an int32 array
+ */
+typedef struct _lvInt32Array {
+ lvArrInt32DH val1; /**< Data */
+ int32 nothing; /**< Not Used */
+} lvInt32Array;
+
+/**
+ * Used for Labview events that return an uInt8 array
+ */
+typedef struct _lvUInt8Array {
+ lvArrUInt8DH val1; /**< Data */
+ int32 nothing; /**< Not Used */
+} lvUInt8Array;
+
+/**
+ * Used for Labview events that return an IR Code
+ */
+typedef struct _lvIRCode {
+ lvArrUInt8DH val1; /**< Code data */
+ int32 val2; /**< bit count */
+ int32 val3; /**< repeat */
+ int32 nothing; /**< Not Used */
+} lvIRCode;
+
+/**
+ * Used for Labview events that return IR Learn data
+ */
+typedef struct _lvIRLearn {
+ lvArrUInt8DH val1; /**< Code data */
+ CPhidgetIR_CodeInfo val2; /**< code parameters */
+ int32 nothing; /**< Not Used */
+} lvIRLearn;
+
+/**
+ * Used for Labview events that return an rfid tag (advanced)
+ */
+typedef struct _lvRFIDTagAdvanced {
+ int32 nothing; /**< Not Used */
+ LStrHandle val1; /**< Tag String */
+ CPhidgetRFID_TagInfo val2; /**< tag properties */
+} lvRFIDTagAdvanced;
+
+/**
+ * Used for Labview events that return spatial data
+ */
+typedef struct _lvSpatialData {
+//Labview 64-bit windows wants doubles on 8-byte boundaries
+#ifdef _WINDOWS
+ size_t nothing; /**< Not Used */
+#else
+ int32 nothing; /**< Not Used */
+#endif
+ CPhidgetSpatial_SpatialEventData val1; /**< Spatial Data */
+} lvSpatialData;
+
+
+/**
+ * Used for Labview manager attach and detach events
+ */
+typedef struct _lvManager {
+ __int64 val1; /**< Handle to a phidget */
+} lvManager;
+
+/**
+ * Used for Labview dictionary key change events
+ */
+typedef struct _lvDictionary {
+ LStrHandle val1; /**< key String */
+ LStrHandle val2; /**< value String */
+ CPhidgetDictionary_keyChangeReason val3; /**< key change reason */
+} lvDictionary;
+
+
+#ifdef _WINDOWS
+//Restore default packing
+#pragma pack(pop)
+#pragma pack(show)
+#endif
+
+/**
+ * Sets up a Labview event callback for the Attach event.
+ * Event callback returns an \ref _lvNothing.
+ * @param phid An attached phidget handle.
+ * @param lvEventRef Lavbiew user event ref
+ */
+LV_CHDREVENT(,Attach)
+/**
+ * Sets up a Labview event callback for the Detach event.
+ * Event callback returns an \ref _lvNothing.
+ * @param phid An attached phidget handle.
+ * @param lvEventRef Lavbiew user event ref
+ */
+LV_CHDREVENT(,Detach)
+/**
+ * Sets up a Labview event callback for the ServerConnect event.
+ * Event callback returns an \ref _lvNothing.
+ * @param phid An attached phidget handle.
+ * @param lvEventRef Lavbiew user event ref
+ */
+LV_CHDREVENT(,ServerConnect)
+/**
+ * Sets up a Labview event callback for the ServerDisconnect event.
+ * Event callback returns an \ref _lvNothing.
+ * @param phid An attached phidget handle.
+ * @param lvEventRef Lavbiew user event ref
+ */
+LV_CHDREVENT(,ServerDisconnect)
+/**
+ * Sets up a Labview event callback for the Error event.
+ * Event callback returns an \ref _lvError.
+ * @param phid An attached phidget handle.
+ * @param lvEventRef Lavbiew user event ref
+ */
+LV_CHDREVENT(,Error)
+
+/**
+ * Sets up a Labview event callback for the AccelerationChange event.
+ * Event callback returns an \ref _lvIndexedDouble.
+ * @param phid An attached phidget handle.
+ * @param lvEventRef Lavbiew user event ref
+ */
+LV_CHDREVENT(Accelerometer,AccelerationChange)
+
+/**
+ * Sets up a Labview event callback for the PositionChange event.
+ * Event callback returns an \ref _lvIndexedDouble.
+ * @param phid An attached phidget handle.
+ * @param lvEventRef Lavbiew user event ref
+ */
+LV_CHDREVENT(AdvancedServo, PositionChange)
+/**
+ * Sets up a Labview event callback for the VelocityChange event.
+ * Event callback returns an \ref _lvIndexedDouble.
+ * @param phid An attached phidget handle.
+ * @param lvEventRef Lavbiew user event ref
+ */
+LV_CHDREVENT(AdvancedServo, VelocityChange)
+/**
+ * Sets up a Labview event callback for the CurrentChange event.
+ * Event callback returns an \ref _lvIndexedDouble.
+ * @param phid An attached phidget handle.
+ * @param lvEventRef Lavbiew user event ref
+ */
+LV_CHDREVENT(AdvancedServo, CurrentChange)
+
+/**
+ * Sets up a Labview event callback for the BridgeData event.
+ * Event callback returns an \ref _lvIndexedDouble.
+ * @param phid An attached phidget handle.
+ * @param lvEventRef Lavbiew user event ref
+ */
+LV_CHDREVENT(Bridge, BridgeData)
+
+/**
+ * Sets up a Labview event callback for the InputChange event.
+ * Event callback returns an \ref _lvIndexedInt32.
+ * @param phid An attached phidget handle.
+ * @param lvEventRef Lavbiew user event ref
+ */
+LV_CHDREVENT(Encoder, InputChange)
+/**
+ * Sets up a Labview event callback for the PositionChange event.
+ * Event callback returns an \ref _lvIndexedInt32Int32.
+ * @param phid An attached phidget handle.
+ * @param lvEventRef Lavbiew user event ref
+ */
+LV_CHDREVENT(Encoder, PositionChange)
+
+/**
+ * Sets up a Labview event callback for the Count event.
+ * Event callback returns an \ref _lvIndexedInt32Int32.
+ * @param phid An attached phidget handle.
+ * @param lvEventRef Lavbiew user event ref
+ */
+LV_CHDREVENT(FrequencyCounter, Count)
+
+/**
+ * Sets up a Labview event callback for the PositionChange event.
+ * Event callback returns an \ref _lvDoubleDoubleDouble.
+ * @param phid An attached phidget handle.
+ * @param lvEventRef Lavbiew user event ref
+ */
+LV_CHDREVENT(GPS, PositionChange)
+/**
+ * Sets up a Labview event callback for the PositionFixStatusChange event.
+ * Event callback returns an \ref _lvInt32.
+ * @param phid An attached phidget handle.
+ * @param lvEventRef Lavbiew user event ref
+ */
+LV_CHDREVENT(GPS, PositionFixStatusChange)
+
+/**
+ * Sets up a Labview event callback for the InputChange event.
+ * Event callback returns an \ref _lvIndexedInt32.
+ * @param phid An attached phidget handle.
+ * @param lvEventRef Lavbiew user event ref
+ */
+LV_CHDREVENT(InterfaceKit, InputChange)
+/**
+ * Sets up a Labview event callback for the OutputChange event.
+ * Event callback returns an \ref _lvIndexedInt32.
+ * @param phid An attached phidget handle.
+ * @param lvEventRef Lavbiew user event ref
+ */
+LV_CHDREVENT(InterfaceKit, OutputChange)
+/**
+ * Sets up a Labview event callback for the SensorChange event.
+ * Event callback returns an \ref _lvIndexedInt32.
+ * @param phid An attached phidget handle.
+ * @param lvEventRef Lavbiew user event ref
+ */
+LV_CHDREVENT(InterfaceKit, SensorChange)
+
+/**
+ * Sets up a Labview event callback for the Code event.
+ * Event callback returns an \ref _lvIRCode.
+ * @param phid An attached phidget handle.
+ * @param lvEventRef Lavbiew user event ref
+ */
+LV_CHDREVENT(IR, Code)
+/**
+ * Sets up a Labview event callback for the RawData event.
+ * Event callback returns an \ref _lvIRRawData.
+ * @param phid An attached phidget handle.
+ * @param lvEventRef Lavbiew user event ref
+ */
+LV_CHDREVENT(IR, RawData)
+/**
+ * Sets up a Labview event callback for the Learn event.
+ * Event callback returns an \ref _lvIRLearn.
+ * @param phid An attached phidget handle.
+ * @param lvEventRef Lavbiew user event ref
+ */
+LV_CHDREVENT(IR, Learn)
+
+/**
+ * Sets up a Labview event callback for the InputChange event.
+ * Event callback returns an \ref _lvIndexedInt32.
+ * @param phid An attached phidget handle.
+ * @param lvEventRef Lavbiew user event ref
+ */
+LV_CHDREVENT(MotorControl, InputChange)
+/**
+ * Sets up a Labview event callback for the VelocityChange event.
+ * Event callback returns an \ref _lvIndexedDouble.
+ * @param phid An attached phidget handle.
+ * @param lvEventRef Lavbiew user event ref
+ */
+LV_CHDREVENT(MotorControl, VelocityChange)
+/**
+ * Sets up a Labview event callback for the CurrentChange event.
+ * Event callback returns an \ref _lvIndexedDouble.
+ * @param phid An attached phidget handle.
+ * @param lvEventRef Lavbiew user event ref
+ */
+LV_CHDREVENT(MotorControl, CurrentChange)
+/**
+ * Sets up a Labview event callback for the EncoderPositionChange event.
+ * Event callback returns an \ref _lvIndexedInt32Int32.
+ * @param phid An attached phidget handle.
+ * @param lvEventRef Lavbiew user event ref
+ */
+LV_CHDREVENT(MotorControl, EncoderPositionChange)
+/**
+ * Sets up a Labview event callback for the EncoderPositionUpdate event.
+ * Event callback returns an \ref _lvIndexedInt32.
+ * @param phid An attached phidget handle.
+ * @param lvEventRef Lavbiew user event ref
+ */
+LV_CHDREVENT(MotorControl, EncoderPositionUpdate)
+/**
+ * Sets up a Labview event callback for the BackEMFUpdate event.
+ * Event callback returns an \ref _lvIndexedDouble.
+ * @param phid An attached phidget handle.
+ * @param lvEventRef Lavbiew user event ref
+ */
+LV_CHDREVENT(MotorControl, BackEMFUpdate)
+/**
+ * Sets up a Labview event callback for the SensorUpdate event.
+ * Event callback returns an \ref _lvIndexedInt32.
+ * @param phid An attached phidget handle.
+ * @param lvEventRef Lavbiew user event ref
+ */
+LV_CHDREVENT(MotorControl, SensorUpdate)
+/**
+ * Sets up a Labview event callback for the CurrentUpdate event.
+ * Event callback returns an \ref _lvIndexedDouble.
+ * @param phid An attached phidget handle.
+ * @param lvEventRef Lavbiew user event ref
+ */
+LV_CHDREVENT(MotorControl, CurrentUpdate)
+
+/**
+ * Sets up a Labview event callback for the PHChange event.
+ * Event callback returns an \ref _lvDouble.
+ * @param phid An attached phidget handle.
+ * @param lvEventRef Lavbiew user event ref
+ */
+LV_CHDREVENT(PHSensor, PHChange)
+
+/**
+ * Sets up a Labview event callback for the OutputChange event.
+ * Event callback returns an \ref _lvIndexedInt32.
+ * @param phid An attached phidget handle.
+ * @param lvEventRef Lavbiew user event ref
+ */
+LV_CHDREVENT(RFID, OutputChange)
+/**
+ * Sets up a Labview event callback for the Tag event.
+ * Event callback returns an \ref _lvRFIDTag.
+ * @param phid An attached phidget handle.
+ * @param lvEventRef Lavbiew user event ref
+ */
+LV_CHDREVENT(RFID, Tag)
+/**
+ * Sets up a Labview event callback for the TagLost event.
+ * Event callback returns an \ref _lvRFIDTag.
+ * @param phid An attached phidget handle.
+ * @param lvEventRef Lavbiew user event ref
+ */
+LV_CHDREVENT(RFID, TagLost)
+/**
+ * Sets up a Labview event callback for the RawData event.
+ * Event callback returns an \ref _lvRFIDRawData.
+ * @param phid An attached phidget handle.
+ * @param lvEventRef Lavbiew user event ref
+ */
+LV_CHDREVENT(RFID, RawData)
+/**
+ * Sets up a Labview event callback for the TagAdvanced event.
+ * Event callback returns an \ref _lvRFIDTagAdvanced.
+ * @param phid An attached phidget handle.
+ * @param lvEventRef Lavbiew user event ref
+ */
+LV_CHDREVENT(RFID, TagAdvanced)
+/**
+ * Sets up a Labview event callback for the TagLostAdvanced event.
+ * Event callback returns an \ref _lvRFIDTagAdvanced.
+ * @param phid An attached phidget handle.
+ * @param lvEventRef Lavbiew user event ref
+ */
+LV_CHDREVENT(RFID, TagLostAdvanced)
+
+/**
+ * Sets up a Labview event callback for the PositionChange event.
+ * Event callback returns an \ref _lvIndexedDouble.
+ * @param phid An attached phidget handle.
+ * @param lvEventRef Lavbiew user event ref
+ */
+LV_CHDREVENT(Servo, PositionChange)
+
+/**
+ * Sets up a Labview event callback for the SpatialData event.
+ * Event callback returns an \ref _lvSpatialData.
+ * @param phid An attached phidget handle.
+ * @param lvEventRef Lavbiew user event ref
+ */
+LV_CHDREVENT(Spatial, SpatialData)
+
+/**
+ * Sets up a Labview event callback for the InputChange event.
+ * Event callback returns an \ref _lvIndexedInt32.
+ * @param phid An attached phidget handle.
+ * @param lvEventRef Lavbiew user event ref
+ */
+LV_CHDREVENT(Stepper, InputChange)
+/**
+ * Sets up a Labview event callback for the PositionChange event.
+ * Event callback returns an \ref _lvIndexedInt64.
+ * @param phid An attached phidget handle.
+ * @param lvEventRef Lavbiew user event ref
+ */
+LV_CHDREVENT(Stepper, PositionChange)
+LV_CHDREVENT(Stepper, PositionChange32)
+/**
+ * Sets up a Labview event callback for the VelocityChange event.
+ * Event callback returns an \ref _lvIndexedDouble.
+ * @param phid An attached phidget handle.
+ * @param lvEventRef Lavbiew user event ref
+ */
+LV_CHDREVENT(Stepper, VelocityChange)
+/**
+ * Sets up a Labview event callback for the CurrentChange event.
+ * Event callback returns an \ref _lvIndexedDouble.
+ * @param phid An attached phidget handle.
+ * @param lvEventRef Lavbiew user event ref
+ */
+LV_CHDREVENT(Stepper, CurrentChange)
+
+/**
+ * Sets up a Labview event callback for the TemperatureChange event.
+ * Event callback returns an \ref _lvIndexedDouble.
+ * @param phid An attached phidget handle.
+ * @param lvEventRef Lavbiew user event ref
+ */
+LV_CHDREVENT(TemperatureSensor, TemperatureChange)
+
+/**
+ * Sets up a Labview event callback for the WeightChange event.
+ * Event callback returns an \ref _lvDouble.
+ * @param phid An attached phidget handle.
+ * @param lvEventRef Lavbiew user event ref
+ */
+LV_CHDREVENT(WeightSensor, WeightChange)
+
+LV_CHDREVENT(Manager,Attach)
+LV_CHDREVENT(Manager,Detach)
+LV_CHDREVENT(Manager,ServerConnect)
+LV_CHDREVENT(Manager,ServerDisconnect)
+LV_CHDREVENT(Manager,Error)
+
+LABVIEW_EXPORT int CCONV CPhidgetDictionary_set_OnKeyChange_LabviewHandler(CPhidgetDictionaryHandle dict, CPhidgetDictionaryListenerHandle *listen, const char *pattern, LVUserEventRef *lvEventRef);
+LV_CHDREVENT(Dictionary,ServerConnect)
+LV_CHDREVENT(Dictionary,ServerDisconnect)
+LV_CHDREVENT(Dictionary,Error)
+
+/** @} */
+
+#endif