tinkerforge 2.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/tinkerforge.rb +5 -0
- data/lib/tinkerforge/brick_dc.rb +359 -0
- data/lib/tinkerforge/brick_imu.rb +512 -0
- data/lib/tinkerforge/brick_master.rb +1120 -0
- data/lib/tinkerforge/brick_servo.rb +475 -0
- data/lib/tinkerforge/brick_stepper.rb +556 -0
- data/lib/tinkerforge/bricklet_ambient_light.rb +246 -0
- data/lib/tinkerforge/bricklet_analog_in.rb +273 -0
- data/lib/tinkerforge/bricklet_analog_out.rb +90 -0
- data/lib/tinkerforge/bricklet_barometer.rb +313 -0
- data/lib/tinkerforge/bricklet_current12.rb +274 -0
- data/lib/tinkerforge/bricklet_current25.rb +274 -0
- data/lib/tinkerforge/bricklet_distance_ir.rb +274 -0
- data/lib/tinkerforge/bricklet_dual_relay.rb +127 -0
- data/lib/tinkerforge/bricklet_gps.rb +301 -0
- data/lib/tinkerforge/bricklet_humidity.rb +245 -0
- data/lib/tinkerforge/bricklet_industrial_digital_in_4.rb +165 -0
- data/lib/tinkerforge/bricklet_industrial_digital_out_4.rb +177 -0
- data/lib/tinkerforge/bricklet_industrial_quad_relay.rb +177 -0
- data/lib/tinkerforge/bricklet_io16.rb +237 -0
- data/lib/tinkerforge/bricklet_io4.rb +236 -0
- data/lib/tinkerforge/bricklet_joystick.rb +274 -0
- data/lib/tinkerforge/bricklet_lcd_16x2.rb +175 -0
- data/lib/tinkerforge/bricklet_lcd_20x4.rb +231 -0
- data/lib/tinkerforge/bricklet_linear_poti.rb +241 -0
- data/lib/tinkerforge/bricklet_piezo_buzzer.rb +84 -0
- data/lib/tinkerforge/bricklet_ptc.rb +277 -0
- data/lib/tinkerforge/bricklet_rotary_poti.rb +241 -0
- data/lib/tinkerforge/bricklet_temperature.rb +188 -0
- data/lib/tinkerforge/bricklet_temperature_ir.rb +275 -0
- data/lib/tinkerforge/bricklet_voltage.rb +241 -0
- data/lib/tinkerforge/bricklet_voltage_current.rb +386 -0
- data/lib/tinkerforge/ip_connection.rb +1027 -0
- data/lib/tinkerforge/version.rb +4 -0
- metadata +98 -0
@@ -0,0 +1,165 @@
|
|
1
|
+
# -*- ruby encoding: utf-8 -*-
|
2
|
+
#############################################################
|
3
|
+
# This file was automatically generated on 2013-05-16. #
|
4
|
+
# #
|
5
|
+
# Bindings Version 2.0.7 #
|
6
|
+
# #
|
7
|
+
# If you have a bugfix for this file and want to commit it, #
|
8
|
+
# please fix the bug in the generator. You can find a link #
|
9
|
+
# to the generator git on tinkerforge.com #
|
10
|
+
#############################################################
|
11
|
+
|
12
|
+
module Tinkerforge
|
13
|
+
# Device for controlling up to 4 optically coupled digital inputs
|
14
|
+
class BrickletIndustrialDigitalIn4 < Device
|
15
|
+
DEVICE_IDENTIFIER = 223 # :nodoc:
|
16
|
+
|
17
|
+
# This callback is triggered whenever a change of the voltage level is detected
|
18
|
+
# on pins where the interrupt was activated with BrickletIndustrialDigitalIn4#set_interrupt.
|
19
|
+
#
|
20
|
+
# The values are a bitmask that specifies which interrupts occurred
|
21
|
+
# and the current value bitmask.
|
22
|
+
#
|
23
|
+
# For example:
|
24
|
+
#
|
25
|
+
# * (1, 1) means that an interrupt on pin 0 occurred and
|
26
|
+
# currently pin 0 is high and pins 1-3 are low.
|
27
|
+
# * (9, 14) means that interrupts on pins 0 and 3
|
28
|
+
# occurred and currently pin 0 is low and pins 1-3 are high.
|
29
|
+
CALLBACK_INTERRUPT = 9
|
30
|
+
|
31
|
+
FUNCTION_GET_VALUE = 1 # :nodoc:
|
32
|
+
FUNCTION_SET_GROUP = 2 # :nodoc:
|
33
|
+
FUNCTION_GET_GROUP = 3 # :nodoc:
|
34
|
+
FUNCTION_GET_AVAILABLE_FOR_GROUP = 4 # :nodoc:
|
35
|
+
FUNCTION_SET_DEBOUNCE_PERIOD = 5 # :nodoc:
|
36
|
+
FUNCTION_GET_DEBOUNCE_PERIOD = 6 # :nodoc:
|
37
|
+
FUNCTION_SET_INTERRUPT = 7 # :nodoc:
|
38
|
+
FUNCTION_GET_INTERRUPT = 8 # :nodoc:
|
39
|
+
FUNCTION_GET_IDENTITY = 255 # :nodoc:
|
40
|
+
|
41
|
+
|
42
|
+
# Creates an object with the unique device ID <tt>uid</tt> and adds it to
|
43
|
+
# the IP Connection <tt>ipcon</tt>.
|
44
|
+
def initialize(uid, ipcon)
|
45
|
+
super uid, ipcon
|
46
|
+
|
47
|
+
@api_version = [2, 0, 0]
|
48
|
+
|
49
|
+
@response_expected[FUNCTION_GET_VALUE] = RESPONSE_EXPECTED_ALWAYS_TRUE
|
50
|
+
@response_expected[FUNCTION_SET_GROUP] = RESPONSE_EXPECTED_FALSE
|
51
|
+
@response_expected[FUNCTION_GET_GROUP] = RESPONSE_EXPECTED_ALWAYS_TRUE
|
52
|
+
@response_expected[FUNCTION_GET_AVAILABLE_FOR_GROUP] = RESPONSE_EXPECTED_ALWAYS_TRUE
|
53
|
+
@response_expected[FUNCTION_SET_DEBOUNCE_PERIOD] = RESPONSE_EXPECTED_TRUE
|
54
|
+
@response_expected[FUNCTION_GET_DEBOUNCE_PERIOD] = RESPONSE_EXPECTED_ALWAYS_TRUE
|
55
|
+
@response_expected[FUNCTION_SET_INTERRUPT] = RESPONSE_EXPECTED_TRUE
|
56
|
+
@response_expected[FUNCTION_GET_INTERRUPT] = RESPONSE_EXPECTED_ALWAYS_TRUE
|
57
|
+
@response_expected[CALLBACK_INTERRUPT] = RESPONSE_EXPECTED_ALWAYS_FALSE
|
58
|
+
@response_expected[FUNCTION_GET_IDENTITY] = RESPONSE_EXPECTED_ALWAYS_TRUE
|
59
|
+
|
60
|
+
@callback_formats[CALLBACK_INTERRUPT] = 'S S'
|
61
|
+
end
|
62
|
+
|
63
|
+
# Returns the input value with a bitmask. The bitmask
|
64
|
+
# is 16 bit long, *true* refers to high and *false* refers to
|
65
|
+
# low.
|
66
|
+
#
|
67
|
+
# For example: The value 0b0000000000000011 means that pins 0-1
|
68
|
+
# are high and the other pins are low.
|
69
|
+
#
|
70
|
+
# If no groups are used (see BrickletIndustrialDigitalIn4#set_group), the pins correspond to the
|
71
|
+
# markings on the Digital In 4 Bricklet.
|
72
|
+
#
|
73
|
+
# If groups are used, the pins correspond to the element in the group.
|
74
|
+
# Element 1 in the group will get pins 0-3, element 2 pins 4-7, element 3
|
75
|
+
# pins 8-11 and element 4 pins 12-15.
|
76
|
+
def get_value
|
77
|
+
send_request(FUNCTION_GET_VALUE, [], '', 2, 'S')
|
78
|
+
end
|
79
|
+
|
80
|
+
# Sets a group of Digital In 4 Bricklets that should work together. You can
|
81
|
+
# find Bricklets that can be grouped together with BrickletIndustrialDigitalIn4#get_available_for_group.
|
82
|
+
#
|
83
|
+
# The group consists of 4 elements. Element 1 in the group will get pins 0-3,
|
84
|
+
# element 2 pins 4-7, element 3 pins 8-11 and element 4 pins 12-15.
|
85
|
+
#
|
86
|
+
# Each element can either be one of the ports ('a' to 'd') or 'n' if it should
|
87
|
+
# not be used.
|
88
|
+
#
|
89
|
+
# For example: If you have two Digital In 4 Bricklets connected to port A and
|
90
|
+
# port B respectively, you could call with "['a', 'b', 'n', 'n']".
|
91
|
+
#
|
92
|
+
# Now the pins on the Digital In 4 on port A are assigned to 0-3 and the
|
93
|
+
# pins on the Digital In 4 on port B are assigned to 4-7. It is now possible
|
94
|
+
# to call BrickletIndustrialDigitalIn4#get_value and read out two Bricklets at the same time.
|
95
|
+
def set_group(group)
|
96
|
+
send_request(FUNCTION_SET_GROUP, [group], 'k4', 0, '')
|
97
|
+
end
|
98
|
+
|
99
|
+
# Returns the group as set by BrickletIndustrialDigitalIn4#set_group
|
100
|
+
def get_group
|
101
|
+
send_request(FUNCTION_GET_GROUP, [], '', 4, 'k4')
|
102
|
+
end
|
103
|
+
|
104
|
+
# Returns a bitmask of ports that are available for grouping. For example the
|
105
|
+
# value 0b0101 means: Port *A* and Port *C* are connected to Bricklets that
|
106
|
+
# can be grouped together.
|
107
|
+
def get_available_for_group
|
108
|
+
send_request(FUNCTION_GET_AVAILABLE_FOR_GROUP, [], '', 1, 'C')
|
109
|
+
end
|
110
|
+
|
111
|
+
# Sets the debounce period of the CALLBACK_INTERRUPT callback in ms.
|
112
|
+
#
|
113
|
+
# For example: If you set this value to 100, you will get the interrupt
|
114
|
+
# maximal every 100ms. This is necessary if something that bounces is
|
115
|
+
# connected to the Digital In 4 Bricklet, such as a button.
|
116
|
+
#
|
117
|
+
# The default value is 100.
|
118
|
+
def set_debounce_period(debounce)
|
119
|
+
send_request(FUNCTION_SET_DEBOUNCE_PERIOD, [debounce], 'L', 0, '')
|
120
|
+
end
|
121
|
+
|
122
|
+
# Returns the debounce period as set by BrickletIndustrialDigitalIn4#set_debounce_period.
|
123
|
+
def get_debounce_period
|
124
|
+
send_request(FUNCTION_GET_DEBOUNCE_PERIOD, [], '', 4, 'L')
|
125
|
+
end
|
126
|
+
|
127
|
+
# Sets the pins on which an interrupt is activated with a bitmask.
|
128
|
+
# Interrupts are triggered on changes of the voltage level of the pin,
|
129
|
+
# i.e. changes from high to low and low to high.
|
130
|
+
#
|
131
|
+
# For example: An interrupt bitmask of 9 (0b0000000000001001) will
|
132
|
+
# enable the interrupt for pins 0 and 3.
|
133
|
+
#
|
134
|
+
# The interrupts use the grouping as set by BrickletIndustrialDigitalIn4#set_group.
|
135
|
+
#
|
136
|
+
# The interrupt is delivered with the callback CALLBACK_INTERRUPT.
|
137
|
+
def set_interrupt(interrupt_mask)
|
138
|
+
send_request(FUNCTION_SET_INTERRUPT, [interrupt_mask], 'S', 0, '')
|
139
|
+
end
|
140
|
+
|
141
|
+
# Returns the interrupt bitmask as set by BrickletIndustrialDigitalIn4#set_interrupt.
|
142
|
+
def get_interrupt
|
143
|
+
send_request(FUNCTION_GET_INTERRUPT, [], '', 2, 'S')
|
144
|
+
end
|
145
|
+
|
146
|
+
# Returns the UID, the UID where the Bricklet is connected to,
|
147
|
+
# the position, the hardware and firmware version as well as the
|
148
|
+
# device identifier.
|
149
|
+
#
|
150
|
+
# The position can be 'a', 'b', 'c' or 'd'.
|
151
|
+
#
|
152
|
+
# The device identifiers can be found :ref:`here <device_identifier>`.
|
153
|
+
#
|
154
|
+
# .. versionadded:: 2.0.0~(Plugin)
|
155
|
+
def get_identity
|
156
|
+
send_request(FUNCTION_GET_IDENTITY, [], '', 25, 'Z8 Z8 k C3 C3 S')
|
157
|
+
end
|
158
|
+
|
159
|
+
# Registers a callback with ID <tt>id</tt> to the block <tt>block</tt>.
|
160
|
+
def register_callback(id, &block)
|
161
|
+
callback = block
|
162
|
+
@registered_callbacks[id] = callback
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
@@ -0,0 +1,177 @@
|
|
1
|
+
# -*- ruby encoding: utf-8 -*-
|
2
|
+
#############################################################
|
3
|
+
# This file was automatically generated on 2013-05-16. #
|
4
|
+
# #
|
5
|
+
# Bindings Version 2.0.7 #
|
6
|
+
# #
|
7
|
+
# If you have a bugfix for this file and want to commit it, #
|
8
|
+
# please fix the bug in the generator. You can find a link #
|
9
|
+
# to the generator git on tinkerforge.com #
|
10
|
+
#############################################################
|
11
|
+
|
12
|
+
module Tinkerforge
|
13
|
+
# Device for controlling up to 4 optically coupled digital outputs
|
14
|
+
class BrickletIndustrialDigitalOut4 < Device
|
15
|
+
DEVICE_IDENTIFIER = 224 # :nodoc:
|
16
|
+
|
17
|
+
# This callback is triggered whenever a monoflop timer reaches 0. The
|
18
|
+
# parameters contain the involved pins and the current value of the pins
|
19
|
+
# (the value after the monoflop).
|
20
|
+
CALLBACK_MONOFLOP_DONE = 8
|
21
|
+
|
22
|
+
FUNCTION_SET_VALUE = 1 # :nodoc:
|
23
|
+
FUNCTION_GET_VALUE = 2 # :nodoc:
|
24
|
+
FUNCTION_SET_MONOFLOP = 3 # :nodoc:
|
25
|
+
FUNCTION_GET_MONOFLOP = 4 # :nodoc:
|
26
|
+
FUNCTION_SET_GROUP = 5 # :nodoc:
|
27
|
+
FUNCTION_GET_GROUP = 6 # :nodoc:
|
28
|
+
FUNCTION_GET_AVAILABLE_FOR_GROUP = 7 # :nodoc:
|
29
|
+
FUNCTION_SET_SELECTED_VALUES = 9 # :nodoc:
|
30
|
+
FUNCTION_GET_IDENTITY = 255 # :nodoc:
|
31
|
+
|
32
|
+
|
33
|
+
# Creates an object with the unique device ID <tt>uid</tt> and adds it to
|
34
|
+
# the IP Connection <tt>ipcon</tt>.
|
35
|
+
def initialize(uid, ipcon)
|
36
|
+
super uid, ipcon
|
37
|
+
|
38
|
+
@api_version = [2, 0, 0]
|
39
|
+
|
40
|
+
@response_expected[FUNCTION_SET_VALUE] = RESPONSE_EXPECTED_FALSE
|
41
|
+
@response_expected[FUNCTION_GET_VALUE] = RESPONSE_EXPECTED_ALWAYS_TRUE
|
42
|
+
@response_expected[FUNCTION_SET_MONOFLOP] = RESPONSE_EXPECTED_FALSE
|
43
|
+
@response_expected[FUNCTION_GET_MONOFLOP] = RESPONSE_EXPECTED_ALWAYS_TRUE
|
44
|
+
@response_expected[FUNCTION_SET_GROUP] = RESPONSE_EXPECTED_FALSE
|
45
|
+
@response_expected[FUNCTION_GET_GROUP] = RESPONSE_EXPECTED_ALWAYS_TRUE
|
46
|
+
@response_expected[FUNCTION_GET_AVAILABLE_FOR_GROUP] = RESPONSE_EXPECTED_ALWAYS_TRUE
|
47
|
+
@response_expected[CALLBACK_MONOFLOP_DONE] = RESPONSE_EXPECTED_ALWAYS_FALSE
|
48
|
+
@response_expected[FUNCTION_SET_SELECTED_VALUES] = RESPONSE_EXPECTED_FALSE
|
49
|
+
@response_expected[FUNCTION_GET_IDENTITY] = RESPONSE_EXPECTED_ALWAYS_TRUE
|
50
|
+
|
51
|
+
@callback_formats[CALLBACK_MONOFLOP_DONE] = 'S S'
|
52
|
+
end
|
53
|
+
|
54
|
+
# Sets the output value with a bitmask. The bitmask
|
55
|
+
# is 16 bit long, *true* refers to high and *false* refers to
|
56
|
+
# low.
|
57
|
+
#
|
58
|
+
# For example: The value 0b0000000000000011 will turn pins 0-1
|
59
|
+
# high and the other pins low.
|
60
|
+
#
|
61
|
+
# If no groups are used (see BrickletIndustrialDigitalOut4#set_group), the pins correspond to the
|
62
|
+
# markings on the Digital Out 4 Bricklet.
|
63
|
+
#
|
64
|
+
# If groups are used, the pins correspond to the element in the group.
|
65
|
+
# Element 1 in the group will get pins 0-3, element 2 pins 4-7, element 3
|
66
|
+
# pins 8-11 and element 4 pins 12-15.
|
67
|
+
def set_value(value_mask)
|
68
|
+
send_request(FUNCTION_SET_VALUE, [value_mask], 'S', 0, '')
|
69
|
+
end
|
70
|
+
|
71
|
+
# Returns the bitmask as set by BrickletIndustrialDigitalOut4#set_value.
|
72
|
+
def get_value
|
73
|
+
send_request(FUNCTION_GET_VALUE, [], '', 2, 'S')
|
74
|
+
end
|
75
|
+
|
76
|
+
# Configures a monoflop of the pins specified by the first parameter
|
77
|
+
# bitmask.
|
78
|
+
#
|
79
|
+
# The second parameter is a bitmask with the desired value of the specified
|
80
|
+
# pins (*true* means high and *false* means low).
|
81
|
+
#
|
82
|
+
# The third parameter indicates the time (in ms) that the pins should hold
|
83
|
+
# the value.
|
84
|
+
#
|
85
|
+
# If this function is called with the parameters
|
86
|
+
# ((1 << 0) | (1 << 3), (1 << 0), 1500):
|
87
|
+
# Pin 0 will get high and pin 3 will get low. In 1.5s pin 0 will get low and
|
88
|
+
# pin 3 will get high again.
|
89
|
+
#
|
90
|
+
# A monoflop can be used as a fail-safe mechanism. For example: Lets assume you
|
91
|
+
# have a RS485 bus and a Digital Out 4 Bricklet connected to one of the slave
|
92
|
+
# stacks. You can now call this function every second, with a time parameter
|
93
|
+
# of two seconds and pin 0 high. Pin 0 will be high all the time. If now
|
94
|
+
# the RS485 connection is lost, then pin 0 will turn low in at most two seconds.
|
95
|
+
def set_monoflop(selection_mask, value_mask, time)
|
96
|
+
send_request(FUNCTION_SET_MONOFLOP, [selection_mask, value_mask, time], 'S S L', 0, '')
|
97
|
+
end
|
98
|
+
|
99
|
+
# Returns (for the given pin) the current value and the time as set by
|
100
|
+
# BrickletIndustrialDigitalOut4#set_monoflop as well as the remaining time until the value flips.
|
101
|
+
#
|
102
|
+
# If the timer is not running currently, the remaining time will be returned
|
103
|
+
# as 0.
|
104
|
+
def get_monoflop(pin)
|
105
|
+
send_request(FUNCTION_GET_MONOFLOP, [pin], 'C', 10, 'S L L')
|
106
|
+
end
|
107
|
+
|
108
|
+
# Sets a group of Digital Out 4 Bricklets that should work together. You can
|
109
|
+
# find Bricklets that can be grouped together with BrickletIndustrialDigitalOut4#get_available_for_group.
|
110
|
+
#
|
111
|
+
# The group consists of 4 elements. Element 1 in the group will get pins 0-3,
|
112
|
+
# element 2 pins 4-7, element 3 pins 8-11 and element 4 pins 12-15.
|
113
|
+
#
|
114
|
+
# Each element can either be one of the ports ('a' to 'd') or 'n' if it should
|
115
|
+
# not be used.
|
116
|
+
#
|
117
|
+
# For example: If you have two Digital Out 4 Bricklets connected to port A and
|
118
|
+
# port B respectively, you could call with "['a', 'b', 'n', 'n']".
|
119
|
+
#
|
120
|
+
# Now the pins on the Digital Out 4 on port A are assigned to 0-3 and the
|
121
|
+
# pins on the Digital Out 4 on port B are assigned to 4-7. It is now possible
|
122
|
+
# to call BrickletIndustrialDigitalOut4#set_value and control two Bricklets at the same time.
|
123
|
+
def set_group(group)
|
124
|
+
send_request(FUNCTION_SET_GROUP, [group], 'k4', 0, '')
|
125
|
+
end
|
126
|
+
|
127
|
+
# Returns the group as set by BrickletIndustrialDigitalOut4#set_group
|
128
|
+
def get_group
|
129
|
+
send_request(FUNCTION_GET_GROUP, [], '', 4, 'k4')
|
130
|
+
end
|
131
|
+
|
132
|
+
# Returns a bitmask of ports that are available for grouping. For example the
|
133
|
+
# value 0b0101 means: Port *A* and Port *C* are connected to Bricklets that
|
134
|
+
# can be grouped together.
|
135
|
+
def get_available_for_group
|
136
|
+
send_request(FUNCTION_GET_AVAILABLE_FOR_GROUP, [], '', 1, 'C')
|
137
|
+
end
|
138
|
+
|
139
|
+
# Sets the output value with a bitmask, according to the selection mask.
|
140
|
+
# The bitmask is 16 bit long, *true* refers to high and *false* refers to
|
141
|
+
# low.
|
142
|
+
#
|
143
|
+
# For example: The values 0b0000000000000011, b0000000000000001 will turn
|
144
|
+
# pin 0 high, pin 1 low the other pins remain untouched.
|
145
|
+
#
|
146
|
+
# If no groups are used (see BrickletIndustrialDigitalOut4#set_group), the pins correspond to the
|
147
|
+
# markings on the Digital Out 4 Bricklet.
|
148
|
+
#
|
149
|
+
# If groups are used, the pins correspond to the element in the group.
|
150
|
+
# Element 1 in the group will get pins 0-3, element 2 pins 4-7, element 3
|
151
|
+
# pins 8-11 and element 4 pins 12-15.
|
152
|
+
#
|
153
|
+
# .. versionadded:: 2.0.0~(Plugin)
|
154
|
+
def set_selected_values(selection_mask, value_mask)
|
155
|
+
send_request(FUNCTION_SET_SELECTED_VALUES, [selection_mask, value_mask], 'S S', 0, '')
|
156
|
+
end
|
157
|
+
|
158
|
+
# Returns the UID, the UID where the Bricklet is connected to,
|
159
|
+
# the position, the hardware and firmware version as well as the
|
160
|
+
# device identifier.
|
161
|
+
#
|
162
|
+
# The position can be 'a', 'b', 'c' or 'd'.
|
163
|
+
#
|
164
|
+
# The device identifiers can be found :ref:`here <device_identifier>`.
|
165
|
+
#
|
166
|
+
# .. versionadded:: 2.0.0~(Plugin)
|
167
|
+
def get_identity
|
168
|
+
send_request(FUNCTION_GET_IDENTITY, [], '', 25, 'Z8 Z8 k C3 C3 S')
|
169
|
+
end
|
170
|
+
|
171
|
+
# Registers a callback with ID <tt>id</tt> to the block <tt>block</tt>.
|
172
|
+
def register_callback(id, &block)
|
173
|
+
callback = block
|
174
|
+
@registered_callbacks[id] = callback
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
@@ -0,0 +1,177 @@
|
|
1
|
+
# -*- ruby encoding: utf-8 -*-
|
2
|
+
#############################################################
|
3
|
+
# This file was automatically generated on 2013-05-16. #
|
4
|
+
# #
|
5
|
+
# Bindings Version 2.0.7 #
|
6
|
+
# #
|
7
|
+
# If you have a bugfix for this file and want to commit it, #
|
8
|
+
# please fix the bug in the generator. You can find a link #
|
9
|
+
# to the generator git on tinkerforge.com #
|
10
|
+
#############################################################
|
11
|
+
|
12
|
+
module Tinkerforge
|
13
|
+
# Device for controlling up to 4 Solid State Relays
|
14
|
+
class BrickletIndustrialQuadRelay < Device
|
15
|
+
DEVICE_IDENTIFIER = 225 # :nodoc:
|
16
|
+
|
17
|
+
# This callback is triggered whenever a monoflop timer reaches 0. The
|
18
|
+
# parameters contain the involved pins and the current value of the pins
|
19
|
+
# (the value after the monoflop).
|
20
|
+
CALLBACK_MONOFLOP_DONE = 8
|
21
|
+
|
22
|
+
FUNCTION_SET_VALUE = 1 # :nodoc:
|
23
|
+
FUNCTION_GET_VALUE = 2 # :nodoc:
|
24
|
+
FUNCTION_SET_MONOFLOP = 3 # :nodoc:
|
25
|
+
FUNCTION_GET_MONOFLOP = 4 # :nodoc:
|
26
|
+
FUNCTION_SET_GROUP = 5 # :nodoc:
|
27
|
+
FUNCTION_GET_GROUP = 6 # :nodoc:
|
28
|
+
FUNCTION_GET_AVAILABLE_FOR_GROUP = 7 # :nodoc:
|
29
|
+
FUNCTION_SET_SELECTED_VALUES = 9 # :nodoc:
|
30
|
+
FUNCTION_GET_IDENTITY = 255 # :nodoc:
|
31
|
+
|
32
|
+
|
33
|
+
# Creates an object with the unique device ID <tt>uid</tt> and adds it to
|
34
|
+
# the IP Connection <tt>ipcon</tt>.
|
35
|
+
def initialize(uid, ipcon)
|
36
|
+
super uid, ipcon
|
37
|
+
|
38
|
+
@api_version = [2, 0, 0]
|
39
|
+
|
40
|
+
@response_expected[FUNCTION_SET_VALUE] = RESPONSE_EXPECTED_FALSE
|
41
|
+
@response_expected[FUNCTION_GET_VALUE] = RESPONSE_EXPECTED_ALWAYS_TRUE
|
42
|
+
@response_expected[FUNCTION_SET_MONOFLOP] = RESPONSE_EXPECTED_FALSE
|
43
|
+
@response_expected[FUNCTION_GET_MONOFLOP] = RESPONSE_EXPECTED_ALWAYS_TRUE
|
44
|
+
@response_expected[FUNCTION_SET_GROUP] = RESPONSE_EXPECTED_FALSE
|
45
|
+
@response_expected[FUNCTION_GET_GROUP] = RESPONSE_EXPECTED_ALWAYS_TRUE
|
46
|
+
@response_expected[FUNCTION_GET_AVAILABLE_FOR_GROUP] = RESPONSE_EXPECTED_ALWAYS_TRUE
|
47
|
+
@response_expected[CALLBACK_MONOFLOP_DONE] = RESPONSE_EXPECTED_ALWAYS_FALSE
|
48
|
+
@response_expected[FUNCTION_SET_SELECTED_VALUES] = RESPONSE_EXPECTED_FALSE
|
49
|
+
@response_expected[FUNCTION_GET_IDENTITY] = RESPONSE_EXPECTED_ALWAYS_TRUE
|
50
|
+
|
51
|
+
@callback_formats[CALLBACK_MONOFLOP_DONE] = 'S S'
|
52
|
+
end
|
53
|
+
|
54
|
+
# Sets the output value with a bitmask. The bitmask
|
55
|
+
# is 16 bit long, *true* refers to a closed relay and *false* refers to
|
56
|
+
# an open relay.
|
57
|
+
#
|
58
|
+
# For example: The value 0b0000000000000011 will close the relay
|
59
|
+
# of pins 0-1 and open the other pins.
|
60
|
+
#
|
61
|
+
# If no groups are used (see BrickletIndustrialQuadRelay#set_group), the pins correspond to the
|
62
|
+
# markings on the Quad Relay Bricklet.
|
63
|
+
#
|
64
|
+
# If groups are used, the pins correspond to the element in the group.
|
65
|
+
# Element 1 in the group will get pins 0-3, element 2 pins 4-7, element 3
|
66
|
+
# pins 8-11 and element 4 pins 12-15.
|
67
|
+
def set_value(value_mask)
|
68
|
+
send_request(FUNCTION_SET_VALUE, [value_mask], 'S', 0, '')
|
69
|
+
end
|
70
|
+
|
71
|
+
# Returns the bitmask as set by BrickletIndustrialQuadRelay#set_value.
|
72
|
+
def get_value
|
73
|
+
send_request(FUNCTION_GET_VALUE, [], '', 2, 'S')
|
74
|
+
end
|
75
|
+
|
76
|
+
# Configures a monoflop of the pins specified by the first parameter
|
77
|
+
# bitmask.
|
78
|
+
#
|
79
|
+
# The second parameter is a bitmask with the desired value of the specified
|
80
|
+
# pins (*true* means relay closed and *false* means relay open).
|
81
|
+
#
|
82
|
+
# The third parameter indicates the time (in ms) that the pins should hold
|
83
|
+
# the value.
|
84
|
+
#
|
85
|
+
# If this function is called with the parameters
|
86
|
+
# ((1 << 0) | (1 << 3), (1 << 0), 1500):
|
87
|
+
# Pin 0 will close and pin 3 will open. In 1.5s pin 0 will open and pin
|
88
|
+
# 3 will close again.
|
89
|
+
#
|
90
|
+
# A monoflop can be used as a fail-safe mechanism. For example: Lets assume you
|
91
|
+
# have a RS485 bus and a Quad Relay Bricklet connected to one of the slave
|
92
|
+
# stacks. You can now call this function every second, with a time parameter
|
93
|
+
# of two seconds and pin 0 closed. Pin 0 will be closed all the time. If now
|
94
|
+
# the RS485 connection is lost, then pin 0 will be opened in at most two seconds.
|
95
|
+
def set_monoflop(selection_mask, value_mask, time)
|
96
|
+
send_request(FUNCTION_SET_MONOFLOP, [selection_mask, value_mask, time], 'S S L', 0, '')
|
97
|
+
end
|
98
|
+
|
99
|
+
# Returns (for the given pin) the current value and the time as set by
|
100
|
+
# BrickletIndustrialQuadRelay#set_monoflop as well as the remaining time until the value flips.
|
101
|
+
#
|
102
|
+
# If the timer is not running currently, the remaining time will be returned
|
103
|
+
# as 0.
|
104
|
+
def get_monoflop(pin)
|
105
|
+
send_request(FUNCTION_GET_MONOFLOP, [pin], 'C', 10, 'S L L')
|
106
|
+
end
|
107
|
+
|
108
|
+
# Sets a group of Quad Relay Bricklets that should work together. You can
|
109
|
+
# find Bricklets that can be grouped together with BrickletIndustrialQuadRelay#get_available_for_group.
|
110
|
+
#
|
111
|
+
# The group consists of 4 elements. Element 1 in the group will get pins 0-3,
|
112
|
+
# element 2 pins 4-7, element 3 pins 8-11 and element 4 pins 12-15.
|
113
|
+
#
|
114
|
+
# Each element can either be one of the ports ('a' to 'd') or 'n' if it should
|
115
|
+
# not be used.
|
116
|
+
#
|
117
|
+
# For example: If you have two Quad Relay Bricklets connected to port A and
|
118
|
+
# port B respectively, you could call with "['a', 'b', 'n', 'n']".
|
119
|
+
#
|
120
|
+
# Now the pins on the Quad Relay on port A are assigned to 0-3 and the
|
121
|
+
# pins on the Quad Relay on port B are assigned to 4-7. It is now possible
|
122
|
+
# to call BrickletIndustrialQuadRelay#set_value and control two Bricklets at the same time.
|
123
|
+
def set_group(group)
|
124
|
+
send_request(FUNCTION_SET_GROUP, [group], 'k4', 0, '')
|
125
|
+
end
|
126
|
+
|
127
|
+
# Returns the group as set by BrickletIndustrialQuadRelay#set_group
|
128
|
+
def get_group
|
129
|
+
send_request(FUNCTION_GET_GROUP, [], '', 4, 'k4')
|
130
|
+
end
|
131
|
+
|
132
|
+
# Returns a bitmask of ports that are available for grouping. For example the
|
133
|
+
# value 0b0101 means: Port *A* and Port *C* are connected to Bricklets that
|
134
|
+
# can be grouped together.
|
135
|
+
def get_available_for_group
|
136
|
+
send_request(FUNCTION_GET_AVAILABLE_FOR_GROUP, [], '', 1, 'C')
|
137
|
+
end
|
138
|
+
|
139
|
+
# Sets the output value with a bitmask, according to the selection mask.
|
140
|
+
# The bitmask is 16 bit long, *true* refers to a closed relay and
|
141
|
+
# *false* refers to an open relay.
|
142
|
+
#
|
143
|
+
# For example: The values 00b0000000000000011, b0000000000000001 will close
|
144
|
+
# the relay of pin 0, open the relay of pin 1 and leave the others untouched.
|
145
|
+
#
|
146
|
+
# If no groups are used (see BrickletIndustrialQuadRelay#set_group), the pins correspond to the
|
147
|
+
# markings on the Quad Relay Bricklet.
|
148
|
+
#
|
149
|
+
# If groups are used, the pins correspond to the element in the group.
|
150
|
+
# Element 1 in the group will get pins 0-3, element 2 pins 4-7, element 3
|
151
|
+
# pins 8-11 and element 4 pins 12-15.
|
152
|
+
#
|
153
|
+
# .. versionadded:: 2.0.0~(Plugin)
|
154
|
+
def set_selected_values(selection_mask, value_mask)
|
155
|
+
send_request(FUNCTION_SET_SELECTED_VALUES, [selection_mask, value_mask], 'S S', 0, '')
|
156
|
+
end
|
157
|
+
|
158
|
+
# Returns the UID, the UID where the Bricklet is connected to,
|
159
|
+
# the position, the hardware and firmware version as well as the
|
160
|
+
# device identifier.
|
161
|
+
#
|
162
|
+
# The position can be 'a', 'b', 'c' or 'd'.
|
163
|
+
#
|
164
|
+
# The device identifiers can be found :ref:`here <device_identifier>`.
|
165
|
+
#
|
166
|
+
# .. versionadded:: 2.0.0~(Plugin)
|
167
|
+
def get_identity
|
168
|
+
send_request(FUNCTION_GET_IDENTITY, [], '', 25, 'Z8 Z8 k C3 C3 S')
|
169
|
+
end
|
170
|
+
|
171
|
+
# Registers a callback with ID <tt>id</tt> to the block <tt>block</tt>.
|
172
|
+
def register_callback(id, &block)
|
173
|
+
callback = block
|
174
|
+
@registered_callbacks[id] = callback
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|