class Tinkerforge::BrickletIndustrialDual020mA
Measures two DC currents between 0mA and 20mA (IEC 60381-1)
Constants
- CALLBACK_CURRENT
This callback is triggered periodically with the period that is set by
BrickletIndustrialDual020mA#set_current_callback_period
. The parameter is the current of the sensor.The
CALLBACK_CURRENT
callback is only triggered if the current has changed since the last triggering.- CALLBACK_CURRENT_REACHED
This callback is triggered when the threshold as set by
BrickletIndustrialDual020mA#set_current_callback_threshold
is reached. The parameter is the current of the sensor.If the threshold keeps being reached, the callback is triggered periodically with the period as set by
BrickletIndustrialDual020mA#set_debounce_period
.
Public Class Methods
Creates an object with the unique device ID uid
and adds it to the IP Connection ipcon
.
# File lib/tinkerforge/bricklet_industrial_dual_0_20ma.rb, line 58 def initialize(uid, ipcon) super uid, ipcon, DEVICE_IDENTIFIER, DEVICE_DISPLAY_NAME @api_version = [2, 0, 0] @response_expected[FUNCTION_GET_CURRENT] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_SET_CURRENT_CALLBACK_PERIOD] = RESPONSE_EXPECTED_TRUE @response_expected[FUNCTION_GET_CURRENT_CALLBACK_PERIOD] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_SET_CURRENT_CALLBACK_THRESHOLD] = RESPONSE_EXPECTED_TRUE @response_expected[FUNCTION_GET_CURRENT_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_SAMPLE_RATE] = RESPONSE_EXPECTED_FALSE @response_expected[FUNCTION_GET_SAMPLE_RATE] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_GET_IDENTITY] = RESPONSE_EXPECTED_ALWAYS_TRUE @callback_formats[CALLBACK_CURRENT] = [13, 'C l'] @callback_formats[CALLBACK_CURRENT_REACHED] = [13, 'C l'] @ipcon.add_device self end
Public Instance Methods
Returns the current of the specified sensor.
It is possible to detect if an IEC 60381-1 compatible sensor is connected and if it works properly.
If the returned current is below 4mA, there is likely no sensor connected or the sensor may be defect. If the returned current is over 20mA, there might be a short circuit or the sensor may be defect.
If you want to get the current periodically, it is recommended to use the CALLBACK_CURRENT
callback and set the period with BrickletIndustrialDual020mA#set_current_callback_period
.
# File lib/tinkerforge/bricklet_industrial_dual_0_20ma.rb, line 92 def get_current(sensor) check_validity send_request FUNCTION_GET_CURRENT, [sensor], 'C', 12, 'l' end
Returns the period as set by BrickletIndustrialDual020mA#set_current_callback_period
.
# File lib/tinkerforge/bricklet_industrial_dual_0_20ma.rb, line 110 def get_current_callback_period(sensor) check_validity send_request FUNCTION_GET_CURRENT_CALLBACK_PERIOD, [sensor], 'C', 12, 'L' end
Returns the threshold as set by BrickletIndustrialDual020mA#set_current_callback_threshold
.
# File lib/tinkerforge/bricklet_industrial_dual_0_20ma.rb, line 135 def get_current_callback_threshold(sensor) check_validity send_request FUNCTION_GET_CURRENT_CALLBACK_THRESHOLD, [sensor], 'C', 17, 'k l l' end
Returns the debounce period as set by BrickletIndustrialDual020mA#set_debounce_period
.
# File lib/tinkerforge/bricklet_industrial_dual_0_20ma.rb, line 157 def get_debounce_period check_validity send_request FUNCTION_GET_DEBOUNCE_PERIOD, [], '', 12, 'L' end
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_industrial_dual_0_20ma.rb, line 195 def get_identity send_request FUNCTION_GET_IDENTITY, [], '', 33, 'Z8 Z8 k C3 C3 S' end
Returns the sample rate as set by BrickletIndustrialDual020mA#set_sample_rate
.
# File lib/tinkerforge/bricklet_industrial_dual_0_20ma.rb, line 179 def get_sample_rate check_validity send_request FUNCTION_GET_SAMPLE_RATE, [], '', 9, 'C' end
Registers a callback with ID id
to the block block
.
# File lib/tinkerforge/bricklet_industrial_dual_0_20ma.rb, line 200 def register_callback(id, &block) callback = block @registered_callbacks[id] = callback end
Sets the period with which the CALLBACK_CURRENT
callback is triggered periodically for the given sensor. A value of 0 turns the callback off.
The CALLBACK_CURRENT
callback is only triggered if the current has changed since the last triggering.
# File lib/tinkerforge/bricklet_industrial_dual_0_20ma.rb, line 103 def set_current_callback_period(sensor, period) check_validity send_request FUNCTION_SET_CURRENT_CALLBACK_PERIOD, [sensor, period], 'C L', 8, '' end
Sets the thresholds for the CALLBACK_CURRENT_REACHED
callback for the given sensor.
The following options are possible:
"Option", "Description" "'x'", "Callback is turned off" "'o'", "Callback is triggered when the current is *outside* the min and max values" "'i'", "Callback is triggered when the current is *inside* the min and max values" "'<'", "Callback is triggered when the current is smaller than the min value (max is ignored)" "'>'", "Callback is triggered when the current is greater than the min value (max is ignored)"
# File lib/tinkerforge/bricklet_industrial_dual_0_20ma.rb, line 128 def set_current_callback_threshold(sensor, option, min, max) check_validity send_request FUNCTION_SET_CURRENT_CALLBACK_THRESHOLD, [sensor, option, min, max], 'C k l l', 8, '' end
Sets the period with which the threshold callback
is triggered, if the threshold
keeps being reached.
# File lib/tinkerforge/bricklet_industrial_dual_0_20ma.rb, line 150 def set_debounce_period(debounce) check_validity send_request FUNCTION_SET_DEBOUNCE_PERIOD, [debounce], 'L', 8, '' end
Sets the sample rate to either 240, 60, 15 or 4 samples per second. The resolution for the rates is 12, 14, 16 and 18 bit respectively.
"Value", "Description" "0", "240 samples per second, 12 bit resolution" "1", "60 samples per second, 14 bit resolution" "2", "15 samples per second, 16 bit resolution" "3", "4 samples per second, 18 bit resolution"
# File lib/tinkerforge/bricklet_industrial_dual_0_20ma.rb, line 172 def set_sample_rate(rate) check_validity send_request FUNCTION_SET_SAMPLE_RATE, [rate], 'C', 8, '' end