class Tinkerforge::BrickletPTC

Reads temperatures from Pt100 und Pt1000 sensors

Constants

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.

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

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.

CALLBACK_SENSOR_CONNECTED

This callback is triggered periodically according to the configuration set by BrickletPTC#set_sensor_connected_callback_configuration.

The parameter is the same as BrickletPTC#is_sensor_connected.

.. versionadded

2.0.2$nbsp;(Plugin)

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.

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

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.

Public Class Methods

new(uid, ipcon) click to toggle source

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

Calls superclass method
# File lib/tinkerforge/bricklet_ptc.rb, line 93
def initialize(uid, ipcon)
  super uid, ipcon, DEVICE_IDENTIFIER, DEVICE_DISPLAY_NAME

  @api_version = [2, 0, 1]

  @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[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_SET_SENSOR_CONNECTED_CALLBACK_CONFIGURATION] = RESPONSE_EXPECTED_TRUE
  @response_expected[FUNCTION_GET_SENSOR_CONNECTED_CALLBACK_CONFIGURATION] = 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_RESISTANCE] = [12, 'l']
  @callback_formats[CALLBACK_RESISTANCE_REACHED] = [12, 'l']
  @callback_formats[CALLBACK_SENSOR_CONNECTED] = [9, '?']

  @ipcon.add_device self
end

Public Instance Methods

get_debounce_period() click to toggle source

Returns the debounce period as set by BrickletPTC#set_debounce_period.

# File lib/tinkerforge/bricklet_ptc.rb, line 257
def get_debounce_period
  check_validity

  send_request FUNCTION_GET_DEBOUNCE_PERIOD, [], '', 12, 'L'
end
get_identity() click to toggle source

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|

# File lib/tinkerforge/bricklet_ptc.rb, line 337
def get_identity
  send_request FUNCTION_GET_IDENTITY, [], '', 33, 'Z8 Z8 k C3 C3 S'
end
get_noise_rejection_filter() click to toggle source

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

# File lib/tinkerforge/bricklet_ptc.rb, line 275
def get_noise_rejection_filter
  check_validity

  send_request FUNCTION_GET_NOISE_REJECTION_FILTER, [], '', 9, 'C'
end
get_resistance() click to toggle source

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_RESISTANCE callback and set the period with BrickletPTC#set_resistance_callback_period.

# File lib/tinkerforge/bricklet_ptc.rb, line 149
def get_resistance
  check_validity

  send_request FUNCTION_GET_RESISTANCE, [], '', 12, 'l'
end
get_resistance_callback_period() click to toggle source

Returns the period as set by BrickletPTC#set_resistance_callback_period.

# File lib/tinkerforge/bricklet_ptc.rb, line 185
def get_resistance_callback_period
  check_validity

  send_request FUNCTION_GET_RESISTANCE_CALLBACK_PERIOD, [], '', 12, 'L'
end
get_resistance_callback_threshold() click to toggle source

Returns the threshold as set by BrickletPTC#set_resistance_callback_threshold.

# File lib/tinkerforge/bricklet_ptc.rb, line 233
def get_resistance_callback_threshold
  check_validity

  send_request FUNCTION_GET_RESISTANCE_CALLBACK_THRESHOLD, [], '', 17, 'k l l'
end
get_sensor_connected_callback_configuration() click to toggle source

Returns the configuration as set by BrickletPTC#set_sensor_connected_callback_configuration.

.. versionadded

2.0.2$nbsp;(Plugin)

# File lib/tinkerforge/bricklet_ptc.rb, line 321
def get_sensor_connected_callback_configuration
  check_validity

  send_request FUNCTION_GET_SENSOR_CONNECTED_CALLBACK_CONFIGURATION, [], '', 9, '?'
end
get_temperature() click to toggle source

Returns the temperature of connected sensor.

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

# File lib/tinkerforge/bricklet_ptc.rb, line 133
def get_temperature
  check_validity

  send_request FUNCTION_GET_TEMPERATURE, [], '', 12, 'l'
end
get_temperature_callback_period() click to toggle source

Returns the period as set by BrickletPTC#set_temperature_callback_period.

# File lib/tinkerforge/bricklet_ptc.rb, line 167
def get_temperature_callback_period
  check_validity

  send_request FUNCTION_GET_TEMPERATURE_CALLBACK_PERIOD, [], '', 12, 'L'
end
get_temperature_callback_threshold() click to toggle source

Returns the threshold as set by BrickletPTC#set_temperature_callback_threshold.

# File lib/tinkerforge/bricklet_ptc.rb, line 209
def get_temperature_callback_threshold
  check_validity

  send_request FUNCTION_GET_TEMPERATURE_CALLBACK_THRESHOLD, [], '', 17, 'k l l'
end
get_wire_mode() click to toggle source

Returns the wire mode as set by BrickletPTC#set_wire_mode

# File lib/tinkerforge/bricklet_ptc.rb, line 302
def get_wire_mode
  check_validity

  send_request FUNCTION_GET_WIRE_MODE, [], '', 9, 'C'
end
is_sensor_connected() click to toggle source

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.

# File lib/tinkerforge/bricklet_ptc.rb, line 286
def is_sensor_connected
  check_validity

  send_request FUNCTION_IS_SENSOR_CONNECTED, [], '', 9, '?'
end
register_callback(id, &block) click to toggle source

Registers a callback with ID id to the block block.

# File lib/tinkerforge/bricklet_ptc.rb, line 342
def register_callback(id, &block)
  callback = block
  @registered_callbacks[id] = callback
end
set_debounce_period(debounce) click to toggle source

Sets the period with which the threshold callback

is triggered, if the threshold

keeps being reached.

# File lib/tinkerforge/bricklet_ptc.rb, line 250
def set_debounce_period(debounce)
  check_validity

  send_request FUNCTION_SET_DEBOUNCE_PERIOD, [debounce], 'L', 8, ''
end
set_noise_rejection_filter(filter) click to toggle source

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.

# File lib/tinkerforge/bricklet_ptc.rb, line 267
def set_noise_rejection_filter(filter)
  check_validity

  send_request FUNCTION_SET_NOISE_REJECTION_FILTER, [filter], 'C', 8, ''
end
set_resistance_callback_period(period) click to toggle source

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

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

# File lib/tinkerforge/bricklet_ptc.rb, line 178
def set_resistance_callback_period(period)
  check_validity

  send_request FUNCTION_SET_RESISTANCE_CALLBACK_PERIOD, [period], 'L', 8, ''
end
set_resistance_callback_threshold(option, min, max) click to toggle source

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)"
# File lib/tinkerforge/bricklet_ptc.rb, line 226
def set_resistance_callback_threshold(option, min, max)
  check_validity

  send_request FUNCTION_SET_RESISTANCE_CALLBACK_THRESHOLD, [option, min, max], 'k l l', 8, ''
end
set_sensor_connected_callback_configuration(enabled) click to toggle source

If you enable this callback, the CALLBACK_SENSOR_CONNECTED callback is triggered every time a Pt sensor is connected/disconnected.

.. versionadded

2.0.2$nbsp;(Plugin)

# File lib/tinkerforge/bricklet_ptc.rb, line 312
def set_sensor_connected_callback_configuration(enabled)
  check_validity

  send_request FUNCTION_SET_SENSOR_CONNECTED_CALLBACK_CONFIGURATION, [enabled], '?', 8, ''
end
set_temperature_callback_period(period) click to toggle source

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.

# File lib/tinkerforge/bricklet_ptc.rb, line 160
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) click to toggle source

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)"
# File lib/tinkerforge/bricklet_ptc.rb, line 202
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
set_wire_mode(mode) click to toggle source

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.

# File lib/tinkerforge/bricklet_ptc.rb, line 295
def set_wire_mode(mode)
  check_validity

  send_request FUNCTION_SET_WIRE_MODE, [mode], 'C', 8, ''
end