class Tinkerforge::BrickletVoltageCurrent
Measures power, DC voltage and DC current up to 720W/36V/20A
Constants
- CALLBACK_CURRENT
This callback is triggered periodically with the period that is set by
BrickletVoltageCurrent#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
BrickletVoltageCurrent#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
BrickletVoltageCurrent#set_debounce_period
.- CALLBACK_POWER
This callback is triggered periodically with the period that is set by
BrickletVoltageCurrent#set_power_callback_period
. The parameter is the power of the sensor.The
CALLBACK_POWER
callback is only triggered if the power has changed since the last triggering.- CALLBACK_POWER_REACHED
This callback is triggered when the threshold as set by
BrickletVoltageCurrent#set_power_callback_threshold
is reached. The parameter is the power of the sensor.If the threshold keeps being reached, the callback is triggered periodically with the period as set by
BrickletVoltageCurrent#set_debounce_period
.- CALLBACK_VOLTAGE
This callback is triggered periodically with the period that is set by
BrickletVoltageCurrent#set_voltage_callback_period
. The parameter is the voltage of the sensor.The
CALLBACK_VOLTAGE
callback is only triggered if the voltage has changed since the last triggering.- CALLBACK_VOLTAGE_REACHED
This callback is triggered when the threshold as set by
BrickletVoltageCurrent#set_voltage_callback_threshold
is reached. The parameter is the voltage of the sensor.If the threshold keeps being reached, the callback is triggered periodically with the period as set by
BrickletVoltageCurrent#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_voltage_current.rb, line 114 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_GET_VOLTAGE] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_GET_POWER] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_SET_CONFIGURATION] = RESPONSE_EXPECTED_FALSE @response_expected[FUNCTION_GET_CONFIGURATION] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_SET_CALIBRATION] = RESPONSE_EXPECTED_FALSE @response_expected[FUNCTION_GET_CALIBRATION] = 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_VOLTAGE_CALLBACK_PERIOD] = RESPONSE_EXPECTED_TRUE @response_expected[FUNCTION_GET_VOLTAGE_CALLBACK_PERIOD] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_SET_POWER_CALLBACK_PERIOD] = RESPONSE_EXPECTED_TRUE @response_expected[FUNCTION_GET_POWER_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_VOLTAGE_CALLBACK_THRESHOLD] = RESPONSE_EXPECTED_TRUE @response_expected[FUNCTION_GET_VOLTAGE_CALLBACK_THRESHOLD] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_SET_POWER_CALLBACK_THRESHOLD] = RESPONSE_EXPECTED_TRUE @response_expected[FUNCTION_GET_POWER_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_GET_IDENTITY] = RESPONSE_EXPECTED_ALWAYS_TRUE @callback_formats[CALLBACK_CURRENT] = [12, 'l'] @callback_formats[CALLBACK_VOLTAGE] = [12, 'l'] @callback_formats[CALLBACK_POWER] = [12, 'l'] @callback_formats[CALLBACK_CURRENT_REACHED] = [12, 'l'] @callback_formats[CALLBACK_VOLTAGE_REACHED] = [12, 'l'] @callback_formats[CALLBACK_POWER_REACHED] = [12, 'l'] @ipcon.add_device self end
Public Instance Methods
Returns the calibration as set by BrickletVoltageCurrent#set_calibration
.
# File lib/tinkerforge/bricklet_voltage_current.rb, line 215 def get_calibration check_validity send_request FUNCTION_GET_CALIBRATION, [], '', 12, 'S S' end
Returns the configuration as set by BrickletVoltageCurrent#set_configuration
.
# File lib/tinkerforge/bricklet_voltage_current.rb, line 195 def get_configuration check_validity send_request FUNCTION_GET_CONFIGURATION, [], '', 11, 'C C C' end
Returns the current.
If you want to get the current periodically, it is recommended to use the CALLBACK_CURRENT
callback and set the period with BrickletVoltageCurrent#set_current_callback_period
.
# File lib/tinkerforge/bricklet_voltage_current.rb, line 157 def get_current check_validity send_request FUNCTION_GET_CURRENT, [], '', 12, 'l' end
Returns the period as set by BrickletVoltageCurrent#set_current_callback_period
.
# File lib/tinkerforge/bricklet_voltage_current.rb, line 233 def get_current_callback_period check_validity send_request FUNCTION_GET_CURRENT_CALLBACK_PERIOD, [], '', 12, 'L' end
Returns the threshold as set by BrickletVoltageCurrent#set_current_callback_threshold
.
# File lib/tinkerforge/bricklet_voltage_current.rb, line 293 def get_current_callback_threshold check_validity send_request FUNCTION_GET_CURRENT_CALLBACK_THRESHOLD, [], '', 17, 'k l l' end
Returns the debounce period as set by BrickletVoltageCurrent#set_debounce_period
.
# File lib/tinkerforge/bricklet_voltage_current.rb, line 367 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_voltage_current.rb, line 383 def get_identity send_request FUNCTION_GET_IDENTITY, [], '', 33, 'Z8 Z8 k C3 C3 S' end
Returns the power.
If you want to get the power periodically, it is recommended to use the CALLBACK_POWER
callback and set the period with BrickletVoltageCurrent#set_power_callback_period
.
# File lib/tinkerforge/bricklet_voltage_current.rb, line 179 def get_power check_validity send_request FUNCTION_GET_POWER, [], '', 12, 'l' end
Returns the period as set by BrickletVoltageCurrent#get_power_callback_period
.
# File lib/tinkerforge/bricklet_voltage_current.rb, line 269 def get_power_callback_period check_validity send_request FUNCTION_GET_POWER_CALLBACK_PERIOD, [], '', 12, 'L' end
Returns the threshold as set by BrickletVoltageCurrent#set_power_callback_threshold
.
# File lib/tinkerforge/bricklet_voltage_current.rb, line 341 def get_power_callback_threshold check_validity send_request FUNCTION_GET_POWER_CALLBACK_THRESHOLD, [], '', 17, 'k l l' end
Returns the voltage.
If you want to get the voltage periodically, it is recommended to use the CALLBACK_VOLTAGE
callback and set the period with BrickletVoltageCurrent#set_voltage_callback_period
.
# File lib/tinkerforge/bricklet_voltage_current.rb, line 168 def get_voltage check_validity send_request FUNCTION_GET_VOLTAGE, [], '', 12, 'l' end
Returns the period as set by BrickletVoltageCurrent#set_voltage_callback_period
.
# File lib/tinkerforge/bricklet_voltage_current.rb, line 251 def get_voltage_callback_period check_validity send_request FUNCTION_GET_VOLTAGE_CALLBACK_PERIOD, [], '', 12, 'L' end
Returns the threshold as set by BrickletVoltageCurrent#set_voltage_callback_threshold
.
# File lib/tinkerforge/bricklet_voltage_current.rb, line 317 def get_voltage_callback_threshold check_validity send_request FUNCTION_GET_VOLTAGE_CALLBACK_THRESHOLD, [], '', 17, 'k l l' end
Registers a callback with ID id
to the block block
.
# File lib/tinkerforge/bricklet_voltage_current.rb, line 388 def register_callback(id, &block) callback = block @registered_callbacks[id] = callback end
Since the shunt resistor that is used to measure the current is not perfectly precise, it needs to be calibrated by a multiplier and divisor if a very precise reading is needed.
For example, if you are expecting a measurement of 1000mA and you are measuring 1023mA, you can calibrate the Voltage/Current Bricklet by setting the multiplier to 1000 and the divisor to 1023.
# File lib/tinkerforge/bricklet_voltage_current.rb, line 208 def set_calibration(gain_multiplier, gain_divisor) check_validity send_request FUNCTION_SET_CALIBRATION, [gain_multiplier, gain_divisor], 'S S', 8, '' end
Sets the configuration of the Voltage/Current Bricklet. It is possible to configure number of averages as well as voltage and current conversion time.
# File lib/tinkerforge/bricklet_voltage_current.rb, line 188 def set_configuration(averaging, voltage_conversion_time, current_conversion_time) check_validity send_request FUNCTION_SET_CONFIGURATION, [averaging, voltage_conversion_time, current_conversion_time], 'C C C', 8, '' end
Sets the period with which the CALLBACK_CURRENT
callback is triggered periodically. 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_voltage_current.rb, line 226 def set_current_callback_period(period) check_validity send_request FUNCTION_SET_CURRENT_CALLBACK_PERIOD, [period], 'L', 8, '' end
Sets the thresholds for the CALLBACK_CURRENT_REACHED
callback.
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_voltage_current.rb, line 286 def set_current_callback_threshold(option, min, max) check_validity send_request FUNCTION_SET_CURRENT_CALLBACK_THRESHOLD, [option, min, max], 'k l l', 8, '' end
Sets the period with which the threshold callbacks
are triggered, if the thresholds
keep being reached.
# File lib/tinkerforge/bricklet_voltage_current.rb, line 360 def set_debounce_period(debounce) check_validity send_request FUNCTION_SET_DEBOUNCE_PERIOD, [debounce], 'L', 8, '' end
Sets the period with which the CALLBACK_POWER
callback is triggered periodically. A value of 0 turns the callback off.
The CALLBACK_POWER
callback is only triggered if the power has changed since the last triggering.
# File lib/tinkerforge/bricklet_voltage_current.rb, line 262 def set_power_callback_period(period) check_validity send_request FUNCTION_SET_POWER_CALLBACK_PERIOD, [period], 'L', 8, '' end
Sets the thresholds for the CALLBACK_POWER_REACHED
callback.
The following options are possible:
"Option", "Description" "'x'", "Callback is turned off" "'o'", "Callback is triggered when the power is *outside* the min and max values" "'i'", "Callback is triggered when the power is *inside* the min and max values" "'<'", "Callback is triggered when the power is smaller than the min value (max is ignored)" "'>'", "Callback is triggered when the power is greater than the min value (max is ignored)"
# File lib/tinkerforge/bricklet_voltage_current.rb, line 334 def set_power_callback_threshold(option, min, max) check_validity send_request FUNCTION_SET_POWER_CALLBACK_THRESHOLD, [option, min, max], 'k l l', 8, '' end
Sets the period with which the CALLBACK_VOLTAGE
callback is triggered periodically. A value of 0 turns the callback off.
The CALLBACK_VOLTAGE
callback is only triggered if the voltage has changed since the last triggering.
# File lib/tinkerforge/bricklet_voltage_current.rb, line 244 def set_voltage_callback_period(period) check_validity send_request FUNCTION_SET_VOLTAGE_CALLBACK_PERIOD, [period], 'L', 8, '' end
Sets the thresholds for the CALLBACK_VOLTAGE_REACHED
callback.
The following options are possible:
"Option", "Description" "'x'", "Callback is turned off" "'o'", "Callback is triggered when the voltage is *outside* the min and max values" "'i'", "Callback is triggered when the voltage is *inside* the min and max values" "'<'", "Callback is triggered when the voltage is smaller than the min value (max is ignored)" "'>'", "Callback is triggered when the voltage is greater than the min value (max is ignored)"
# File lib/tinkerforge/bricklet_voltage_current.rb, line 310 def set_voltage_callback_threshold(option, min, max) check_validity send_request FUNCTION_SET_VOLTAGE_CALLBACK_THRESHOLD, [option, min, max], 'k l l', 8, '' end