PhidgetTemperatureSensor Class
The PhidgetTemperatureSensor class allows you receive data from PhidgetTemperatureSensor
boards.
As of this writing, this class has only been tested with a 1048_0 - PhidgetTemperatureSensor 4-input, but should be compatible with any PhidgetTemperatureSensor board.
var PhidgetTemperatureSensor = require('phidgets').PhidgetTemperatureSensor;
var pts = new PhidgetTemperatureSensor();
function onReady() {
var inputIndex = 0;
// set the ThermocoupleType to K
pts.setThermocoupleType(inputIndex, PhidgetTemperatureSensor.THERMOCOUPLE_TYPES.TYPE_K);
// receive temperature events when the temperature changes by at least 2 degrees Celsius
// (default is 0.5)
pts.setTemperatureChangeTrigger(inputIndex, 2);
pts.on('temperature', function (emitter, data) {
if (data.index === inputIndex) {
console.log('Temperature: ' + data.value);
}
});
}
pts.addListener('opened', onReady);
pts.open();
This object extends the Phidget object which itself extends Node.js'
events.EventEmitter object.
See that object's documentation for more inherited methods and properties.
Constructor
PhidgetTemperatureSensor
()
Item Index
Methods
Properties
Methods
_forceBetween
-
value -
min -
max
Returns the value after making sure it falls between min and max.
Parameters:
-
valueInt | NumberThe value to check
-
minIntThe minimum value desired
-
maxIntThe maximum value desired
Returns:
int
_handleData
-
chunk
This function is called each time data is received from the Phidget WebSerice. It adds
the data to the input buffer and checks if full lines (separated by '\n') can be
reconstructed. If full lines are found they are handed over to the _parseLineInput()
method for processing.
Parameters:
-
chunkStringA chunk of utf8 encoded text to parse
_makePckString
-
keyword -
[index]
Returns a /PCK string built from the specified parameters. PCK strings are the keys sent out to control the board.
Parameters:
-
keywordStringThe operation keyword to use
-
[index]Int optionalThe index of the output to use
_parseLineInput
-
line
Parses a single line of data typically received from the Phidget WebService. If the
line is a report line, the function hands it off to the _parsePskKey() method.
Otherwise, it deals with it locally.
Parameters:
-
lineStringA non-terminated line of utf8 text
_parsePhidgetSpecificData
-
data
Parses Phidget-specific data received from the Phidget WebService. This function is meant to be overridden by subclasses.
Parameters:
-
dataObjectAn object containing the received data
-
deviceStringThe device identifier (e.g. PhidgetInterfaceKey, PhidgetLED, etc.).
-
labelStringThe custom label set for the device.
-
serialIntThe serial number of the device.
-
keywordStringA keyword identifying the type of information conveyed. It could be 'Input', 'Version', 'DataRate', etc.
-
indexIntThe numerical index (for indexed keys only)
-
valueStringThe actual value.
-
statusStringThe status of the key. It could be: 'added', 'changed', 'removing', etc.
-
_sendLine
-
line
Sends a line of data to the webservice
Parameters:
-
lineStringA non-terminated line of data to send
_sendPck
-
key -
value -
[persistent=false]
Sends the /PCK string (with attached value) to the webservice.
_setPhidgetSpecificInitialState
()
protected
Sets phidget-specific state before the 'opened' event is triggered. This is a good place for subclasses to assign initial values to the board. This is meant to be overridden by subclasses.
addListener
-
event -
listener
This is an alias for the on() method.
close
()
Phidget
chainable
Closes a previously opened connection to a Phidget device.
Returns:
Returns the Phidget to allow method chaining.
on
-
event -
listener
Adds a listener to the end of the listeners array for the specified event. No checks are made to see if the listener has already been added. Multiple calls passing the same combination of event and listener will result in the listener being added multiple times.
This method is inherited from Node.js'
events.EventEmitter object.
See that object's documentation for more details methods.
once
-
event -
listener
Adds a one time listener for the event. This listener is invoked only the next time the event is fired, after which it is removed.
This method is inherited from Node.js'
events.EventEmitter object.
See that object's documentation for more details methods.
open
-
[options={}]
Opens a connection to a Phidget device. Opening a connection is a two-step process. First, a connection to the Phidget WebService (which must be running) is established. Then, a session to the specified device (which must be plugged in) is opened.
Parameters:
-
[options={}]Object optionalOptions
Returns:
Returns the Phidget to allow method chaining.
removeAllListeners
-
[event]
Removes all listeners, or those of the specified event.
This method is inherited from Node.js'
events.EventEmitter object.
See that object's documentation for more details methods.
Parameters:
-
[event]String optionalThe event to remove the listeners for.
removeListener
-
[event] -
listener
Removes a listener from the listener array for the specified event. removeListener()
will remove, at most, one instance of a listener from the listener array. If any single
listener has been added multiple times to the listener array for the specified event,
then removeListener() must be called multiple times to remove each instance.
This method is inherited from Node.js'
events.EventEmitter object.
See that object's documentation for more details methods.
setTemperatureChangeTrigger
-
index -
value
Sets the change trigger for an input. This is the amount by which the sensed temperature must change between temperature change events. By default this is set to 0.5. Setting trigger to 0 will cause all temperature updates to fire events. This is helpful for applications that are implementing their own filtering.
Parameters:
Returns:
Returns the PhidgetTemperatureSensor to allow method chaining.
setThermocoupleType
-
index -
value
Sets the thermocouple type for an input. The possible values are 'J', 'K', 'E', and 'T', or one of the values in the PhidgetTemperatureSensor.THERMOCOUPLE_TYPES enum. Support for other thermocouple types, and voltage sources other than thermocouples in the valid range (between potentialMin and potentialMax) can be achieved using potential.
Parameters:
Returns:
Returns the PhidgetTemperatureSensor to allow method chaining.
Properties
ambientTemperature
Number
[read-only] The last known ambient temperature of the sensor (where the inputs connect to the board), in degrees celsius.
ambientTemperatureMax
Number
[read-only] The highest possible ambient temperature value which can be returned by the sensor, in degrees celsius.
ambientTemperatureMin
Number
[read-only] The lowest possible ambient temperature value which can be returned by the sensor, in degrees celsius.
inputs
Object
[read-only] An object containing data about each input on the device.
Sub-properties:
-
countIntThe number of inputs available on the device.
-
inputs[int].temperatureNumberThe input's last known temperature in degrees celsius.
-
inputs[int].temperatureMaxNumberThe highest temperature possible for the given input, based on thermocouple type.
-
inputs[int].temperatureMinNumberThe lowest temperature possible for the given input, based on thermocouple type.
-
inputs[int].triggerNumberThe input's temperature change trigger, in degrees celsius.
-
inputs[int].potentialNumberThe input's last known voltage.
-
inputs[int].potentialMaxNumberThe highest voltage possible for the given input, based on thermocouple type.
-
inputs[int].potentialMinNumberThe lowest voltage possible for the given input, based on thermocouple type.
-
inputs[int].thermocoupleTypeIntThe type of thermocouple attached to the given input. Value corresponds to a value from PhidgetTemperatureSensor.THERMOCOUPLE_TYPES.
interReportPeriod
Int
The delay (in milliseconds) between report updates sent from the webservice.
Default: 8
label
String
The unique label of the device. The label must have a maximum length of 10 characters. If you try to set a longer label, the remainder will be truncated. Labels are supported only on newer devices and are remembered even when the device is unplugged. A label can only be set after a Phidget has been 'opened'. Trying to set the label before that will fail silently.
Default: undefined
name
String
[read-only] Human-readable version of the board's name (i.e. "Phidget InterfaceKit 8/8/8". This information is only available some time after the connection has been successfully opened.
Default: undefined
password
String
private
The password to connect to the WebService. If specified, it will be used when opening a new connection. As soon as connected the password property will be erased. THIS IS CURRENTLY SET TO PRIVATE BECAUSE IT'S NOT IMPLEMENTED YET!
Default: undefined
port
Int
The port of the Phidgets webservice to connect to.
Default: 5001
ready
Boolean
[read-only] Whether the device is ready for use or not. A device must be 'opened' before it can be used.
reopen
Boolean
Whether to try to automatically reopen the device if it gets remotely closed.
Default: true
serial
Int
The unique serial number of the device. If specified, it will be used to connect to the matching device.
Default: undefined
serverId
Int
[read-only] The unique ID of the Phidget WebService the device is currently connected to.
Default: undefined
THERMOCOUPLE_TYPES
Object
[read-only] An enum of supported thermocouple types. Support for other thermocouple types, and voltage sources other than thermocouples in the valid range (between potentialMin and potentialMax) can be achieved using potential.
Sub-properties:
-
TYPE_KIntInteger value represent a K-type thermocouple.
-
TYPE_JIntInteger value represent a J-type thermocouple.
-
TYPE_EIntInteger value represent a E-type thermocouple.
-
TYPE_TIntInteger value represent a T-type thermocouple.
version
String
[read-only] This number distinguishes between revisions of a specific type of Phidget. It is only useful for debugging purposes. This information is only available some time after the connection has been successfully opened.
Default: undefined
Events
ambientTemperature
The sensor's ambient temperature has changed.
Event Payload:
-
emitterPhidgetTemperatureSensorThe actual PhidgetTemperatureSensor object that emitted the event.
-
dataObjectAn object containing the sensor data and related information
-
valueNumberThe sensor's new ambient temperature.
-
closed
Event emitted when the connection to a phidget has been remotely closed.
Event Payload:
-
emitterPhidgetThe actual object that emitted the event.
error
Event emitted when an error occurs while trying to open a phidget
opened
Event emitted when a phidget is successfully opened.
Event Payload:
-
emitterPhidgetThe actual Phidget object that emitted the event.
opening
Event emitted when an attempt to open a Phidget has been initiated.
Event Payload:
-
emitterPhidgetThe actual Phidget object that emitted the event.
potential
The potential (voltage) of the given input has changed.
Event Payload:
-
emitterPhidgetTemperatureSensorThe actual PhidgetTemperatureSensor object that emitted the event.
-
dataObjectAn object containing the sensor data and related information
-
indexIntThe input's index number
-
valueNumberThe input's new potential.
-
received
private
Event emitted when a new line of data has been received from the web service. This is mostly useful for debugging purposes (hence the @private denomination). It will let you view all data coming in.
reopening
Event emitted when an attempt to automatically re-open a closed Phidget is being carried on.
sent
private
Event emitted when a new line of data has been sent to the Phidget WebService. This is mostly useful for debugging purposes (hence the @private denomination). It will let you view all data going out.
temperature
The calculated temperature of the given input has changed by more than temperatureChangeTrigger. This value is dependent on the sensor's ambient temperature, the input's thermocouple type, and the input's potential.
Event Payload:
-
emitterPhidgetTemperatureSensorThe actual PhidgetTemperatureSensor object that emitted the event.
-
dataObjectAn object containing the sensor data and related information
-
indexIntThe input's index number
-
valueNumberThe input's new temperature.
-
timeout
Event emitted when an attempt to open a Phidget times out.
Event Payload:
-
emitterPhidgetThe actual Phidget object that emitted the event.
