class Tinkerforge::BrickletIndustrialDualAnalogIn

Measures two DC voltages between -35V and +35V with 24bit resolution each

Constants

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.

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.

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_industrial_dual_analog_in.rb, line 65
def initialize(uid, ipcon)
  super uid, ipcon, DEVICE_IDENTIFIER, DEVICE_DISPLAY_NAME

  @api_version = [2, 0, 0]

  @response_expected[FUNCTION_GET_VOLTAGE] = 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_VOLTAGE_CALLBACK_THRESHOLD] = RESPONSE_EXPECTED_TRUE
  @response_expected[FUNCTION_GET_VOLTAGE_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_SET_CALIBRATION] = RESPONSE_EXPECTED_FALSE
  @response_expected[FUNCTION_GET_CALIBRATION] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_GET_ADC_VALUES] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_GET_IDENTITY] = RESPONSE_EXPECTED_ALWAYS_TRUE

  @callback_formats[CALLBACK_VOLTAGE] = [13, 'C l']
  @callback_formats[CALLBACK_VOLTAGE_REACHED] = [13, 'C l']

  @ipcon.add_device self
end

Public Instance Methods

get_adc_values() click to toggle source

Returns the ADC values as given by the MCP3911 IC. This function is needed for proper calibration, see BrickletIndustrialDualAnalogIn#set_calibration.

# File lib/tinkerforge/bricklet_industrial_dual_analog_in.rb, line 202
def get_adc_values
  check_validity

  send_request FUNCTION_GET_ADC_VALUES, [], '', 16, 'l2'
end
get_calibration() click to toggle source

Returns the calibration as set by BrickletIndustrialDualAnalogIn#set_calibration.

# File lib/tinkerforge/bricklet_industrial_dual_analog_in.rb, line 194
def get_calibration
  check_validity

  send_request FUNCTION_GET_CALIBRATION, [], '', 24, 'l2 l2'
end
get_debounce_period() click to toggle source

Returns the debounce period as set by BrickletIndustrialDualAnalogIn#set_debounce_period.

# File lib/tinkerforge/bricklet_industrial_dual_analog_in.rb, line 160
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_industrial_dual_analog_in.rb, line 218
def get_identity
  send_request FUNCTION_GET_IDENTITY, [], '', 33, 'Z8 Z8 k C3 C3 S'
end
get_sample_rate() click to toggle source

Returns the sample rate as set by BrickletIndustrialDualAnalogIn#set_sample_rate.

# File lib/tinkerforge/bricklet_industrial_dual_analog_in.rb, line 176
def get_sample_rate
  check_validity

  send_request FUNCTION_GET_SAMPLE_RATE, [], '', 9, 'C'
end
get_voltage(channel) click to toggle source

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.

# File lib/tinkerforge/bricklet_industrial_dual_analog_in.rb, line 95
def get_voltage(channel)
  check_validity

  send_request FUNCTION_GET_VOLTAGE, [channel], 'C', 12, 'l'
end
get_voltage_callback_period(channel) click to toggle source

Returns the period as set by BrickletIndustrialDualAnalogIn#set_voltage_callback_period.

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

Returns the threshold as set by BrickletIndustrialDualAnalogIn#set_voltage_callback_threshold.

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

Registers a callback with ID id to the block block.

# File lib/tinkerforge/bricklet_industrial_dual_analog_in.rb, line 223
def register_callback(id, &block)
  callback = block
  @registered_callbacks[id] = callback
end
set_calibration(offset, gain) click to toggle source

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

# File lib/tinkerforge/bricklet_industrial_dual_analog_in.rb, line 187
def set_calibration(offset, gain)
  check_validity

  send_request FUNCTION_SET_CALIBRATION, [offset, gain], 'l2 l2', 8, ''
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_industrial_dual_analog_in.rb, line 153
def set_debounce_period(debounce)
  check_validity

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

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.

# File lib/tinkerforge/bricklet_industrial_dual_analog_in.rb, line 169
def set_sample_rate(rate)
  check_validity

  send_request FUNCTION_SET_SAMPLE_RATE, [rate], 'C', 8, ''
end
set_voltage_callback_period(channel, period) click to toggle source

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.

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

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)"
# File lib/tinkerforge/bricklet_industrial_dual_analog_in.rb, line 131
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