Class: Tinkerforge::BrickletIndustrialDualAnalogIn
- Defined in:
- lib/tinkerforge/bricklet_industrial_dual_analog_in.rb
Overview
Measures two DC voltages between -35V and +35V with 24bit resolution each
Constant Summary collapse
- DEVICE_IDENTIFIER =
:nodoc:
249
- DEVICE_DISPLAY_NAME =
:nodoc:
'Industrial Dual Analog In Bricklet'
- CALLBACK_VOLTAGE =
This callback is triggered periodically with the period that is set by BrickletIndustrialDualAnalogIn#set_voltage_callback_period. The parameter is the voltage of the channel.
The CALLBACK_VOLTAGE callback is only triggered if the voltage has changed since the last triggering.
13
- CALLBACK_VOLTAGE_REACHED =
This callback is triggered when the threshold as set by BrickletIndustrialDualAnalogIn#set_voltage_callback_threshold is reached. The parameter is the voltage of the channel.
If the threshold keeps being reached, the callback is triggered periodically with the period as set by BrickletIndustrialDualAnalogIn#set_debounce_period.
14
- FUNCTION_GET_VOLTAGE =
:nodoc:
1
- FUNCTION_SET_VOLTAGE_CALLBACK_PERIOD =
:nodoc:
2
- FUNCTION_GET_VOLTAGE_CALLBACK_PERIOD =
:nodoc:
3
- FUNCTION_SET_VOLTAGE_CALLBACK_THRESHOLD =
:nodoc:
4
- FUNCTION_GET_VOLTAGE_CALLBACK_THRESHOLD =
:nodoc:
5
- FUNCTION_SET_DEBOUNCE_PERIOD =
:nodoc:
6
- FUNCTION_GET_DEBOUNCE_PERIOD =
:nodoc:
7
- FUNCTION_SET_SAMPLE_RATE =
:nodoc:
8
- FUNCTION_GET_SAMPLE_RATE =
:nodoc:
9
- FUNCTION_SET_CALIBRATION =
:nodoc:
10
- FUNCTION_GET_CALIBRATION =
:nodoc:
11
- FUNCTION_GET_ADC_VALUES =
:nodoc:
12
- 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:
'>'
- SAMPLE_RATE_976_SPS =
:nodoc:
0
- SAMPLE_RATE_488_SPS =
:nodoc:
1
- SAMPLE_RATE_244_SPS =
:nodoc:
2
- SAMPLE_RATE_122_SPS =
:nodoc:
3
- SAMPLE_RATE_61_SPS =
:nodoc:
4
- SAMPLE_RATE_4_SPS =
:nodoc:
5
- SAMPLE_RATE_2_SPS =
:nodoc:
6
- SAMPLE_RATE_1_SPS =
:nodoc:
7
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
-
#get_adc_values ⇒ Object
Returns the ADC values as given by the MCP3911 IC.
-
#get_calibration ⇒ Object
Returns the calibration as set by BrickletIndustrialDualAnalogIn#set_calibration.
-
#get_debounce_period ⇒ Object
Returns the debounce period as set by BrickletIndustrialDualAnalogIn#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.
-
#get_sample_rate ⇒ Object
Returns the sample rate as set by BrickletIndustrialDualAnalogIn#set_sample_rate.
-
#get_voltage(channel) ⇒ Object
Returns the voltage for the given channel.
-
#get_voltage_callback_period(channel) ⇒ Object
Returns the period as set by BrickletIndustrialDualAnalogIn#set_voltage_callback_period.
-
#get_voltage_callback_threshold(channel) ⇒ Object
Returns the threshold as set by BrickletIndustrialDualAnalogIn#set_voltage_callback_threshold.
-
#initialize(uid, ipcon) ⇒ BrickletIndustrialDualAnalogIn
constructor
Creates an object with the unique device ID
uid
and adds it to the IP Connectionipcon
. -
#register_callback(id, &block) ⇒ Object
Registers a callback with ID
id
to the blockblock
. -
#set_calibration(offset, gain) ⇒ Object
Sets offset and gain of MCP3911 internal calibration registers.
-
#set_debounce_period(debounce) ⇒ Object
Sets the period with which the threshold callback.
-
#set_sample_rate(rate) ⇒ Object
Sets the sample rate.
-
#set_voltage_callback_period(channel, period) ⇒ Object
Sets the period with which the CALLBACK_VOLTAGE callback is triggered periodically for the given channel.
-
#set_voltage_callback_threshold(channel, option, min, max) ⇒ Object
Sets the thresholds for the CALLBACK_VOLTAGE_REACHED callback for the given channel.
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) ⇒ BrickletIndustrialDualAnalogIn
Creates an object with the unique device ID uid
and adds it to the IP Connection ipcon
.
Instance Method Details
#get_adc_values ⇒ Object
Returns the ADC values as given by the MCP3911 IC. This function is needed for proper calibration, see BrickletIndustrialDualAnalogIn#set_calibration.
203 204 205 206 207 |
# File 'lib/tinkerforge/bricklet_industrial_dual_analog_in.rb', line 203 def get_adc_values check_validity send_request FUNCTION_GET_ADC_VALUES, [], '', 16, 'l2' end |
#get_calibration ⇒ Object
Returns the calibration as set by BrickletIndustrialDualAnalogIn#set_calibration.
195 196 197 198 199 |
# File 'lib/tinkerforge/bricklet_industrial_dual_analog_in.rb', line 195 def get_calibration check_validity send_request FUNCTION_GET_CALIBRATION, [], '', 24, 'l2 l2' end |
#get_debounce_period ⇒ Object
Returns the debounce period as set by BrickletIndustrialDualAnalogIn#set_debounce_period.
161 162 163 164 165 |
# File 'lib/tinkerforge/bricklet_industrial_dual_analog_in.rb', line 161 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|
219 220 221 |
# File 'lib/tinkerforge/bricklet_industrial_dual_analog_in.rb', line 219 def get_identity send_request FUNCTION_GET_IDENTITY, [], '', 33, 'Z8 Z8 k C3 C3 S' end |
#get_sample_rate ⇒ Object
Returns the sample rate as set by BrickletIndustrialDualAnalogIn#set_sample_rate.
177 178 179 180 181 |
# File 'lib/tinkerforge/bricklet_industrial_dual_analog_in.rb', line 177 def get_sample_rate check_validity send_request FUNCTION_GET_SAMPLE_RATE, [], '', 9, 'C' end |
#get_voltage(channel) ⇒ Object
Returns the voltage for the given channel.
If you want to get the voltage periodically, it is recommended to use the CALLBACK_VOLTAGE callback and set the period with BrickletIndustrialDualAnalogIn#set_voltage_callback_period.
96 97 98 99 100 |
# File 'lib/tinkerforge/bricklet_industrial_dual_analog_in.rb', line 96 def get_voltage(channel) check_validity send_request FUNCTION_GET_VOLTAGE, [channel], 'C', 12, 'l' end |
#get_voltage_callback_period(channel) ⇒ Object
Returns the period as set by BrickletIndustrialDualAnalogIn#set_voltage_callback_period.
114 115 116 117 118 |
# File 'lib/tinkerforge/bricklet_industrial_dual_analog_in.rb', line 114 def get_voltage_callback_period(channel) check_validity send_request FUNCTION_GET_VOLTAGE_CALLBACK_PERIOD, [channel], 'C', 12, 'L' end |
#get_voltage_callback_threshold(channel) ⇒ Object
Returns the threshold as set by BrickletIndustrialDualAnalogIn#set_voltage_callback_threshold.
139 140 141 142 143 |
# File 'lib/tinkerforge/bricklet_industrial_dual_analog_in.rb', line 139 def get_voltage_callback_threshold(channel) check_validity send_request FUNCTION_GET_VOLTAGE_CALLBACK_THRESHOLD, [channel], 'C', 17, 'k l l' end |
#register_callback(id, &block) ⇒ Object
Registers a callback with ID id
to the block block
.
224 225 226 227 |
# File 'lib/tinkerforge/bricklet_industrial_dual_analog_in.rb', line 224 def register_callback(id, &block) callback = block @registered_callbacks[id] = callback end |
#set_calibration(offset, gain) ⇒ Object
Sets offset and gain of MCP3911 internal calibration registers.
See MCP3911 datasheet 7.7 and 7.8. The Industrial Dual Analog In Bricklet is already factory calibrated by Tinkerforge. It should not be necessary for you to use this function
188 189 190 191 192 |
# File 'lib/tinkerforge/bricklet_industrial_dual_analog_in.rb', line 188 def set_calibration(offset, gain) check_validity send_request FUNCTION_SET_CALIBRATION, [offset, gain], 'l2 l2', 8, '' end |
#set_debounce_period(debounce) ⇒ Object
Sets the period with which the threshold callback
-
CALLBACK_VOLTAGE_REACHED
is triggered, if the threshold
-
BrickletIndustrialDualAnalogIn#set_voltage_callback_threshold
keeps being reached.
154 155 156 157 158 |
# File 'lib/tinkerforge/bricklet_industrial_dual_analog_in.rb', line 154 def set_debounce_period(debounce) check_validity send_request FUNCTION_SET_DEBOUNCE_PERIOD, [debounce], 'L', 8, '' end |
#set_sample_rate(rate) ⇒ Object
Sets the sample rate. The sample rate can be between 1 sample per second and 976 samples per second. Decreasing the sample rate will also decrease the noise on the data.
170 171 172 173 174 |
# File 'lib/tinkerforge/bricklet_industrial_dual_analog_in.rb', line 170 def set_sample_rate(rate) check_validity send_request FUNCTION_SET_SAMPLE_RATE, [rate], 'C', 8, '' end |
#set_voltage_callback_period(channel, period) ⇒ Object
Sets the period with which the CALLBACK_VOLTAGE callback is triggered periodically for the given channel. A value of 0 turns the callback off.
The CALLBACK_VOLTAGE callback is only triggered if the voltage has changed since the last triggering.
107 108 109 110 111 |
# File 'lib/tinkerforge/bricklet_industrial_dual_analog_in.rb', line 107 def set_voltage_callback_period(channel, period) check_validity send_request FUNCTION_SET_VOLTAGE_CALLBACK_PERIOD, [channel, period], 'C L', 8, '' end |
#set_voltage_callback_threshold(channel, option, min, max) ⇒ Object
Sets the thresholds for the CALLBACK_VOLTAGE_REACHED callback for the given channel.
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)"
132 133 134 135 136 |
# File 'lib/tinkerforge/bricklet_industrial_dual_analog_in.rb', line 132 def set_voltage_callback_threshold(channel, option, min, max) check_validity send_request FUNCTION_SET_VOLTAGE_CALLBACK_THRESHOLD, [channel, option, min, max], 'C k l l', 8, '' end |