class Tinkerforge::BrickletSolidStateRelay

Controls AC and DC Solid State Relays

Constants

CALLBACK_MONOFLOP_DONE

This callback is triggered whenever the monoflop timer reaches 0. The parameter is the current state of the relay (the state after the monoflop).

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

  @api_version = [2, 0, 0]

  @response_expected[FUNCTION_SET_STATE] = RESPONSE_EXPECTED_FALSE
  @response_expected[FUNCTION_GET_STATE] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_SET_MONOFLOP] = RESPONSE_EXPECTED_FALSE
  @response_expected[FUNCTION_GET_MONOFLOP] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_GET_IDENTITY] = RESPONSE_EXPECTED_ALWAYS_TRUE

  @callback_formats[CALLBACK_MONOFLOP_DONE] = [9, '?']

  @ipcon.add_device self
end

Public Instance Methods

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_solid_state_relay.rb, line 104
def get_identity
  send_request FUNCTION_GET_IDENTITY, [], '', 33, 'Z8 Z8 k C3 C3 S'
end
get_monoflop() click to toggle source

Returns the current state and the time as set by BrickletSolidStateRelay#set_monoflop as well as the remaining time until the state flips.

If the timer is not running currently, the remaining time will be returned as 0.

# File lib/tinkerforge/bricklet_solid_state_relay.rb, line 88
def get_monoflop
  check_validity

  send_request FUNCTION_GET_MONOFLOP, [], '', 17, '? L L'
end
get_state() click to toggle source

Returns the state of the relay, true means on and false means off.

# File lib/tinkerforge/bricklet_solid_state_relay.rb, line 59
def get_state
  check_validity

  send_request FUNCTION_GET_STATE, [], '', 9, '?'
end
register_callback(id, &block) click to toggle source

Registers a callback with ID id to the block block.

# File lib/tinkerforge/bricklet_solid_state_relay.rb, line 109
def register_callback(id, &block)
  callback = block
  @registered_callbacks[id] = callback
end
set_monoflop(state, time) click to toggle source

The first parameter is the desired state of the relay (true means on and false means off). The second parameter indicates the time that the relay should hold the state.

If this function is called with the parameters (true, 1500): The relay will turn on and in 1.5s it will turn off again.

A monoflop can be used as a failsafe mechanism. For example: Lets assume you have a RS485 bus and a Solid State Relay Bricklet connected to one of the slave stacks. You can now call this function every second, with a time parameter of two seconds. The relay will be on all the time. If now the RS485 connection is lost, the relay will turn off in at most two seconds.

# File lib/tinkerforge/bricklet_solid_state_relay.rb, line 77
def set_monoflop(state, time)
  check_validity

  send_request FUNCTION_SET_MONOFLOP, [state, time], '? L', 8, ''
end
set_state(state) click to toggle source

Sets the state of the relays true means on and false means off.

A running monoflop timer will be aborted if this function is called.

# File lib/tinkerforge/bricklet_solid_state_relay.rb, line 52
def set_state(state)
  check_validity

  send_request FUNCTION_SET_STATE, [state], '?', 8, ''
end