Class: Tinkerforge::BrickletSolidStateRelay

Inherits:
Device
  • Object
show all
Defined in:
lib/tinkerforge/bricklet_solid_state_relay.rb

Overview

Controls AC and DC Solid State Relays

Constant Summary collapse

DEVICE_IDENTIFIER =

:nodoc:

244
DEVICE_DISPLAY_NAME =

:nodoc:

'Solid State Relay Bricklet'
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).

5
FUNCTION_SET_STATE =

:nodoc:

1
FUNCTION_GET_STATE =

:nodoc:

2
FUNCTION_SET_MONOFLOP =

:nodoc:

3
FUNCTION_GET_MONOFLOP =

:nodoc:

4
FUNCTION_GET_IDENTITY =

:nodoc:

255

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

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) ⇒ BrickletSolidStateRelay

Creates an object with the unique device ID uid and adds it to the IP Connection ipcon.



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/tinkerforge/bricklet_solid_state_relay.rb', line 34

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

Instance Method Details

#get_identityObject

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|



105
106
107
# File 'lib/tinkerforge/bricklet_solid_state_relay.rb', line 105

def get_identity
  send_request FUNCTION_GET_IDENTITY, [], '', 33, 'Z8 Z8 k C3 C3 S'
end

#get_monoflopObject

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.



89
90
91
92
93
# File 'lib/tinkerforge/bricklet_solid_state_relay.rb', line 89

def get_monoflop
  check_validity

  send_request FUNCTION_GET_MONOFLOP, [], '', 17, '? L L'
end

#get_stateObject

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



60
61
62
63
64
# File 'lib/tinkerforge/bricklet_solid_state_relay.rb', line 60

def get_state
  check_validity

  send_request FUNCTION_GET_STATE, [], '', 9, '?'
end

#register_callback(id, &block) ⇒ Object

Registers a callback with ID id to the block block.



110
111
112
113
# File 'lib/tinkerforge/bricklet_solid_state_relay.rb', line 110

def register_callback(id, &block)
  callback = block
  @registered_callbacks[id] = callback
end

#set_monoflop(state, time) ⇒ Object

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.



78
79
80
81
82
# File 'lib/tinkerforge/bricklet_solid_state_relay.rb', line 78

def set_monoflop(state, time)
  check_validity

  send_request FUNCTION_SET_MONOFLOP, [state, time], '? L', 8, ''
end

#set_state(state) ⇒ Object

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.



53
54
55
56
57
# File 'lib/tinkerforge/bricklet_solid_state_relay.rb', line 53

def set_state(state)
  check_validity

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