class Tinkerforge::BrickletIndustrialDigitalIn4

4 galvanically isolated digital inputs

Constants

CALLBACK_INTERRUPT

This callback is triggered whenever a change of the voltage level is detected on pins where the interrupt was activated with BrickletIndustrialDigitalIn4#set_interrupt.

The values are a bitmask that specifies which interrupts occurred and the current value bitmask.

For example:

  • (1, 1) or (0b0001, 0b0001) means that an interrupt on pin 0 occurred and currently pin 0 is high and pins 1-3 are low.

  • (9, 14) or (0b1001, 0b1110) means that interrupts on pins 0 and 3 occurred and currently pin 0 is low and pins 1-3 are high.

The interrupts use the grouping as set by BrickletIndustrialDigitalIn4#set_group.

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

  @api_version = [2, 0, 1]

  @response_expected[FUNCTION_GET_VALUE] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_SET_GROUP] = RESPONSE_EXPECTED_FALSE
  @response_expected[FUNCTION_GET_GROUP] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_GET_AVAILABLE_FOR_GROUP] = 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_INTERRUPT] = RESPONSE_EXPECTED_TRUE
  @response_expected[FUNCTION_GET_INTERRUPT] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_GET_EDGE_COUNT] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_SET_EDGE_COUNT_CONFIG] = RESPONSE_EXPECTED_FALSE
  @response_expected[FUNCTION_GET_EDGE_COUNT_CONFIG] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_GET_IDENTITY] = RESPONSE_EXPECTED_ALWAYS_TRUE

  @callback_formats[CALLBACK_INTERRUPT] = [12, 'S S']

  @ipcon.add_device self
end

Public Instance Methods

get_available_for_group() click to toggle source

Returns a bitmask of ports that are available for grouping. For example the value 5 or 0b0101 means: Port A and port C are connected to Bricklets that can be grouped together.

# File lib/tinkerforge/bricklet_industrial_digital_in_4.rb, line 129
def get_available_for_group
  check_validity

  send_request FUNCTION_GET_AVAILABLE_FOR_GROUP, [], '', 9, 'C'
end
get_debounce_period() click to toggle source

Returns the debounce period as set by BrickletIndustrialDigitalIn4#set_debounce_period.

# File lib/tinkerforge/bricklet_industrial_digital_in_4.rb, line 147
def get_debounce_period
  check_validity

  send_request FUNCTION_GET_DEBOUNCE_PERIOD, [], '', 12, 'L'
end
get_edge_count(pin, reset_counter) click to toggle source

Returns the current value of the edge counter for the selected pin. You can configure the edges that are counted with BrickletIndustrialDigitalIn4#set_edge_count_config.

If you set the reset counter to true, the count is set back to 0 directly after it is read.

The edge counters use the grouping as set by BrickletIndustrialDigitalIn4#set_group.

.. versionadded

2.0.1$nbsp;(Plugin)

# File lib/tinkerforge/bricklet_industrial_digital_in_4.rb, line 185
def get_edge_count(pin, reset_counter)
  check_validity

  send_request FUNCTION_GET_EDGE_COUNT, [pin, reset_counter], 'C ?', 12, 'L'
end
get_edge_count_config(pin) click to toggle source

Returns the edge type and debounce time for the selected pin as set by BrickletIndustrialDigitalIn4#set_edge_count_config.

.. versionadded

2.0.1$nbsp;(Plugin)

# File lib/tinkerforge/bricklet_industrial_digital_in_4.rb, line 219
def get_edge_count_config(pin)
  check_validity

  send_request FUNCTION_GET_EDGE_COUNT_CONFIG, [pin], 'C', 10, 'C C'
end
get_group() click to toggle source

Returns the group as set by BrickletIndustrialDigitalIn4#set_group

# File lib/tinkerforge/bricklet_industrial_digital_in_4.rb, line 120
def get_group
  check_validity

  send_request FUNCTION_GET_GROUP, [], '', 12, 'k4'
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_digital_in_4.rb, line 235
def get_identity
  send_request FUNCTION_GET_IDENTITY, [], '', 33, 'Z8 Z8 k C3 C3 S'
end
get_interrupt() click to toggle source

Returns the interrupt bitmask as set by BrickletIndustrialDigitalIn4#set_interrupt.

# File lib/tinkerforge/bricklet_industrial_digital_in_4.rb, line 170
def get_interrupt
  check_validity

  send_request FUNCTION_GET_INTERRUPT, [], '', 10, 'S'
end
get_value() click to toggle source

Returns the input value with a bitmask. The bitmask is 16bit long, true refers to high and false refers to low.

For example: The value 3 or 0b0011 means that pins 0-1 are high and the other pins are low.

If no groups are used (see BrickletIndustrialDigitalIn4#set_group), the pins correspond to the markings on the IndustrialDigital In 4 Bricklet.

If groups are used, the pins correspond to the element in the group. Element 1 in the group will get pins 0-3, element 2 pins 4-7, element 3 pins 8-11 and element 4 pins 12-15.

# File lib/tinkerforge/bricklet_industrial_digital_in_4.rb, line 89
def get_value
  check_validity

  send_request FUNCTION_GET_VALUE, [], '', 10, 'S'
end
register_callback(id, &block) click to toggle source

Registers a callback with ID id to the block block.

# File lib/tinkerforge/bricklet_industrial_digital_in_4.rb, line 240
def register_callback(id, &block)
  callback = block
  @registered_callbacks[id] = callback
end
set_debounce_period(debounce) click to toggle source

Sets the debounce period of the CALLBACK_INTERRUPT callback.

For example: If you set this value to 100, you will get the interrupt maximal every 100ms. This is necessary if something that bounces is connected to the Digital In 4 Bricklet, such as a button.

# File lib/tinkerforge/bricklet_industrial_digital_in_4.rb, line 140
def set_debounce_period(debounce)
  check_validity

  send_request FUNCTION_SET_DEBOUNCE_PERIOD, [debounce], 'L', 8, ''
end
set_edge_count_config(selection_mask, edge_type, debounce) click to toggle source

Configures the edge counter for the selected pins. A bitmask of 9 or 0b1001 will enable the edge counter for pins 0 and 3.

The edge type parameter configures if rising edges, falling edges or both are counted if the pin is configured for input. Possible edge types are:

  • 0 = rising

  • 1 = falling

  • 2 = both

Configuring an edge counter resets its value to 0.

If you don't know what any of this means, just leave it at default. The default configuration is very likely OK for you.

The edge counters use the grouping as set by BrickletIndustrialDigitalIn4#set_group.

.. versionadded

2.0.1$nbsp;(Plugin)

# File lib/tinkerforge/bricklet_industrial_digital_in_4.rb, line 209
def set_edge_count_config(selection_mask, edge_type, debounce)
  check_validity

  send_request FUNCTION_SET_EDGE_COUNT_CONFIG, [selection_mask, edge_type, debounce], 'S C C', 8, ''
end
set_group(group) click to toggle source

Sets a group of Digital In 4 Bricklets that should work together. You can find Bricklets that can be grouped together with BrickletIndustrialDigitalIn4#get_available_for_group.

The group consists of 4 elements. Element 1 in the group will get pins 0-3, element 2 pins 4-7, element 3 pins 8-11 and element 4 pins 12-15.

Each element can either be one of the ports ('a' to 'd') or 'n' if it should not be used.

For example: If you have two Digital In 4 Bricklets connected to port A and port B respectively, you could call with “['a', 'b', 'n', 'n']“.

Now the pins on the Digital In 4 on port A are assigned to 0-3 and the pins on the Digital In 4 on port B are assigned to 4-7. It is now possible to call BrickletIndustrialDigitalIn4#get_value and read out two Bricklets at the same time.

Changing the group configuration resets all edge counter configurations and values.

# File lib/tinkerforge/bricklet_industrial_digital_in_4.rb, line 113
def set_group(group)
  check_validity

  send_request FUNCTION_SET_GROUP, [group], 'k4', 8, ''
end
set_interrupt(interrupt_mask) click to toggle source

Sets the pins on which an interrupt is activated with a bitmask. Interrupts are triggered on changes of the voltage level of the pin, i.e. changes from high to low and low to high.

For example: An interrupt bitmask of 9 or 0b1001 will enable the interrupt for pins 0 and 3.

The interrupts use the grouping as set by BrickletIndustrialDigitalIn4#set_group.

The interrupt is delivered with the CALLBACK_INTERRUPT callback.

# File lib/tinkerforge/bricklet_industrial_digital_in_4.rb, line 163
def set_interrupt(interrupt_mask)
  check_validity

  send_request FUNCTION_SET_INTERRUPT, [interrupt_mask], 'S', 8, ''
end