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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
|
#ifndef __CPHIDGETFREQUENCYCOUNTER
#define __CPHIDGETFREQUENCYCOUNTER
#include "cphidget.h"
/** \defgroup phidfreq Phidget Frequency Counter
* \ingroup phidgets
* These calls are specific to the Phidget Frequency Counter object. See your device's User Guide for more specific API details, technical information, and revision details. The User Guide, along with other resources, can be found on the product page for your device.
*
* @{
*/
/**
* Filter Types supported by the frequency counter.
*/
typedef enum {
PHIDGET_FREQUENCYCOUNTER_FILTERTYPE_ZERO_CROSSING = 1, /**< Zero crossing signal filter. */
PHIDGET_FREQUENCYCOUNTER_FILTERTYPE_LOGIC_LEVEL, /**< Logic level signal filter. */
PHIDGET_FREQUENCYCOUNTER_FILTERTYPE_UNKNOWN /**< Filter type unknown. */
} CPhidgetFrequencyCounter_FilterType;
DPHANDLE(FrequencyCounter)
CHDRSTANDARD(FrequencyCounter)
/**
* Gets the number of inputs supported by this phidget frequency counter.
* @param phid An attached phidget frequency counter handle.
* @param count The input count.
*/
CHDRGET(FrequencyCounter,FrequencyInputCount,int *count)
/**
* Gets the measured frequency of an input, in Hz.
* @param phid An attached phidget frequency counter handle.
* @param index The input index.
* @param frequency The frequency.
*/
CHDRGETINDEX(FrequencyCounter,Frequency,double *frequency)
/**
* Gets the total time that has passed since the last reset on this input, in microseconds.
* @param phid An attached phidget frequency counter handle.
* @param index The input index.
* @param time The time.
*/
CHDRGETINDEX(FrequencyCounter,TotalTime,__int64 *time)
/**
* Gets the total number of ticks that have happened since the last reset on this input.
* @param phid An attached phidget frequency counter handle.
* @param index The input index.
* @param count The tick count.
*/
CHDRGETINDEX(FrequencyCounter,TotalCount,__int64 *count)
/**
* Gets the timeout value for an input, in microseconds. This controls the lowest measurable frequency.
* @param phid An attached phidget frequency counter handle.
* @param index The input index.
* @param timeout The timeout.
*/
CHDRSETINDEX(FrequencyCounter,Timeout,int timeout)
/**
* Sets the timeout value for an input, in microseconds.
* @param phid An attached phidget frequency counter handle.
* @param index The input index.
* @param timeout The timeout.
*/
CHDRGETINDEX(FrequencyCounter,Timeout,int *timeout)
/**
* Gets the enabled state for an input.
* @param phid An attached phidget frequency counter handle.
* @param index The input index.
* @param enabledState The enabled state.
*/
CHDRSETINDEX(FrequencyCounter,Enabled,int enabledState)
/**
* Sets the enabled state for an input.
* @param phid An attached phidget frequency counter handle.
* @param index The input index.
* @param enabledState The enabled state.
*/
CHDRGETINDEX(FrequencyCounter,Enabled,int *enabledState)
/**
* Gets the filter type for an input.
* @param phid An attached phidget frequency counter handle.
* @param index The input index.
* @param filter The filter type.
*/
CHDRSETINDEX(FrequencyCounter,Filter,CPhidgetFrequencyCounter_FilterType filter)
/**
* Sets the filter type for an input.
* @param phid An attached phidget frequency counter handle.
* @param index The input index.
* @param filter The filter type.
*/
CHDRGETINDEX(FrequencyCounter,Filter,CPhidgetFrequencyCounter_FilterType *filter)
/**
* Resets total count and total time for an input.
* @param phid An attached phidget frequency counter handle.
* @param index The input index.
*/
PHIDGET21_API int CCONV CPhidgetFrequencyCounter_reset(CPhidgetFrequencyCounterHandle phid, int index);
/**
* Sets a count event handler. This is called when ticks have been counted on an input, or when the timeout has passed.
* @param phid A phidget frequency counter handle.
* @param fptr Callback function pointer.
* @param userPtr A pointer for use by the user - this value is passed back into the callback function.
*/
CHDREVENTINDEX(FrequencyCounter,Count,int time,int counts)
#ifndef EXTERNALPROTO
CHDRGETINDEX(FrequencyCounter,TotalTime32,int *time)
CHDRGETINDEX(FrequencyCounter,TotalCount32,int *count)
#define FREQCOUNTER_MAXINPUTS 2
#define FREQCOUNTER_TICKS_PER_SEC 100000
#define FREQCOUNTER_MICROSECONDS_PER_TICK (1000000 / FREQCOUNTER_TICKS_PER_SEC)
//OUT packet flags
#define FREQCOUNTER_FLAG_CH1_LOGIC 0x01
#define FREQCOUNTER_FLAG_CH0_LOGIC 0x02
#define FREQCOUNTER_FLAG_CH1_ENABLE 0x04
#define FREQCOUNTER_FLAG_CH0_ENABLE 0x08
struct _CPhidgetFrequencyCounter {
CPhidget phid;
int (CCONV *fptrCount)(CPhidgetFrequencyCounterHandle, void *, int, int, int);
void *fptrCountptr;
int timeout[FREQCOUNTER_MAXINPUTS]; //microseconds
CPhidgetFrequencyCounter_FilterType filter[FREQCOUNTER_MAXINPUTS];
unsigned char enabled[FREQCOUNTER_MAXINPUTS];
CPhidgetFrequencyCounter_FilterType filterEcho[FREQCOUNTER_MAXINPUTS];
unsigned char enabledEcho[FREQCOUNTER_MAXINPUTS];
double frequency[FREQCOUNTER_MAXINPUTS]; //Hz
int totalTicksSinceLastCount[FREQCOUNTER_MAXINPUTS]; //ticks
__int64 totalCount[FREQCOUNTER_MAXINPUTS];
__int64 totalTime[FREQCOUNTER_MAXINPUTS]; //microseconds
int flip[FREQCOUNTER_MAXINPUTS];
int lastPacketCount;
CThread_mutex_t resetlock; /* protects reset */
int countsGood[FREQCOUNTER_MAXINPUTS]; //for webservice
unsigned char outputPacket[MAX_OUT_PACKET_SIZE];
unsigned int outputPacketLen;
} typedef CPhidgetFrequencyCounterInfo;
#endif
/** @} */
#endif
|