Class: Tinkerforge::BrickletCurrent25
- Defined in:
- lib/tinkerforge/bricklet_current25.rb
Overview
Measures AC/DC current between -25A and +25A
Constant Summary collapse
- DEVICE_IDENTIFIER =
:nodoc:
24
- DEVICE_DISPLAY_NAME =
:nodoc:
'Current25 Bricklet'
- CALLBACK_CURRENT =
This callback is triggered periodically with the period that is set by BrickletCurrent25#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.
15
- CALLBACK_ANALOG_VALUE =
This callback is triggered periodically with the period that is set by BrickletCurrent25#set_analog_value_callback_period. The parameter is the analog value of the sensor.
The CALLBACK_ANALOG_VALUE callback is only triggered if the current has changed since the last triggering.
16
- CALLBACK_CURRENT_REACHED =
This callback is triggered when the threshold as set by BrickletCurrent25#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 BrickletCurrent25#set_debounce_period.
17
- CALLBACK_ANALOG_VALUE_REACHED =
This callback is triggered when the threshold as set by BrickletCurrent25#set_analog_value_callback_threshold is reached. The parameter is the analog value of the sensor.
If the threshold keeps being reached, the callback is triggered periodically with the period as set by BrickletCurrent25#set_debounce_period.
18
- CALLBACK_OVER_CURRENT =
This callback is triggered when an over current is measured (see BrickletCurrent25#is_over_current).
19
- FUNCTION_GET_CURRENT =
:nodoc:
1
- FUNCTION_CALIBRATE =
:nodoc:
2
- FUNCTION_IS_OVER_CURRENT =
:nodoc:
3
- FUNCTION_GET_ANALOG_VALUE =
:nodoc:
4
- FUNCTION_SET_CURRENT_CALLBACK_PERIOD =
:nodoc:
5
- FUNCTION_GET_CURRENT_CALLBACK_PERIOD =
:nodoc:
6
- FUNCTION_SET_ANALOG_VALUE_CALLBACK_PERIOD =
:nodoc:
7
- FUNCTION_GET_ANALOG_VALUE_CALLBACK_PERIOD =
:nodoc:
8
- FUNCTION_SET_CURRENT_CALLBACK_THRESHOLD =
:nodoc:
9
- FUNCTION_GET_CURRENT_CALLBACK_THRESHOLD =
:nodoc:
10
- FUNCTION_SET_ANALOG_VALUE_CALLBACK_THRESHOLD =
:nodoc:
11
- FUNCTION_GET_ANALOG_VALUE_CALLBACK_THRESHOLD =
:nodoc:
12
- FUNCTION_SET_DEBOUNCE_PERIOD =
:nodoc:
13
- FUNCTION_GET_DEBOUNCE_PERIOD =
:nodoc:
14
- 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:
'>'
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
-
#calibrate ⇒ Object
Calibrates the 0 value of the sensor.
-
#get_analog_value ⇒ Object
Returns the value as read by a 12-bit analog-to-digital converter.
-
#get_analog_value_callback_period ⇒ Object
Returns the period as set by BrickletCurrent25#set_analog_value_callback_period.
-
#get_analog_value_callback_threshold ⇒ Object
Returns the threshold as set by BrickletCurrent25#set_analog_value_callback_threshold.
-
#get_current ⇒ Object
Returns the current of the sensor.
-
#get_current_callback_period ⇒ Object
Returns the period as set by BrickletCurrent25#set_current_callback_period.
-
#get_current_callback_threshold ⇒ Object
Returns the threshold as set by BrickletCurrent25#set_current_callback_threshold.
-
#get_debounce_period ⇒ Object
Returns the debounce period as set by BrickletCurrent25#set_debounce_period.
-
#get_identity ⇒ Object
Returns the UID, the UID where the Bricklet is connected to, the position, the hardware and firmware version as well as the device identifier.
-
#initialize(uid, ipcon) ⇒ BrickletCurrent25
constructor
Creates an object with the unique device ID
uid
and adds it to the IP Connectionipcon
. -
#is_over_current ⇒ Object
Returns true if more than 25A were measured.
-
#register_callback(id, &block) ⇒ Object
Registers a callback with ID
id
to the blockblock
. -
#set_analog_value_callback_period(period) ⇒ Object
Sets the period with which the CALLBACK_ANALOG_VALUE callback is triggered periodically.
-
#set_analog_value_callback_threshold(option, min, max) ⇒ Object
Sets the thresholds for the CALLBACK_ANALOG_VALUE_REACHED callback.
-
#set_current_callback_period(period) ⇒ Object
Sets the period with which the CALLBACK_CURRENT callback is triggered periodically.
-
#set_current_callback_threshold(option, min, max) ⇒ Object
Sets the thresholds for the CALLBACK_CURRENT_REACHED callback.
-
#set_debounce_period(debounce) ⇒ Object
Sets the period with which the threshold callbacks.
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) ⇒ BrickletCurrent25
Creates an object with the unique device ID uid
and adds it to the IP Connection ipcon
.
Instance Method Details
#calibrate ⇒ Object
Calibrates the 0 value of the sensor. You have to call this function when there is no current present.
The zero point of the current sensor is depending on the exact properties of the analog-to-digital converter, the length of the Bricklet cable and the temperature. Thus, if you change the Brick or the environment in which the Bricklet is used, you might have to recalibrate.
The resulting calibration will be saved on the EEPROM of the Current Bricklet.
132 133 134 135 136 |
# File 'lib/tinkerforge/bricklet_current25.rb', line 132 def calibrate check_validity send_request FUNCTION_CALIBRATE, [], '', 8, '' end |
#get_analog_value ⇒ Object
Returns the value as read by a 12-bit analog-to-digital converter.
- .. note
-
The value returned by BrickletCurrent25#get_current is averaged over several samples to yield less noise, while BrickletCurrent25#get_analog_value gives back raw unfiltered analog values. The only reason to use BrickletCurrent25#get_analog_value is, if you need the full resolution of the analog-to-digital converter.
If you want the analog value periodically, it is recommended to use the CALLBACK_ANALOG_VALUE callback and set the period with BrickletCurrent25#set_analog_value_callback_period.
159 160 161 162 163 |
# File 'lib/tinkerforge/bricklet_current25.rb', line 159 def get_analog_value check_validity send_request FUNCTION_GET_ANALOG_VALUE, [], '', 10, 'S' end |
#get_analog_value_callback_period ⇒ Object
Returns the period as set by BrickletCurrent25#set_analog_value_callback_period.
195 196 197 198 199 |
# File 'lib/tinkerforge/bricklet_current25.rb', line 195 def get_analog_value_callback_period check_validity send_request FUNCTION_GET_ANALOG_VALUE_CALLBACK_PERIOD, [], '', 12, 'L' end |
#get_analog_value_callback_threshold ⇒ Object
Returns the threshold as set by BrickletCurrent25#set_analog_value_callback_threshold.
243 244 245 246 247 |
# File 'lib/tinkerforge/bricklet_current25.rb', line 243 def get_analog_value_callback_threshold check_validity send_request FUNCTION_GET_ANALOG_VALUE_CALLBACK_THRESHOLD, [], '', 13, 'k S S' end |
#get_current ⇒ Object
Returns the current of the sensor.
If you want to get the current periodically, it is recommended to use the CALLBACK_CURRENT callback and set the period with BrickletCurrent25#set_current_callback_period.
115 116 117 118 119 |
# File 'lib/tinkerforge/bricklet_current25.rb', line 115 def get_current check_validity send_request FUNCTION_GET_CURRENT, [], '', 10, 's' end |
#get_current_callback_period ⇒ Object
Returns the period as set by BrickletCurrent25#set_current_callback_period.
177 178 179 180 181 |
# File 'lib/tinkerforge/bricklet_current25.rb', line 177 def get_current_callback_period check_validity send_request FUNCTION_GET_CURRENT_CALLBACK_PERIOD, [], '', 12, 'L' end |
#get_current_callback_threshold ⇒ Object
Returns the threshold as set by BrickletCurrent25#set_current_callback_threshold.
219 220 221 222 223 |
# File 'lib/tinkerforge/bricklet_current25.rb', line 219 def get_current_callback_threshold check_validity send_request FUNCTION_GET_CURRENT_CALLBACK_THRESHOLD, [], '', 13, 'k s s' end |
#get_debounce_period ⇒ Object
Returns the debounce period as set by BrickletCurrent25#set_debounce_period.
267 268 269 270 271 |
# File 'lib/tinkerforge/bricklet_current25.rb', line 267 def get_debounce_period check_validity send_request FUNCTION_GET_DEBOUNCE_PERIOD, [], '', 12, 'L' end |
#get_identity ⇒ Object
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|
283 284 285 |
# File 'lib/tinkerforge/bricklet_current25.rb', line 283 def get_identity send_request FUNCTION_GET_IDENTITY, [], '', 33, 'Z8 Z8 k C3 C3 S' end |
#is_over_current ⇒ Object
Returns true if more than 25A were measured.
- .. note
-
To reset this value you have to power cycle the Bricklet.
142 143 144 145 146 |
# File 'lib/tinkerforge/bricklet_current25.rb', line 142 def is_over_current check_validity send_request FUNCTION_IS_OVER_CURRENT, [], '', 9, '?' end |
#register_callback(id, &block) ⇒ Object
Registers a callback with ID id
to the block block
.
288 289 290 291 |
# File 'lib/tinkerforge/bricklet_current25.rb', line 288 def register_callback(id, &block) callback = block @registered_callbacks[id] = callback end |
#set_analog_value_callback_period(period) ⇒ Object
Sets the period with which the CALLBACK_ANALOG_VALUE callback is triggered periodically. A value of 0 turns the callback off.
The CALLBACK_ANALOG_VALUE callback is only triggered if the analog value has changed since the last triggering.
188 189 190 191 192 |
# File 'lib/tinkerforge/bricklet_current25.rb', line 188 def set_analog_value_callback_period(period) check_validity send_request FUNCTION_SET_ANALOG_VALUE_CALLBACK_PERIOD, [period], 'L', 8, '' end |
#set_analog_value_callback_threshold(option, min, max) ⇒ Object
Sets the thresholds for the CALLBACK_ANALOG_VALUE_REACHED callback.
The following options are possible:
"Option", "Description"
"'x'", "Callback is turned off"
"'o'", "Callback is triggered when the analog value is *outside* the min and max values"
"'i'", "Callback is triggered when the analog value is *inside* the min and max values"
"'<'", "Callback is triggered when the analog value is smaller than the min value (max is ignored)"
"'>'", "Callback is triggered when the analog value is greater than the min value (max is ignored)"
236 237 238 239 240 |
# File 'lib/tinkerforge/bricklet_current25.rb', line 236 def set_analog_value_callback_threshold(option, min, max) check_validity send_request FUNCTION_SET_ANALOG_VALUE_CALLBACK_THRESHOLD, [option, min, max], 'k S S', 8, '' end |
#set_current_callback_period(period) ⇒ Object
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.
170 171 172 173 174 |
# File 'lib/tinkerforge/bricklet_current25.rb', line 170 def set_current_callback_period(period) check_validity send_request FUNCTION_SET_CURRENT_CALLBACK_PERIOD, [period], 'L', 8, '' end |
#set_current_callback_threshold(option, min, max) ⇒ Object
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)"
212 213 214 215 216 |
# File 'lib/tinkerforge/bricklet_current25.rb', line 212 def set_current_callback_threshold(option, min, max) check_validity send_request FUNCTION_SET_CURRENT_CALLBACK_THRESHOLD, [option, min, max], 'k s s', 8, '' end |
#set_debounce_period(debounce) ⇒ Object
Sets the period with which the threshold callbacks
-
CALLBACK_CURRENT_REACHED,
-
CALLBACK_ANALOG_VALUE_REACHED
are triggered, if the thresholds
-
BrickletCurrent25#set_current_callback_threshold,
-
BrickletCurrent25#set_analog_value_callback_threshold
keep being reached.
260 261 262 263 264 |
# File 'lib/tinkerforge/bricklet_current25.rb', line 260 def set_debounce_period(debounce) check_validity send_request FUNCTION_SET_DEBOUNCE_PERIOD, [debounce], 'L', 8, '' end |