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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
|
/*
* Copyright 2006 Phidgets Inc. All rights reserved.
*/
package com.phidgets;
import java.util.Iterator;
import java.util.LinkedList;
import com.phidgets.event.*;
/**
* This class represents a Phidget temperature Sensor. All methods
* to read temperaure data from the sensor are implemented in this class.
* <p>
* The Temperature Phidget consists of a thermocouple interface, and a temperature
* sensing IC, which is used to measure the temperature of the thermocouple cold junction
* and calibrate the thermocouple sensed temperature.
* <p>
* Both the thermocouple and temperature IC temperatures can be read. Value are returned in degrees celcius.
*
* @author Phidgets Inc.
*/
public final class TemperatureSensorPhidget extends Phidget
{
public TemperatureSensorPhidget () throws PhidgetException
{
super (create ());
}
private static native long create () throws PhidgetException;
/**
* K-Type Thermocouple. This is used with {@link #getThermocoupleType getThermocoupleType} and {@link #setThermocoupleType setThermocoupleType}
*/
public static final int PHIDGET_TEMPERATURE_SENSOR_K_TYPE = 1;
/**
* J-Type Thermocouple. This is used with {@link #getThermocoupleType getThermocoupleType} and {@link #setThermocoupleType setThermocoupleType}
*/
public static final int PHIDGET_TEMPERATURE_SENSOR_J_TYPE = 2;
/**
* E-Type Thermocouple. This is used with {@link #getThermocoupleType getThermocoupleType} and {@link #setThermocoupleType setThermocoupleType}
*/
public static final int PHIDGET_TEMPERATURE_SENSOR_E_TYPE = 3;
/**
* T-Type Thermocouple. This is used with {@link #getThermocoupleType getThermocoupleType} and {@link #setThermocoupleType setThermocoupleType}
*/
public static final int PHIDGET_TEMPERATURE_SENSOR_T_TYPE = 4;
/**
* Returns the number of thermocouples.
* @return Number of inputs
*/
public native int getTemperatureInputCount () throws PhidgetException;
/**
* @deprecated Replaced by
* {@link #getTemperatureInputCount}
*/
public native int getSensorCount () throws PhidgetException;
/**
* Returns the temperature of a thermocouple. This value is returned in degrees celcius but can easily be converted into other units.
* This value will always be between {@link #getTemperatureMin getTemperatureMin} and {@link #getTemperatureMax getTemperatureMax}.
* The accuracy depends on the thermocouple used. The board is calibrated during manufacture.
* @param index Index of the thermocouple
* @return Temperature in derees celcius
* @throws PhidgetException If this Phidget is not opened and attached, or if a thermocouple sensor is not plugged into the board.
* See {@link com.phidgets.Phidget#open(int) open} for information on determining if a device is attached.
*/
public native double getTemperature (int index) throws PhidgetException;
/**
* Returns the maximum temperature that will be returned by a thermocouple input. This value depends on the thermocouple type.
* @param index Index of the thermocouple
* @return Maximum temperature in derees celcius
* @throws PhidgetException If this Phidget is not opened and attached.
* See {@link com.phidgets.Phidget#open(int) open} for information on determining if a device is attached.
*/
public native double getTemperatureMax (int index) throws PhidgetException;
/**
* Returns the minimum temperature that will be returned by a thermocouple input. This value depends on the thermocouple type.
* @param index Index of the thermocouple
* @return Minimum temperature in derees celcius
* @throws PhidgetException If this Phidget is not opened and attached.
* See {@link com.phidgets.Phidget#open(int) open} for information on determining if a device is attached.
*/
public native double getTemperatureMin (int index) throws PhidgetException;
/**
* Returns the temperature of the ambient sensor. This value is returned in degrees celcius but can easily be converted into other units.
* This value will always be between {@link #getAmbientTemperatureMin getAmbientTemperatureMin} and {@link #getAmbientTemperatureMax getAmbientTemperatureMax}.
* This is the temperature of the board at the thermocouple cold junction.
* @return Temperature in derees celcius
* @throws PhidgetException If this Phidget is not opened and attached.
* See {@link com.phidgets.Phidget#open(int) open} for information on determining if a device is attached.
*/
public native double getAmbientTemperature () throws PhidgetException;
/**
* Returns the maximum temperature that will be returned by the ambient sensor.
* @return Maximum ambient temperature in derees celcius
* @throws PhidgetException If this Phidget is not opened and attached.
* See {@link com.phidgets.Phidget#open(int) open} for information on determining if a device is attached.
*/
public native double getAmbientTemperatureMax () throws PhidgetException;
/**
* Returns the minimum temperature that will be returned by the ambient sensor.
* @return Minimum ambient temperature in derees celcius
* @throws PhidgetException If this Phidget is not opened and attached.
* See {@link com.phidgets.Phidget#open(int) open} for information on determining if a device is attached.
*/
public native double getAmbientTemperatureMin () throws PhidgetException;
/**
* Returns the potential of a thermocouple input. This value is returned in millivolts.
* This value will always be between {@link #getPotentialMin getPotentialMin} and {@link #getPotentialMax getPotentialMax}.
* This is very accurate, as it is a raw value from the A/D. This is the value that is internally used to calculate temperature in the library.
* @param index Index of the thermocouple
* @return Potential in millivolts
* @throws PhidgetException If this Phidget is not opened and attached.
* See {@link com.phidgets.Phidget#open(int) open} for information on determining if a device is attached.
*/
public native double getPotential (int index) throws PhidgetException;
/**
* Returns the maximum potential that will be returned by a thermocouple input.
* @param index Index of the thermocouple
* @return Maximum potential in millivolts
* @throws PhidgetException If this Phidget is not opened and attached.
* See {@link com.phidgets.Phidget#open(int) open} for information on determining if a device is attached.
*/
public native double getPotentialMax (int index) throws PhidgetException;
/**
* Returns the minimum potential that will be returned by a thermocouple input.
* @param index Index of the thermocouple
* @return Minimum potential in millivolts
* @throws PhidgetException If this Phidget is not opened and attached.
* See {@link com.phidgets.Phidget#open(int) open} for information on determining if a device is attached.
*/
public native double getPotentialMin (int index) throws PhidgetException;
/**
* Sets the change trigger for an input. This is the ammount by which the sensed temperature must
* change between TemperatureChangeEvents. By default this is set to 0.5.
* @param index Input
* @param newVal Trigger
* @throws PhidgetException If this Phidget is not opened and attached, or if the index is out of range.
* See {@link com.phidgets.Phidget#open(int) open} for information on determining if a device is attached.
*/
public native void setTemperatureChangeTrigger (int index, double newVal) throws PhidgetException;
/**
* Returns the change trigger for an input. This is the ammount by which the sensed temperature must
* change between TemperatureChangeEvents. By default this is set to 0.5.
* @param index Input
* @return Trigger
* @throws PhidgetException If this Phidget is not opened and attached, or if the index is out of range.
* See {@link com.phidgets.Phidget#open(int) open} for information on determining if a device is attached.
*/
public native double getTemperatureChangeTrigger (int index) throws PhidgetException;
/**
* Returns the thermocouple type for an input.
* The possible values for type are {@link #PHIDGET_TEMPERATURE_SENSOR_K_TYPE PHIDGET_TEMPERATURE_SENSOR_K_TYPE},
* {@link #PHIDGET_TEMPERATURE_SENSOR_J_TYPE PHIDGET_TEMPERATURE_SENSOR_J_TYPE}, {@link #PHIDGET_TEMPERATURE_SENSOR_E_TYPE PHIDGET_TEMPERATURE_SENSOR_E_TYPE} and
* {@link #PHIDGET_TEMPERATURE_SENSOR_T_TYPE PHIDGET_TEMPERATURE_SENSOR_T_TYPE}
* @param index Input
* @return Thermocouple Type
* @throws PhidgetException If this Phidget is not opened and attached, or if the index is out of range.
* See {@link com.phidgets.Phidget#open(int) open} for information on determining if a device is attached.
*/
public native int getThermocoupleType (int index) throws PhidgetException;
/**
* Sets the thermocouple type for an input. The Phidget Temperature Sensor board can be used with K, E, J and T-Type Thermocouples.
* Support for other thermocouple types, and voltage sources other then thermocouples in the valid range (between {@link #getPotentialMin getPotentialMin} and {@link #getPotentialMax getPotentialMax}) can
* be achieved using {@link #getPotential getPotential}.
* <p>
* The possible values for type are {@link #PHIDGET_TEMPERATURE_SENSOR_K_TYPE PHIDGET_TEMPERATURE_SENSOR_K_TYPE},
* {@link #PHIDGET_TEMPERATURE_SENSOR_J_TYPE PHIDGET_TEMPERATURE_SENSOR_J_TYPE}, {@link #PHIDGET_TEMPERATURE_SENSOR_E_TYPE PHIDGET_TEMPERATURE_SENSOR_E_TYPE} and
* {@link #PHIDGET_TEMPERATURE_SENSOR_T_TYPE PHIDGET_TEMPERATURE_SENSOR_T_TYPE}
* <p>
* By default, type is set to {@link #PHIDGET_TEMPERATURE_SENSOR_K_TYPE PHIDGET_TEMPERATURE_SENSOR_K_TYPE}.
* @param index Input
* @param type Thermocouple Type
* @throws PhidgetException If this Phidget is not opened and attached, or if the index is out of range.
* See {@link com.phidgets.Phidget#open(int) open} for information on determining if a device is attached.
*/
public native void setThermocoupleType (int index, int type) throws PhidgetException;
private final void enableDeviceSpecificEvents (boolean b)
{
enableTemperatureChangeEvents (b && temperatureChangeListeners.size () > 0);
}
/**
* Adds a temperature change listener. The temperature change handler is a method that will be called when the temperature
* has changed by at least the {@link #getTemperatureChangeTrigger(int) Trigger} that has been set.
* <p>
* There is no limit on the number of temperature change handlers that can be registered for a particular Phidget.
*
* @param l An implemetation of the {@link com.phidgets.event.TemperatureChangeListener TemperatureChangeListener} interface
*/
public final void addTemperatureChangeListener (TemperatureChangeListener l)
{
synchronized (temperatureChangeListeners)
{
temperatureChangeListeners.add (l);
enableTemperatureChangeEvents (true);
}} private LinkedList temperatureChangeListeners = new LinkedList ();
private long nativeTemperatureChangeHandler = 0;
public final void removeTemperatureChangeListener (TemperatureChangeListener l)
{
synchronized (temperatureChangeListeners)
{
temperatureChangeListeners.remove (l);
enableTemperatureChangeEvents (temperatureChangeListeners.size () > 0);
}} private void fireTemperatureChange (TemperatureChangeEvent e)
{
synchronized (temperatureChangeListeners)
{
for (Iterator it = temperatureChangeListeners.iterator (); it.hasNext ();)
((TemperatureChangeListener) it.next ()).temperatureChanged (e);
}
}
private native void enableTemperatureChangeEvents (boolean b);
}
|