Class: Tinkerforge::BrickletThermocouple

Inherits:
Device
  • Object
show all
Defined in:
lib/tinkerforge/bricklet_thermocouple.rb

Overview

Measures temperature with thermocouples

Constant Summary collapse

DEVICE_IDENTIFIER =

:nodoc:

266
DEVICE_DISPLAY_NAME =

:nodoc:

'Thermocouple Bricklet'
CALLBACK_TEMPERATURE =

This callback is triggered periodically with the period that is set by BrickletThermocouple#set_temperature_callback_period. The parameter is the temperature of the thermocouple.

The CALLBACK_TEMPERATURE callback is only triggered if the temperature has changed since the last triggering.

8
CALLBACK_TEMPERATURE_REACHED =

This callback is triggered when the threshold as set by BrickletThermocouple#set_temperature_callback_threshold is reached. The parameter is the temperature of the thermocouple.

If the threshold keeps being reached, the callback is triggered periodically with the period as set by BrickletThermocouple#set_debounce_period.

9
CALLBACK_ERROR_STATE =

This Callback is triggered every time the error state changes (see BrickletThermocouple#get_error_state).

13
FUNCTION_GET_TEMPERATURE =

:nodoc:

1
FUNCTION_SET_TEMPERATURE_CALLBACK_PERIOD =

:nodoc:

2
FUNCTION_GET_TEMPERATURE_CALLBACK_PERIOD =

:nodoc:

3
FUNCTION_SET_TEMPERATURE_CALLBACK_THRESHOLD =

:nodoc:

4
FUNCTION_GET_TEMPERATURE_CALLBACK_THRESHOLD =

:nodoc:

5
FUNCTION_SET_DEBOUNCE_PERIOD =

:nodoc:

6
FUNCTION_GET_DEBOUNCE_PERIOD =

:nodoc:

7
FUNCTION_SET_CONFIGURATION =

:nodoc:

10
FUNCTION_GET_CONFIGURATION =

:nodoc:

11
FUNCTION_GET_ERROR_STATE =

:nodoc:

12
FUNCTION_GET_IDENTITY =

:nodoc:

255
THRESHOLD_OPTION_OFF =

:nodoc:

'x'
THRESHOLD_OPTION_OUTSIDE =

:nodoc:

'o'
THRESHOLD_OPTION_INSIDE =

:nodoc:

'i'
THRESHOLD_OPTION_SMALLER =

:nodoc:

'<'
THRESHOLD_OPTION_GREATER =

:nodoc:

'>'
AVERAGING_1 =

:nodoc:

1
AVERAGING_2 =

:nodoc:

2
AVERAGING_4 =

:nodoc:

4
AVERAGING_8 =

:nodoc:

8
AVERAGING_16 =

:nodoc:

16
TYPE_B =

:nodoc:

0
TYPE_E =

:nodoc:

1
TYPE_J =

:nodoc:

2
TYPE_K =

:nodoc:

3
TYPE_N =

:nodoc:

4
TYPE_R =

:nodoc:

5
TYPE_S =

:nodoc:

6
TYPE_T =

:nodoc:

7
TYPE_G8 =

:nodoc:

8
TYPE_G32 =

:nodoc:

9
FILTER_OPTION_50HZ =

:nodoc:

0
FILTER_OPTION_60HZ =

:nodoc:

1

Constants inherited from Device

Device::DEVICE_IDENTIFIER_CHECK_MATCH, Device::DEVICE_IDENTIFIER_CHECK_MISMATCH, Device::DEVICE_IDENTIFIER_CHECK_PENDING, Device::RESPONSE_EXPECTED_ALWAYS_TRUE, Device::RESPONSE_EXPECTED_FALSE, Device::RESPONSE_EXPECTED_INVALID_FUNCTION_ID, Device::RESPONSE_EXPECTED_TRUE

Instance Attribute Summary

Attributes inherited from Device

#callback_formats, #expected_response_function_id, #expected_response_sequence_number, #high_level_callbacks, #registered_callbacks, #replaced, #uid

Instance Method Summary collapse

Methods inherited from Device

#check_validity, #dequeue_response, #enqueue_response, #get_api_version, #get_response_expected, #send_request, #set_response_expected, #set_response_expected_all

Constructor Details

#initialize(uid, ipcon) ⇒ BrickletThermocouple

Creates an object with the unique device ID uid and adds it to the IP Connection ipcon.



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/tinkerforge/bricklet_thermocouple.rb', line 77

def initialize(uid, ipcon)
  super uid, ipcon, DEVICE_IDENTIFIER, DEVICE_DISPLAY_NAME

  @api_version = [2, 0, 0]

  @response_expected[FUNCTION_GET_TEMPERATURE] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_SET_TEMPERATURE_CALLBACK_PERIOD] = RESPONSE_EXPECTED_TRUE
  @response_expected[FUNCTION_GET_TEMPERATURE_CALLBACK_PERIOD] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_SET_TEMPERATURE_CALLBACK_THRESHOLD] = RESPONSE_EXPECTED_TRUE
  @response_expected[FUNCTION_GET_TEMPERATURE_CALLBACK_THRESHOLD] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_SET_DEBOUNCE_PERIOD] = RESPONSE_EXPECTED_TRUE
  @response_expected[FUNCTION_GET_DEBOUNCE_PERIOD] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_SET_CONFIGURATION] = RESPONSE_EXPECTED_FALSE
  @response_expected[FUNCTION_GET_CONFIGURATION] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_GET_ERROR_STATE] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_GET_IDENTITY] = RESPONSE_EXPECTED_ALWAYS_TRUE

  @callback_formats[CALLBACK_TEMPERATURE] = [12, 'l']
  @callback_formats[CALLBACK_TEMPERATURE_REACHED] = [12, 'l']
  @callback_formats[CALLBACK_ERROR_STATE] = [10, '? ?']

  @ipcon.add_device self
end

Instance Method Details

#get_configurationObject

Returns the configuration as set by BrickletThermocouple#set_configuration.



206
207
208
209
210
# File 'lib/tinkerforge/bricklet_thermocouple.rb', line 206

def get_configuration
  check_validity

  send_request FUNCTION_GET_CONFIGURATION, [], '', 11, 'C C C'
end

#get_debounce_periodObject

Returns the debounce period as set by BrickletThermocouple#set_debounce_period.



170
171
172
173
174
# File 'lib/tinkerforge/bricklet_thermocouple.rb', line 170

def get_debounce_period
  check_validity

  send_request FUNCTION_GET_DEBOUNCE_PERIOD, [], '', 12, 'L'
end

#get_error_stateObject

Returns the current error state. There are two possible errors:

  • Over/Under Voltage and

  • Open Circuit.

Over/Under Voltage happens for voltages below 0V or above 3.3V. In this case it is very likely that your thermocouple is defective. An Open Circuit error indicates that there is no thermocouple connected.

You can use the CALLBACK_ERROR_STATE callback to automatically get triggered when the error state changes.



223
224
225
226
227
# File 'lib/tinkerforge/bricklet_thermocouple.rb', line 223

def get_error_state
  check_validity

  send_request FUNCTION_GET_ERROR_STATE, [], '', 10, '? ?'
end

#get_identityObject

Returns the UID, the UID where the Bricklet is connected to, the position, the hardware and firmware version as well as the device identifier.

The position can be ‘a’, ‘b’, ‘c’, ‘d’, ‘e’, ‘f’, ‘g’ or ‘h’ (Bricklet Port). A Bricklet connected to an :ref:‘Isolator Bricklet <isolator_bricklet>` is always at position ’z’.

The device identifier numbers can be found :ref:‘here <device_identifier>`. |device_identifier_constant|



239
240
241
# File 'lib/tinkerforge/bricklet_thermocouple.rb', line 239

def get_identity
  send_request FUNCTION_GET_IDENTITY, [], '', 33, 'Z8 Z8 k C3 C3 S'
end

#get_temperatureObject

Returns the temperature of the thermocouple.

If you want to get the temperature periodically, it is recommended to use the CALLBACK_TEMPERATURE callback and set the period with BrickletThermocouple#set_temperature_callback_period.



106
107
108
109
110
# File 'lib/tinkerforge/bricklet_thermocouple.rb', line 106

def get_temperature
  check_validity

  send_request FUNCTION_GET_TEMPERATURE, [], '', 12, 'l'
end

#get_temperature_callback_periodObject

Returns the period as set by BrickletThermocouple#set_temperature_callback_period.



124
125
126
127
128
# File 'lib/tinkerforge/bricklet_thermocouple.rb', line 124

def get_temperature_callback_period
  check_validity

  send_request FUNCTION_GET_TEMPERATURE_CALLBACK_PERIOD, [], '', 12, 'L'
end

#get_temperature_callback_thresholdObject

Returns the threshold as set by BrickletThermocouple#set_temperature_callback_threshold.



148
149
150
151
152
# File 'lib/tinkerforge/bricklet_thermocouple.rb', line 148

def get_temperature_callback_threshold
  check_validity

  send_request FUNCTION_GET_TEMPERATURE_CALLBACK_THRESHOLD, [], '', 17, 'k l l'
end

#register_callback(id, &block) ⇒ Object

Registers a callback with ID id to the block block.



244
245
246
247
# File 'lib/tinkerforge/bricklet_thermocouple.rb', line 244

def register_callback(id, &block)
  callback = block
  @registered_callbacks[id] = callback
end

#set_configuration(averaging, thermocouple_type, filter) ⇒ Object

You can configure averaging size, thermocouple type and frequency filtering.

Available averaging sizes are 1, 2, 4, 8 and 16 samples.

As thermocouple type you can use B, E, J, K, N, R, S and T. If you have a different thermocouple or a custom thermocouple you can also use G8 and G32. With these types the returned value will not be in °C/100, it will be calculated by the following formulas:

  • G8: “value = 8 * 1.6 * 2^17 * Vin“

  • G32: “value = 32 * 1.6 * 2^17 * Vin“

where Vin is the thermocouple input voltage.

The frequency filter can be either configured to 50Hz or to 60Hz. You should configure it according to your utility frequency.

The conversion time depends on the averaging and filter configuration, it can be calculated as follows:

  • 60Hz: “time = 82 + (samples - 1) * 16.67“

  • 50Hz: “time = 98 + (samples - 1) * 20“



199
200
201
202
203
# File 'lib/tinkerforge/bricklet_thermocouple.rb', line 199

def set_configuration(averaging, thermocouple_type, filter)
  check_validity

  send_request FUNCTION_SET_CONFIGURATION, [averaging, thermocouple_type, filter], 'C C C', 8, ''
end

#set_debounce_period(debounce) ⇒ Object

Sets the period with which the threshold callback

  • CALLBACK_TEMPERATURE_REACHED

is triggered, if the threshold

  • BrickletThermocouple#set_temperature_callback_threshold

keeps being reached.



163
164
165
166
167
# File 'lib/tinkerforge/bricklet_thermocouple.rb', line 163

def set_debounce_period(debounce)
  check_validity

  send_request FUNCTION_SET_DEBOUNCE_PERIOD, [debounce], 'L', 8, ''
end

#set_temperature_callback_period(period) ⇒ Object

Sets the period with which the CALLBACK_TEMPERATURE callback is triggered periodically. A value of 0 turns the callback off.

The CALLBACK_TEMPERATURE callback is only triggered if the temperature has changed since the last triggering.



117
118
119
120
121
# File 'lib/tinkerforge/bricklet_thermocouple.rb', line 117

def set_temperature_callback_period(period)
  check_validity

  send_request FUNCTION_SET_TEMPERATURE_CALLBACK_PERIOD, [period], 'L', 8, ''
end

#set_temperature_callback_threshold(option, min, max) ⇒ Object

Sets the thresholds for the CALLBACK_TEMPERATURE_REACHED callback.

The following options are possible:

"Option", "Description"

"'x'",    "Callback is turned off"
"'o'",    "Callback is triggered when the temperature is *outside* the min and max values"
"'i'",    "Callback is triggered when the temperature is *inside* the min and max values"
"'<'",    "Callback is triggered when the temperature is smaller than the min value (max is ignored)"
"'>'",    "Callback is triggered when the temperature is greater than the min value (max is ignored)"


141
142
143
144
145
# File 'lib/tinkerforge/bricklet_thermocouple.rb', line 141

def set_temperature_callback_threshold(option, min, max)
  check_validity

  send_request FUNCTION_SET_TEMPERATURE_CALLBACK_THRESHOLD, [option, min, max], 'k l l', 8, ''
end