Class: Tinkerforge::BrickletPTC

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

Overview

Reads temperatures from Pt100 und Pt1000 sensors

Constant Summary collapse

DEVICE_IDENTIFIER =

:nodoc:

226
DEVICE_DISPLAY_NAME =

:nodoc:

'PTC Bricklet'
CALLBACK_TEMPERATURE =

This callback is triggered periodically with the period that is set by BrickletPTC#set_temperature_callback_period. The parameter is the temperature of the connected sensor.

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

13
CALLBACK_TEMPERATURE_REACHED =

This callback is triggered when the threshold as set by BrickletPTC#set_temperature_callback_threshold is reached. The parameter is the temperature of the connected sensor.

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

14
CALLBACK_RESISTANCE =

This callback is triggered periodically with the period that is set by BrickletPTC#set_resistance_callback_period. The parameter is the resistance of the connected sensor.

CALLBACK_RESISTANCE is only triggered if the resistance has changed since the last triggering.

15
CALLBACK_RESISTANCE_REACHED =

This callback is triggered when the threshold as set by BrickletPTC#set_resistance_callback_threshold is reached. The parameter is the resistance of the connected sensor.

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

16
FUNCTION_GET_TEMPERATURE =

:nodoc:

1
FUNCTION_GET_RESISTANCE =

:nodoc:

2
FUNCTION_SET_TEMPERATURE_CALLBACK_PERIOD =

:nodoc:

3
FUNCTION_GET_TEMPERATURE_CALLBACK_PERIOD =

:nodoc:

4
FUNCTION_SET_RESISTANCE_CALLBACK_PERIOD =

:nodoc:

5
FUNCTION_GET_RESISTANCE_CALLBACK_PERIOD =

:nodoc:

6
FUNCTION_SET_TEMPERATURE_CALLBACK_THRESHOLD =

:nodoc:

7
FUNCTION_GET_TEMPERATURE_CALLBACK_THRESHOLD =

:nodoc:

8
FUNCTION_SET_RESISTANCE_CALLBACK_THRESHOLD =

:nodoc:

9
FUNCTION_GET_RESISTANCE_CALLBACK_THRESHOLD =

:nodoc:

10
FUNCTION_SET_DEBOUNCE_PERIOD =

:nodoc:

11
FUNCTION_GET_DEBOUNCE_PERIOD =

:nodoc:

12
FUNCTION_SET_NOISE_REJECTION_FILTER =

:nodoc:

17
FUNCTION_GET_NOISE_REJECTION_FILTER =

:nodoc:

18
FUNCTION_IS_SENSOR_CONNECTED =

:nodoc:

19
FUNCTION_SET_WIRE_MODE =

:nodoc:

20
FUNCTION_GET_WIRE_MODE =

:nodoc:

21
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:

'>'
FILTER_OPTION_50HZ =

:nodoc:

0
FILTER_OPTION_60HZ =

:nodoc:

1
WIRE_MODE_2 =

:nodoc:

2
WIRE_MODE_3 =

:nodoc:

3
WIRE_MODE_4 =

:nodoc:

4

Constants inherited from Device

Device::RESPONSE_EXPECTED_ALWAYS_FALSE, 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, #registered_callbacks, #uid

Instance Method Summary collapse

Methods inherited from Device

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

Constructor Details

#initialize(uid, ipcon) ⇒ BrickletPTC

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



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
# File 'lib/tinkerforge/bricklet_ptc.rb', line 82

def initialize(uid, ipcon)
  super uid, ipcon

  @api_version = [2, 0, 0]

  @response_expected[FUNCTION_GET_TEMPERATURE] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_GET_RESISTANCE] = 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_RESISTANCE_CALLBACK_PERIOD] = RESPONSE_EXPECTED_TRUE
  @response_expected[FUNCTION_GET_RESISTANCE_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_RESISTANCE_CALLBACK_THRESHOLD] = RESPONSE_EXPECTED_TRUE
  @response_expected[FUNCTION_GET_RESISTANCE_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[CALLBACK_TEMPERATURE] = RESPONSE_EXPECTED_ALWAYS_FALSE
  @response_expected[CALLBACK_TEMPERATURE_REACHED] = RESPONSE_EXPECTED_ALWAYS_FALSE
  @response_expected[CALLBACK_RESISTANCE] = RESPONSE_EXPECTED_ALWAYS_FALSE
  @response_expected[CALLBACK_RESISTANCE_REACHED] = RESPONSE_EXPECTED_ALWAYS_FALSE
  @response_expected[FUNCTION_SET_NOISE_REJECTION_FILTER] = RESPONSE_EXPECTED_FALSE
  @response_expected[FUNCTION_GET_NOISE_REJECTION_FILTER] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_IS_SENSOR_CONNECTED] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_SET_WIRE_MODE] = RESPONSE_EXPECTED_FALSE
  @response_expected[FUNCTION_GET_WIRE_MODE] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_GET_IDENTITY] = RESPONSE_EXPECTED_ALWAYS_TRUE

  @callback_formats[CALLBACK_TEMPERATURE] = 'l'
  @callback_formats[CALLBACK_TEMPERATURE_REACHED] = 'l'
  @callback_formats[CALLBACK_RESISTANCE] = 'S'
  @callback_formats[CALLBACK_RESISTANCE_REACHED] = 'S'
end

Instance Method Details

#get_debounce_periodObject

Returns the debounce period as set by BrickletPTC#set_debounce_period.



235
236
237
# File 'lib/tinkerforge/bricklet_ptc.rb', line 235

def get_debounce_period
  send_request(FUNCTION_GET_DEBOUNCE_PERIOD, [], '', 4, 'L')
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’ or ‘d’.

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



286
287
288
# File 'lib/tinkerforge/bricklet_ptc.rb', line 286

def get_identity
  send_request(FUNCTION_GET_IDENTITY, [], '', 25, 'Z8 Z8 k C3 C3 S')
end

#get_noise_rejection_filterObject

Returns the noise rejection filter option as set by BrickletPTC#set_noise_rejection_filter



251
252
253
# File 'lib/tinkerforge/bricklet_ptc.rb', line 251

def get_noise_rejection_filter
  send_request(FUNCTION_GET_NOISE_REJECTION_FILTER, [], '', 1, 'C')
end

#get_resistanceObject

Returns the value as measured by the MAX31865 precision delta-sigma ADC.

The value can be converted with the following formulas:

  • Pt100: resistance = (value * 390) / 32768

  • Pt1000: resistance = (value * 3900) / 32768

If you want to get the resistance periodically, it is recommended to use the callback CALLBACK_RESISTANCE and set the period with BrickletPTC#set_resistance_callback_period.



137
138
139
# File 'lib/tinkerforge/bricklet_ptc.rb', line 137

def get_resistance
  send_request(FUNCTION_GET_RESISTANCE, [], '', 2, 'S')
end

#get_resistance_callback_periodObject

Returns the period as set by BrickletPTC#set_resistance_callback_period.



169
170
171
# File 'lib/tinkerforge/bricklet_ptc.rb', line 169

def get_resistance_callback_period
  send_request(FUNCTION_GET_RESISTANCE_CALLBACK_PERIOD, [], '', 4, 'L')
end

#get_resistance_callback_thresholdObject

Returns the threshold as set by BrickletPTC#set_resistance_callback_threshold.



213
214
215
# File 'lib/tinkerforge/bricklet_ptc.rb', line 213

def get_resistance_callback_threshold
  send_request(FUNCTION_GET_RESISTANCE_CALLBACK_THRESHOLD, [], '', 5, 'k S S')
end

#get_temperatureObject

Returns the temperature of connected sensor. The value has a range of -246 to 849 °C and is given in °C/100, e.g. a value of 4223 means that a temperature of 42.23 °C is measured.

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



123
124
125
# File 'lib/tinkerforge/bricklet_ptc.rb', line 123

def get_temperature
  send_request(FUNCTION_GET_TEMPERATURE, [], '', 4, 'l')
end

#get_temperature_callback_periodObject

Returns the period as set by BrickletPTC#set_temperature_callback_period.



153
154
155
# File 'lib/tinkerforge/bricklet_ptc.rb', line 153

def get_temperature_callback_period
  send_request(FUNCTION_GET_TEMPERATURE_CALLBACK_PERIOD, [], '', 4, 'L')
end

#get_temperature_callback_thresholdObject

Returns the threshold as set by BrickletPTC#set_temperature_callback_threshold.



191
192
193
# File 'lib/tinkerforge/bricklet_ptc.rb', line 191

def get_temperature_callback_threshold
  send_request(FUNCTION_GET_TEMPERATURE_CALLBACK_THRESHOLD, [], '', 9, 'k l l')
end

#get_wire_modeObject

Returns the wire mode as set by BrickletPTC#set_wire_mode



274
275
276
# File 'lib/tinkerforge/bricklet_ptc.rb', line 274

def get_wire_mode
  send_request(FUNCTION_GET_WIRE_MODE, [], '', 1, 'C')
end

#is_sensor_connectedObject

Returns true if the sensor is connected correctly.

If this function returns false, there is either no Pt100 or Pt1000 sensor connected, the sensor is connected incorrectly or the sensor itself is faulty.



260
261
262
# File 'lib/tinkerforge/bricklet_ptc.rb', line 260

def is_sensor_connected
  send_request(FUNCTION_IS_SENSOR_CONNECTED, [], '', 1, '?')
end

#register_callback(id, &block) ⇒ Object

Registers a callback with ID id to the block block.



291
292
293
294
# File 'lib/tinkerforge/bricklet_ptc.rb', line 291

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

#set_debounce_period(debounce) ⇒ Object

Sets the period in ms with which the threshold callback

  • CALLBACK_TEMPERATURE_REACHED,

  • CALLBACK_RESISTANCE_REACHED

is triggered, if the threshold

  • BrickletPTC#set_temperature_callback_threshold,

  • BrickletPTC#set_resistance_callback_threshold

keeps being reached.

The default value is 100.



230
231
232
# File 'lib/tinkerforge/bricklet_ptc.rb', line 230

def set_debounce_period(debounce)
  send_request(FUNCTION_SET_DEBOUNCE_PERIOD, [debounce], 'L', 0, '')
end

#set_noise_rejection_filter(filter) ⇒ Object

Sets the noise rejection filter to either 50Hz (0) or 60Hz (1). Noise from 50Hz or 60Hz power sources (including harmonics of the AC power’s fundamental frequency) is attenuated by 82dB.

Default value is 0 = 50Hz.



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

def set_noise_rejection_filter(filter)
  send_request(FUNCTION_SET_NOISE_REJECTION_FILTER, [filter], 'C', 0, '')
end

#set_resistance_callback_period(period) ⇒ Object

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

CALLBACK_RESISTANCE is only triggered if the resistance has changed since the last triggering.

The default value is 0.



164
165
166
# File 'lib/tinkerforge/bricklet_ptc.rb', line 164

def set_resistance_callback_period(period)
  send_request(FUNCTION_SET_RESISTANCE_CALLBACK_PERIOD, [period], 'L', 0, '')
end

#set_resistance_callback_threshold(option, min, max) ⇒ Object

Sets the thresholds for the CALLBACK_RESISTANCE_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)"

The default value is (‘x’, 0, 0).



208
209
210
# File 'lib/tinkerforge/bricklet_ptc.rb', line 208

def set_resistance_callback_threshold(option, min, max)
  send_request(FUNCTION_SET_RESISTANCE_CALLBACK_THRESHOLD, [option, min, max], 'k S S', 0, '')
end

#set_temperature_callback_period(period) ⇒ Object

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

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

The default value is 0.



148
149
150
# File 'lib/tinkerforge/bricklet_ptc.rb', line 148

def set_temperature_callback_period(period)
  send_request(FUNCTION_SET_TEMPERATURE_CALLBACK_PERIOD, [period], 'L', 0, '')
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)"

The default value is (‘x’, 0, 0).



186
187
188
# File 'lib/tinkerforge/bricklet_ptc.rb', line 186

def set_temperature_callback_threshold(option, min, max)
  send_request(FUNCTION_SET_TEMPERATURE_CALLBACK_THRESHOLD, [option, min, max], 'k l l', 0, '')
end

#set_wire_mode(mode) ⇒ Object

Sets the wire mode of the sensor. Possible values are 2, 3 and 4 which correspond to 2-, 3- and 4-wire sensors. The value has to match the jumper configuration on the Bricklet.

The default value is 2 = 2-wire.



269
270
271
# File 'lib/tinkerforge/bricklet_ptc.rb', line 269

def set_wire_mode(mode)
  send_request(FUNCTION_SET_WIRE_MODE, [mode], 'C', 0, '')
end