tinkerforge 2.1.24 → 2.1.25
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/tinkerforge/brick_dc.rb +155 -74
- data/lib/tinkerforge/brick_hat.rb +70 -30
- data/lib/tinkerforge/brick_hat_zero.rb +56 -22
- data/lib/tinkerforge/brick_imu.rb +184 -77
- data/lib/tinkerforge/brick_imu_v2.rb +208 -105
- data/lib/tinkerforge/brick_master.rb +484 -182
- data/lib/tinkerforge/brick_red.rb +197 -74
- data/lib/tinkerforge/brick_servo.rb +185 -101
- data/lib/tinkerforge/brick_silent_stepper.rb +246 -166
- data/lib/tinkerforge/brick_stepper.rb +210 -98
- data/lib/tinkerforge/bricklet_accelerometer.rb +58 -23
- data/lib/tinkerforge/bricklet_accelerometer_v2.rb +105 -54
- data/lib/tinkerforge/bricklet_air_quality.rb +117 -59
- data/lib/tinkerforge/bricklet_ambient_light.rb +51 -21
- data/lib/tinkerforge/bricklet_ambient_light_v2.rb +40 -22
- data/lib/tinkerforge/bricklet_ambient_light_v3.rb +61 -25
- data/lib/tinkerforge/bricklet_analog_in.rb +63 -25
- data/lib/tinkerforge/bricklet_analog_in_v2.rb +57 -23
- data/lib/tinkerforge/bricklet_analog_in_v3.rb +67 -25
- data/lib/tinkerforge/bricklet_analog_out.rb +23 -9
- data/lib/tinkerforge/bricklet_analog_out_v2.rb +20 -8
- data/lib/tinkerforge/bricklet_analog_out_v3.rb +54 -20
- data/lib/tinkerforge/bricklet_barometer.rb +66 -26
- data/lib/tinkerforge/bricklet_barometer_v2.rb +99 -37
- data/lib/tinkerforge/bricklet_can.rb +83 -18
- data/lib/tinkerforge/bricklet_can_v2.rb +172 -38
- data/lib/tinkerforge/bricklet_co2.rb +34 -14
- data/lib/tinkerforge/bricklet_co2_v2.rb +97 -37
- data/lib/tinkerforge/bricklet_color.rb +69 -27
- data/lib/tinkerforge/bricklet_color_v2.rb +87 -33
- data/lib/tinkerforge/bricklet_compass.rb +78 -30
- data/lib/tinkerforge/bricklet_current12.rb +58 -24
- data/lib/tinkerforge/bricklet_current25.rb +58 -24
- data/lib/tinkerforge/bricklet_distance_ir.rb +57 -23
- data/lib/tinkerforge/bricklet_distance_ir_v2.rb +83 -31
- data/lib/tinkerforge/bricklet_distance_us.rb +40 -16
- data/lib/tinkerforge/bricklet_distance_us_v2.rb +67 -25
- data/lib/tinkerforge/bricklet_dmx.rb +88 -34
- data/lib/tinkerforge/bricklet_dual_button.rb +24 -10
- data/lib/tinkerforge/bricklet_dual_button_v2.rb +64 -24
- data/lib/tinkerforge/bricklet_dual_relay.rb +27 -11
- data/lib/tinkerforge/bricklet_dust_detector.rb +40 -16
- data/lib/tinkerforge/bricklet_e_paper_296x128.rb +88 -32
- data/lib/tinkerforge/bricklet_energy_monitor.rb +73 -27
- data/lib/tinkerforge/bricklet_gps.rb +64 -26
- data/lib/tinkerforge/bricklet_gps_v2.rb +117 -47
- data/lib/tinkerforge/bricklet_hall_effect.rb +43 -23
- data/lib/tinkerforge/bricklet_hall_effect_v2.rb +71 -27
- data/lib/tinkerforge/bricklet_humidity.rb +51 -21
- data/lib/tinkerforge/bricklet_humidity_v2.rb +83 -31
- data/lib/tinkerforge/bricklet_industrial_analog_out.rb +38 -14
- data/lib/tinkerforge/bricklet_industrial_analog_out_v2.rb +81 -29
- data/lib/tinkerforge/bricklet_industrial_counter.rb +101 -39
- data/lib/tinkerforge/bricklet_industrial_digital_in_4.rb +45 -17
- data/lib/tinkerforge/bricklet_industrial_digital_in_4_v2.rb +77 -29
- data/lib/tinkerforge/bricklet_industrial_digital_out_4.rb +36 -14
- data/lib/tinkerforge/bricklet_industrial_digital_out_4_v2.rb +73 -27
- data/lib/tinkerforge/bricklet_industrial_dual_0_20ma.rb +40 -16
- data/lib/tinkerforge/bricklet_industrial_dual_0_20ma_v2.rb +79 -29
- data/lib/tinkerforge/bricklet_industrial_dual_analog_in.rb +49 -19
- data/lib/tinkerforge/bricklet_industrial_dual_analog_in_v2.rb +82 -30
- data/lib/tinkerforge/bricklet_industrial_dual_relay.rb +61 -23
- data/lib/tinkerforge/bricklet_industrial_quad_relay.rb +36 -14
- data/lib/tinkerforge/bricklet_industrial_quad_relay_v2.rb +67 -25
- data/lib/tinkerforge/bricklet_io16.rb +55 -21
- data/lib/tinkerforge/bricklet_io16_v2.rb +90 -34
- data/lib/tinkerforge/bricklet_io4.rb +55 -23
- data/lib/tinkerforge/bricklet_io4_v2.rb +96 -36
- data/lib/tinkerforge/bricklet_isolator.rb +72 -28
- data/lib/tinkerforge/bricklet_joystick.rb +59 -25
- data/lib/tinkerforge/bricklet_joystick_v2.rb +68 -26
- data/lib/tinkerforge/bricklet_laser_range_finder.rb +82 -32
- data/lib/tinkerforge/bricklet_laser_range_finder_v2.rb +96 -36
- data/lib/tinkerforge/bricklet_lcd_128x64.rb +192 -70
- data/lib/tinkerforge/bricklet_lcd_16x2.rb +45 -18
- data/lib/tinkerforge/bricklet_lcd_20x4.rb +58 -23
- data/lib/tinkerforge/bricklet_led_strip.rb +60 -22
- data/lib/tinkerforge/bricklet_led_strip_v2.rb +91 -46
- data/lib/tinkerforge/bricklet_line.rb +34 -14
- data/lib/tinkerforge/bricklet_linear_poti.rb +51 -21
- data/lib/tinkerforge/bricklet_linear_poti_v2.rb +55 -21
- data/lib/tinkerforge/bricklet_load_cell.rb +61 -23
- data/lib/tinkerforge/bricklet_load_cell_v2.rb +80 -30
- data/lib/tinkerforge/bricklet_moisture.rb +40 -16
- data/lib/tinkerforge/bricklet_motion_detector.rb +22 -10
- data/lib/tinkerforge/bricklet_motion_detector_v2.rb +62 -24
- data/lib/tinkerforge/bricklet_motorized_linear_poti.rb +71 -27
- data/lib/tinkerforge/bricklet_multi_touch.rb +31 -13
- data/lib/tinkerforge/bricklet_multi_touch_v2.rb +76 -28
- data/lib/tinkerforge/bricklet_nfc.rb +123 -58
- data/lib/tinkerforge/bricklet_nfc_rfid.rb +33 -13
- data/lib/tinkerforge/bricklet_oled_128x64.rb +29 -11
- data/lib/tinkerforge/bricklet_oled_128x64_v2.rb +66 -24
- data/lib/tinkerforge/bricklet_oled_64x48.rb +29 -11
- data/lib/tinkerforge/bricklet_one_wire.rb +66 -24
- data/lib/tinkerforge/bricklet_outdoor_weather.rb +71 -27
- data/lib/tinkerforge/bricklet_particulate_matter.rb +75 -30
- data/lib/tinkerforge/bricklet_piezo_buzzer.rb +19 -9
- data/lib/tinkerforge/bricklet_piezo_speaker.rb +22 -10
- data/lib/tinkerforge/bricklet_piezo_speaker_v2.rb +80 -42
- data/lib/tinkerforge/bricklet_ptc.rb +74 -42
- data/lib/tinkerforge/bricklet_ptc_v2.rb +95 -48
- data/lib/tinkerforge/bricklet_real_time_clock.rb +45 -33
- data/lib/tinkerforge/bricklet_real_time_clock_v2.rb +78 -44
- data/lib/tinkerforge/bricklet_remote_switch.rb +39 -29
- data/lib/tinkerforge/bricklet_remote_switch_v2.rb +87 -49
- data/lib/tinkerforge/bricklet_rgb_led.rb +18 -8
- data/lib/tinkerforge/bricklet_rgb_led_button.rb +62 -30
- data/lib/tinkerforge/bricklet_rgb_led_matrix.rb +79 -33
- data/lib/tinkerforge/bricklet_rgb_led_v2.rb +52 -20
- data/lib/tinkerforge/bricklet_rotary_encoder.rb +39 -19
- data/lib/tinkerforge/bricklet_rotary_encoder_v2.rb +60 -24
- data/lib/tinkerforge/bricklet_rotary_poti.rb +53 -28
- data/lib/tinkerforge/bricklet_rotary_poti_v2.rb +57 -23
- data/lib/tinkerforge/bricklet_rs232.rb +90 -28
- data/lib/tinkerforge/bricklet_rs232_v2.rb +118 -44
- data/lib/tinkerforge/bricklet_rs485.rb +223 -95
- data/lib/tinkerforge/bricklet_segment_display_4x7.rb +25 -14
- data/lib/tinkerforge/bricklet_segment_display_4x7_v2.rb +75 -35
- data/lib/tinkerforge/bricklet_solid_state_relay.rb +25 -13
- data/lib/tinkerforge/bricklet_solid_state_relay_v2.rb +59 -25
- data/lib/tinkerforge/bricklet_sound_intensity.rb +35 -18
- data/lib/tinkerforge/bricklet_sound_pressure_level.rb +72 -31
- data/lib/tinkerforge/bricklet_temperature.rb +40 -16
- data/lib/tinkerforge/bricklet_temperature_ir.rb +57 -23
- data/lib/tinkerforge/bricklet_temperature_ir_v2.rb +71 -27
- data/lib/tinkerforge/bricklet_temperature_v2.rb +61 -25
- data/lib/tinkerforge/bricklet_thermal_imaging.rb +105 -44
- data/lib/tinkerforge/bricklet_thermocouple.rb +45 -24
- data/lib/tinkerforge/bricklet_thermocouple_v2.rb +65 -27
- data/lib/tinkerforge/bricklet_tilt.rb +24 -10
- data/lib/tinkerforge/bricklet_uv_light.rb +36 -18
- data/lib/tinkerforge/bricklet_uv_light_v2.rb +85 -37
- data/lib/tinkerforge/bricklet_voltage.rb +52 -28
- data/lib/tinkerforge/bricklet_voltage_current.rb +91 -73
- data/lib/tinkerforge/bricklet_voltage_current_v2.rb +90 -68
- data/lib/tinkerforge/bricklet_xmc1400_breakout.rb +80 -30
- data/lib/tinkerforge/device_display_names.rb +163 -0
- data/lib/tinkerforge/ip_connection.rb +151 -32
- data/lib/tinkerforge/version.rb +1 -1
- metadata +3 -2
@@ -1,14 +1,16 @@
|
|
1
1
|
# -*- ruby encoding: utf-8 -*-
|
2
2
|
#############################################################
|
3
|
-
# This file was automatically generated on
|
3
|
+
# This file was automatically generated on 2020-04-07. #
|
4
4
|
# #
|
5
|
-
# Ruby Bindings Version 2.1.
|
5
|
+
# Ruby Bindings Version 2.1.25 #
|
6
6
|
# #
|
7
7
|
# If you have a bugfix for this file and want to commit it, #
|
8
8
|
# please fix the bug in the generator. You can find a link #
|
9
9
|
# to the generators git repository on tinkerforge.com #
|
10
10
|
#############################################################
|
11
11
|
|
12
|
+
require_relative './ip_connection'
|
13
|
+
|
12
14
|
module Tinkerforge
|
13
15
|
# Communicates with RS232 devices
|
14
16
|
class BrickletRS232 < Device
|
@@ -28,6 +30,14 @@ module Tinkerforge
|
|
28
30
|
# .. versionadded:: 2.0.1$nbsp;(Plugin)
|
29
31
|
CALLBACK_ERROR = 9
|
30
32
|
|
33
|
+
# This callback is called if at least one frame of data is readable. The frame size is configured with BrickletRS232#set_frame_readable_callback_configuration.
|
34
|
+
# The frame count parameter is the number of frames that can be read.
|
35
|
+
# This callback is triggered only once until BrickletRS232#read or BrickletRS232#read_frame is called. This means, that if you have configured a frame size of X bytes,
|
36
|
+
# you can read exactly X bytes using the BrickletRS232#read_frame function, every time the callback triggers without checking the frame count parameter.
|
37
|
+
#
|
38
|
+
# .. versionadded:: 2.0.4$nbsp;(Plugin)
|
39
|
+
CALLBACK_FRAME_READABLE = 13
|
40
|
+
|
31
41
|
CALLBACK_READ_CALLBACK = 8 # :nodoc: for backward compatibility
|
32
42
|
CALLBACK_ERROR_CALLBACK = 9 # :nodoc: for backward compatibility
|
33
43
|
|
@@ -39,6 +49,9 @@ module Tinkerforge
|
|
39
49
|
FUNCTION_SET_CONFIGURATION = 6 # :nodoc:
|
40
50
|
FUNCTION_GET_CONFIGURATION = 7 # :nodoc:
|
41
51
|
FUNCTION_SET_BREAK_CONDITION = 10 # :nodoc:
|
52
|
+
FUNCTION_SET_FRAME_READABLE_CALLBACK_CONFIGURATION = 11 # :nodoc:
|
53
|
+
FUNCTION_GET_FRAME_READABLE_CALLBACK_CONFIGURATION = 12 # :nodoc:
|
54
|
+
FUNCTION_READ_FRAME = 14 # :nodoc:
|
42
55
|
FUNCTION_GET_IDENTITY = 255 # :nodoc:
|
43
56
|
|
44
57
|
BAUDRATE_300 = 0 # :nodoc:
|
@@ -76,9 +89,9 @@ module Tinkerforge
|
|
76
89
|
# Creates an object with the unique device ID <tt>uid</tt> and adds it to
|
77
90
|
# the IP Connection <tt>ipcon</tt>.
|
78
91
|
def initialize(uid, ipcon)
|
79
|
-
super uid, ipcon
|
92
|
+
super uid, ipcon, DEVICE_IDENTIFIER, DEVICE_DISPLAY_NAME
|
80
93
|
|
81
|
-
@api_version = [2, 0,
|
94
|
+
@api_version = [2, 0, 3]
|
82
95
|
|
83
96
|
@response_expected[FUNCTION_WRITE] = RESPONSE_EXPECTED_ALWAYS_TRUE
|
84
97
|
@response_expected[FUNCTION_READ] = RESPONSE_EXPECTED_ALWAYS_TRUE
|
@@ -88,11 +101,16 @@ module Tinkerforge
|
|
88
101
|
@response_expected[FUNCTION_SET_CONFIGURATION] = RESPONSE_EXPECTED_FALSE
|
89
102
|
@response_expected[FUNCTION_GET_CONFIGURATION] = RESPONSE_EXPECTED_ALWAYS_TRUE
|
90
103
|
@response_expected[FUNCTION_SET_BREAK_CONDITION] = RESPONSE_EXPECTED_FALSE
|
104
|
+
@response_expected[FUNCTION_SET_FRAME_READABLE_CALLBACK_CONFIGURATION] = RESPONSE_EXPECTED_TRUE
|
105
|
+
@response_expected[FUNCTION_GET_FRAME_READABLE_CALLBACK_CONFIGURATION] = RESPONSE_EXPECTED_ALWAYS_TRUE
|
106
|
+
@response_expected[FUNCTION_READ_FRAME] = RESPONSE_EXPECTED_ALWAYS_TRUE
|
91
107
|
@response_expected[FUNCTION_GET_IDENTITY] = RESPONSE_EXPECTED_ALWAYS_TRUE
|
92
108
|
|
93
|
-
@callback_formats[CALLBACK_READ] = 'k60 C'
|
94
|
-
@callback_formats[CALLBACK_ERROR] = 'C'
|
109
|
+
@callback_formats[CALLBACK_READ] = [69, 'k60 C']
|
110
|
+
@callback_formats[CALLBACK_ERROR] = [9, 'C']
|
111
|
+
@callback_formats[CALLBACK_FRAME_READABLE] = [9, 'C']
|
95
112
|
|
113
|
+
@ipcon.add_device self
|
96
114
|
end
|
97
115
|
|
98
116
|
# Writes a string of up to 60 characters to the RS232 interface. The string
|
@@ -105,75 +123,119 @@ module Tinkerforge
|
|
105
123
|
# See BrickletRS232#set_configuration for configuration possibilities
|
106
124
|
# regarding baudrate, parity and so on.
|
107
125
|
def write(message, length)
|
108
|
-
|
126
|
+
check_validity
|
127
|
+
|
128
|
+
send_request FUNCTION_WRITE, [message, length], 'k60 C', 9, 'C'
|
109
129
|
end
|
110
130
|
|
111
131
|
# Returns the currently buffered message. The maximum length
|
112
|
-
# of message is 60. If the length is
|
113
|
-
# new data available.
|
132
|
+
# of message is 60. If the returned length is 0, no new data was available.
|
114
133
|
#
|
115
134
|
# Instead of polling with this function, you can also use
|
116
135
|
# callbacks. See BrickletRS232#enable_read_callback and CALLBACK_READ callback.
|
117
136
|
def read
|
118
|
-
|
137
|
+
check_validity
|
138
|
+
|
139
|
+
send_request FUNCTION_READ, [], '', 69, 'k60 C'
|
119
140
|
end
|
120
141
|
|
121
|
-
# Enables the CALLBACK_READ callback.
|
142
|
+
# Enables the CALLBACK_READ callback. This will disable the CALLBACK_FRAME_READABLE callback.
|
122
143
|
#
|
123
144
|
# By default the callback is disabled.
|
124
145
|
def enable_read_callback
|
125
|
-
|
146
|
+
check_validity
|
147
|
+
|
148
|
+
send_request FUNCTION_ENABLE_READ_CALLBACK, [], '', 8, ''
|
126
149
|
end
|
127
150
|
|
128
151
|
# Disables the CALLBACK_READ callback.
|
129
152
|
#
|
130
153
|
# By default the callback is disabled.
|
131
154
|
def disable_read_callback
|
132
|
-
|
155
|
+
check_validity
|
156
|
+
|
157
|
+
send_request FUNCTION_DISABLE_READ_CALLBACK, [], '', 8, ''
|
133
158
|
end
|
134
159
|
|
135
160
|
# Returns *true* if the CALLBACK_READ callback is enabled,
|
136
161
|
# *false* otherwise.
|
137
162
|
def is_read_callback_enabled
|
138
|
-
|
163
|
+
check_validity
|
164
|
+
|
165
|
+
send_request FUNCTION_IS_READ_CALLBACK_ENABLED, [], '', 9, '?'
|
139
166
|
end
|
140
167
|
|
141
|
-
# Sets the configuration for the RS232 communication.
|
142
|
-
#
|
143
|
-
# * Baudrate between 300 and 230400 baud.
|
144
|
-
# * Parity of none, odd, even or forced parity.
|
145
|
-
# * Stopbits can be 1 or 2.
|
146
|
-
# * Word length of 5 to 8.
|
147
|
-
# * Hard-/Software flow control can either be on or off but not both simultaneously on.
|
168
|
+
# Sets the configuration for the RS232 communication.
|
148
169
|
#
|
149
|
-
#
|
170
|
+
# Hard-/Software flow control can either be on or off but not both simultaneously on.
|
150
171
|
def set_configuration(baudrate, parity, stopbits, wordlength, hardware_flowcontrol, software_flowcontrol)
|
151
|
-
|
172
|
+
check_validity
|
173
|
+
|
174
|
+
send_request FUNCTION_SET_CONFIGURATION, [baudrate, parity, stopbits, wordlength, hardware_flowcontrol, software_flowcontrol], 'C C C C C C', 8, ''
|
152
175
|
end
|
153
176
|
|
154
177
|
# Returns the configuration as set by BrickletRS232#set_configuration.
|
155
178
|
def get_configuration
|
156
|
-
|
179
|
+
check_validity
|
180
|
+
|
181
|
+
send_request FUNCTION_GET_CONFIGURATION, [], '', 14, 'C C C C C C'
|
157
182
|
end
|
158
183
|
|
159
184
|
# Sets a break condition (the TX output is forced to a logic 0 state).
|
160
|
-
# The parameter sets the hold-time of the break condition
|
185
|
+
# The parameter sets the hold-time of the break condition.
|
161
186
|
#
|
162
187
|
# .. versionadded:: 2.0.2$nbsp;(Plugin)
|
163
188
|
def set_break_condition(break_time)
|
164
|
-
|
189
|
+
check_validity
|
190
|
+
|
191
|
+
send_request FUNCTION_SET_BREAK_CONDITION, [break_time], 'S', 8, ''
|
192
|
+
end
|
193
|
+
|
194
|
+
# Configures the CALLBACK_FRAME_READABLE callback. The frame size is the number of bytes, that have to be readable to trigger the callback.
|
195
|
+
# A frame size of 0 disables the callback. A frame size greater than 0 enables the callback and disables the CALLBACK_READ callback.
|
196
|
+
#
|
197
|
+
# By default the callback is disabled.
|
198
|
+
#
|
199
|
+
# .. versionadded:: 2.0.4$nbsp;(Plugin)
|
200
|
+
def set_frame_readable_callback_configuration(frame_size)
|
201
|
+
check_validity
|
202
|
+
|
203
|
+
send_request FUNCTION_SET_FRAME_READABLE_CALLBACK_CONFIGURATION, [frame_size], 'C', 8, ''
|
204
|
+
end
|
205
|
+
|
206
|
+
# Returns the callback configuration as set by BrickletRS232#set_frame_readable_callback_configuration.
|
207
|
+
#
|
208
|
+
# .. versionadded:: 2.0.4$nbsp;(Plugin)
|
209
|
+
def get_frame_readable_callback_configuration
|
210
|
+
check_validity
|
211
|
+
|
212
|
+
send_request FUNCTION_GET_FRAME_READABLE_CALLBACK_CONFIGURATION, [], '', 9, 'C'
|
213
|
+
end
|
214
|
+
|
215
|
+
# Returns up to one frame of bytes from the read buffer.
|
216
|
+
# The frame size is configured with BrickletRS232#set_frame_readable_callback_configuration.
|
217
|
+
# If the returned length is 0, no new data was available.
|
218
|
+
#
|
219
|
+
# .. versionadded:: 2.0.4$nbsp;(Plugin)
|
220
|
+
def read_frame
|
221
|
+
check_validity
|
222
|
+
|
223
|
+
send_request FUNCTION_READ_FRAME, [], '', 69, 'k60 C'
|
165
224
|
end
|
166
225
|
|
167
226
|
# Returns the UID, the UID where the Bricklet is connected to,
|
168
227
|
# the position, the hardware and firmware version as well as the
|
169
228
|
# device identifier.
|
170
229
|
#
|
171
|
-
# The position can be 'a', 'b', 'c' or '
|
230
|
+
# The position can be 'a', 'b', 'c', 'd', 'e', 'f', 'g' or 'h' (Bricklet Port).
|
231
|
+
# The Raspberry Pi HAT (Zero) Brick is always at position 'i' and the Bricklet
|
232
|
+
# connected to an :ref:`Isolator Bricklet <isolator_bricklet>` is always as
|
233
|
+
# position 'z'.
|
172
234
|
#
|
173
235
|
# The device identifier numbers can be found :ref:`here <device_identifier>`.
|
174
236
|
# |device_identifier_constant|
|
175
237
|
def get_identity
|
176
|
-
send_request FUNCTION_GET_IDENTITY, [], '',
|
238
|
+
send_request FUNCTION_GET_IDENTITY, [], '', 33, 'Z8 Z8 k C3 C3 S'
|
177
239
|
end
|
178
240
|
|
179
241
|
# Registers a callback with ID <tt>id</tt> to the block <tt>block</tt>.
|
@@ -1,14 +1,16 @@
|
|
1
1
|
# -*- ruby encoding: utf-8 -*-
|
2
2
|
#############################################################
|
3
|
-
# This file was automatically generated on
|
3
|
+
# This file was automatically generated on 2020-04-07. #
|
4
4
|
# #
|
5
|
-
# Ruby Bindings Version 2.1.
|
5
|
+
# Ruby Bindings Version 2.1.25 #
|
6
6
|
# #
|
7
7
|
# If you have a bugfix for this file and want to commit it, #
|
8
8
|
# please fix the bug in the generator. You can find a link #
|
9
9
|
# to the generators git repository on tinkerforge.com #
|
10
10
|
#############################################################
|
11
11
|
|
12
|
+
require_relative './ip_connection'
|
13
|
+
|
12
14
|
module Tinkerforge
|
13
15
|
# Communicates with RS232 devices
|
14
16
|
class BrickletRS232V2 < Device
|
@@ -22,6 +24,14 @@ module Tinkerforge
|
|
22
24
|
# the current overrun and parity error count.
|
23
25
|
CALLBACK_ERROR_COUNT = 13
|
24
26
|
|
27
|
+
# This callback is called if at least one frame of data is readable. The frame size is configured with BrickletRS232V2#set_frame_readable_callback_configuration.
|
28
|
+
# The frame count parameter is the number of frames that can be read.
|
29
|
+
# This callback is triggered only once until BrickletRS232V2#read is called. This means, that if you have configured a frame size of X bytes,
|
30
|
+
# you can read exactly X bytes using the BrickletRS232V2#read function, every time the callback triggers without checking the frame count parameter.
|
31
|
+
#
|
32
|
+
# .. versionadded:: 2.0.3$nbsp;(Plugin)
|
33
|
+
CALLBACK_FRAME_READABLE = 16
|
34
|
+
|
25
35
|
# This callback is called if new data is available.
|
26
36
|
#
|
27
37
|
# To enable this callback, use BrickletRS232V2#enable_read_callback.
|
@@ -41,6 +51,8 @@ module Tinkerforge
|
|
41
51
|
FUNCTION_GET_BUFFER_CONFIG = 9 # :nodoc:
|
42
52
|
FUNCTION_GET_BUFFER_STATUS = 10 # :nodoc:
|
43
53
|
FUNCTION_GET_ERROR_COUNT = 11 # :nodoc:
|
54
|
+
FUNCTION_SET_FRAME_READABLE_CALLBACK_CONFIGURATION = 14 # :nodoc:
|
55
|
+
FUNCTION_GET_FRAME_READABLE_CALLBACK_CONFIGURATION = 15 # :nodoc:
|
44
56
|
FUNCTION_GET_SPITFP_ERROR_COUNT = 234 # :nodoc:
|
45
57
|
FUNCTION_SET_BOOTLOADER_MODE = 235 # :nodoc:
|
46
58
|
FUNCTION_GET_BOOTLOADER_MODE = 236 # :nodoc:
|
@@ -85,9 +97,9 @@ module Tinkerforge
|
|
85
97
|
# Creates an object with the unique device ID <tt>uid</tt> and adds it to
|
86
98
|
# the IP Connection <tt>ipcon</tt>.
|
87
99
|
def initialize(uid, ipcon)
|
88
|
-
super uid, ipcon
|
100
|
+
super uid, ipcon, DEVICE_IDENTIFIER, DEVICE_DISPLAY_NAME
|
89
101
|
|
90
|
-
@api_version = [2, 0,
|
102
|
+
@api_version = [2, 0, 1]
|
91
103
|
|
92
104
|
@response_expected[FUNCTION_WRITE_LOW_LEVEL] = RESPONSE_EXPECTED_ALWAYS_TRUE
|
93
105
|
@response_expected[FUNCTION_READ_LOW_LEVEL] = RESPONSE_EXPECTED_ALWAYS_TRUE
|
@@ -100,6 +112,8 @@ module Tinkerforge
|
|
100
112
|
@response_expected[FUNCTION_GET_BUFFER_CONFIG] = RESPONSE_EXPECTED_ALWAYS_TRUE
|
101
113
|
@response_expected[FUNCTION_GET_BUFFER_STATUS] = RESPONSE_EXPECTED_ALWAYS_TRUE
|
102
114
|
@response_expected[FUNCTION_GET_ERROR_COUNT] = RESPONSE_EXPECTED_ALWAYS_TRUE
|
115
|
+
@response_expected[FUNCTION_SET_FRAME_READABLE_CALLBACK_CONFIGURATION] = RESPONSE_EXPECTED_TRUE
|
116
|
+
@response_expected[FUNCTION_GET_FRAME_READABLE_CALLBACK_CONFIGURATION] = RESPONSE_EXPECTED_ALWAYS_TRUE
|
103
117
|
@response_expected[FUNCTION_GET_SPITFP_ERROR_COUNT] = RESPONSE_EXPECTED_ALWAYS_TRUE
|
104
118
|
@response_expected[FUNCTION_SET_BOOTLOADER_MODE] = RESPONSE_EXPECTED_ALWAYS_TRUE
|
105
119
|
@response_expected[FUNCTION_GET_BOOTLOADER_MODE] = RESPONSE_EXPECTED_ALWAYS_TRUE
|
@@ -113,10 +127,12 @@ module Tinkerforge
|
|
113
127
|
@response_expected[FUNCTION_READ_UID] = RESPONSE_EXPECTED_ALWAYS_TRUE
|
114
128
|
@response_expected[FUNCTION_GET_IDENTITY] = RESPONSE_EXPECTED_ALWAYS_TRUE
|
115
129
|
|
116
|
-
@callback_formats[CALLBACK_READ_LOW_LEVEL] = 'S S k60'
|
117
|
-
@callback_formats[CALLBACK_ERROR_COUNT] = 'L L'
|
130
|
+
@callback_formats[CALLBACK_READ_LOW_LEVEL] = [72, 'S S k60']
|
131
|
+
@callback_formats[CALLBACK_ERROR_COUNT] = [16, 'L L']
|
132
|
+
@callback_formats[CALLBACK_FRAME_READABLE] = [10, 'S']
|
118
133
|
|
119
134
|
@high_level_callbacks[CALLBACK_READ] = [['stream_length', 'stream_chunk_offset', 'stream_chunk_data'], {'fixed_length' => nil, 'single_chunk' => false}, nil]
|
135
|
+
@ipcon.add_device self
|
120
136
|
end
|
121
137
|
|
122
138
|
# Writes characters to the RS232 interface. The characters can be binary data,
|
@@ -127,7 +143,9 @@ module Tinkerforge
|
|
127
143
|
# See BrickletRS232V2#set_configuration for configuration possibilities
|
128
144
|
# regarding baud rate, parity and so on.
|
129
145
|
def write_low_level(message_length, message_chunk_offset, message_chunk_data)
|
130
|
-
|
146
|
+
check_validity
|
147
|
+
|
148
|
+
send_request FUNCTION_WRITE_LOW_LEVEL, [message_length, message_chunk_offset, message_chunk_data], 'S S k60', 9, 'C'
|
131
149
|
end
|
132
150
|
|
133
151
|
# Returns up to *length* characters from receive buffer.
|
@@ -137,49 +155,53 @@ module Tinkerforge
|
|
137
155
|
# data only when the read callback is disabled.
|
138
156
|
# See BrickletRS232V2#enable_read_callback and CALLBACK_READ callback.
|
139
157
|
def read_low_level(length)
|
140
|
-
|
158
|
+
check_validity
|
159
|
+
|
160
|
+
send_request FUNCTION_READ_LOW_LEVEL, [length], 'S', 72, 'S S k60'
|
141
161
|
end
|
142
162
|
|
143
|
-
# Enables the CALLBACK_READ callback.
|
163
|
+
# Enables the CALLBACK_READ callback. This will disable the CALLBACK_FRAME_READABLE callback.
|
144
164
|
#
|
145
165
|
# By default the callback is disabled.
|
146
166
|
def enable_read_callback
|
147
|
-
|
167
|
+
check_validity
|
168
|
+
|
169
|
+
send_request FUNCTION_ENABLE_READ_CALLBACK, [], '', 8, ''
|
148
170
|
end
|
149
171
|
|
150
172
|
# Disables the CALLBACK_READ callback.
|
151
173
|
#
|
152
174
|
# By default the callback is disabled.
|
153
175
|
def disable_read_callback
|
154
|
-
|
176
|
+
check_validity
|
177
|
+
|
178
|
+
send_request FUNCTION_DISABLE_READ_CALLBACK, [], '', 8, ''
|
155
179
|
end
|
156
180
|
|
157
181
|
# Returns *true* if the CALLBACK_READ callback is enabled,
|
158
182
|
# *false* otherwise.
|
159
183
|
def is_read_callback_enabled
|
160
|
-
|
184
|
+
check_validity
|
185
|
+
|
186
|
+
send_request FUNCTION_IS_READ_CALLBACK_ENABLED, [], '', 9, '?'
|
161
187
|
end
|
162
188
|
|
163
|
-
# Sets the configuration for the RS232 communication.
|
164
|
-
#
|
165
|
-
# * Baud rate between 100 and 2000000 baud.
|
166
|
-
# * Parity of none, odd or even.
|
167
|
-
# * Stop bits can be 1 or 2.
|
168
|
-
# * Word length of 5 to 8.
|
169
|
-
# * Flow control can be off, software or hardware.
|
170
|
-
#
|
171
|
-
# The default is: 115200 baud, parity none, 1 stop bit, word length 8.
|
189
|
+
# Sets the configuration for the RS232 communication.
|
172
190
|
def set_configuration(baudrate, parity, stopbits, wordlength, flowcontrol)
|
173
|
-
|
191
|
+
check_validity
|
192
|
+
|
193
|
+
send_request FUNCTION_SET_CONFIGURATION, [baudrate, parity, stopbits, wordlength, flowcontrol], 'L C C C C', 8, ''
|
174
194
|
end
|
175
195
|
|
176
196
|
# Returns the configuration as set by BrickletRS232V2#set_configuration.
|
177
197
|
def get_configuration
|
178
|
-
|
198
|
+
check_validity
|
199
|
+
|
200
|
+
send_request FUNCTION_GET_CONFIGURATION, [], '', 16, 'L C C C C'
|
179
201
|
end
|
180
202
|
|
181
203
|
# Sets the send and receive buffer size in byte. In total the buffers have to be
|
182
|
-
# 10240 byte (
|
204
|
+
# 10240 byte (10KiB) in size, the minimum buffer size is 1024 byte (1KiB) for each.
|
183
205
|
#
|
184
206
|
# The current buffer content is lost if this function is called.
|
185
207
|
#
|
@@ -187,27 +209,54 @@ module Tinkerforge
|
|
187
209
|
# can not be written yet. The receive buffer holds data that is
|
188
210
|
# received through RS232 but could not yet be send to the
|
189
211
|
# user, either by BrickletRS232V2#read or through CALLBACK_READ callback.
|
190
|
-
#
|
191
|
-
# The default configuration is 5120 byte (5kb) per buffer.
|
192
212
|
def set_buffer_config(send_buffer_size, receive_buffer_size)
|
193
|
-
|
213
|
+
check_validity
|
214
|
+
|
215
|
+
send_request FUNCTION_SET_BUFFER_CONFIG, [send_buffer_size, receive_buffer_size], 'S S', 8, ''
|
194
216
|
end
|
195
217
|
|
196
218
|
# Returns the buffer configuration as set by BrickletRS232V2#set_buffer_config.
|
197
219
|
def get_buffer_config
|
198
|
-
|
220
|
+
check_validity
|
221
|
+
|
222
|
+
send_request FUNCTION_GET_BUFFER_CONFIG, [], '', 12, 'S S'
|
199
223
|
end
|
200
224
|
|
201
225
|
# Returns the currently used bytes for the send and received buffer.
|
202
226
|
#
|
203
227
|
# See BrickletRS232V2#set_buffer_config for buffer size configuration.
|
204
228
|
def get_buffer_status
|
205
|
-
|
229
|
+
check_validity
|
230
|
+
|
231
|
+
send_request FUNCTION_GET_BUFFER_STATUS, [], '', 12, 'S S'
|
206
232
|
end
|
207
233
|
|
208
234
|
# Returns the current number of overrun and parity errors.
|
209
235
|
def get_error_count
|
210
|
-
|
236
|
+
check_validity
|
237
|
+
|
238
|
+
send_request FUNCTION_GET_ERROR_COUNT, [], '', 16, 'L L'
|
239
|
+
end
|
240
|
+
|
241
|
+
# Configures the CALLBACK_FRAME_READABLE callback. The frame size is the number of bytes, that have to be readable to trigger the callback.
|
242
|
+
# A frame size of 0 disables the callback. A frame size greater than 0 enables the callback and disables the CALLBACK_READ callback.
|
243
|
+
#
|
244
|
+
# By default the callback is disabled.
|
245
|
+
#
|
246
|
+
# .. versionadded:: 2.0.3$nbsp;(Plugin)
|
247
|
+
def set_frame_readable_callback_configuration(frame_size)
|
248
|
+
check_validity
|
249
|
+
|
250
|
+
send_request FUNCTION_SET_FRAME_READABLE_CALLBACK_CONFIGURATION, [frame_size], 'S', 8, ''
|
251
|
+
end
|
252
|
+
|
253
|
+
# Returns the callback configuration as set by BrickletRS232V2#set_frame_readable_callback_configuration.
|
254
|
+
#
|
255
|
+
# .. versionadded:: 2.0.3$nbsp;(Plugin)
|
256
|
+
def get_frame_readable_callback_configuration
|
257
|
+
check_validity
|
258
|
+
|
259
|
+
send_request FUNCTION_GET_FRAME_READABLE_CALLBACK_CONFIGURATION, [], '', 10, 'S'
|
211
260
|
end
|
212
261
|
|
213
262
|
# Returns the error count for the communication between Brick and Bricklet.
|
@@ -222,7 +271,9 @@ module Tinkerforge
|
|
222
271
|
# The errors counts are for errors that occur on the Bricklet side. All
|
223
272
|
# Bricks have a similar function that returns the errors on the Brick side.
|
224
273
|
def get_spitfp_error_count
|
225
|
-
|
274
|
+
check_validity
|
275
|
+
|
276
|
+
send_request FUNCTION_GET_SPITFP_ERROR_COUNT, [], '', 24, 'L L L L'
|
226
277
|
end
|
227
278
|
|
228
279
|
# Sets the bootloader mode and returns the status after the requested
|
@@ -235,12 +286,16 @@ module Tinkerforge
|
|
235
286
|
# This function is used by Brick Viewer during flashing. It should not be
|
236
287
|
# necessary to call it in a normal user program.
|
237
288
|
def set_bootloader_mode(mode)
|
238
|
-
|
289
|
+
check_validity
|
290
|
+
|
291
|
+
send_request FUNCTION_SET_BOOTLOADER_MODE, [mode], 'C', 9, 'C'
|
239
292
|
end
|
240
293
|
|
241
294
|
# Returns the current bootloader mode, see BrickletRS232V2#set_bootloader_mode.
|
242
295
|
def get_bootloader_mode
|
243
|
-
|
296
|
+
check_validity
|
297
|
+
|
298
|
+
send_request FUNCTION_GET_BOOTLOADER_MODE, [], '', 9, 'C'
|
244
299
|
end
|
245
300
|
|
246
301
|
# Sets the firmware pointer for BrickletRS232V2#write_firmware. The pointer has
|
@@ -250,7 +305,9 @@ module Tinkerforge
|
|
250
305
|
# This function is used by Brick Viewer during flashing. It should not be
|
251
306
|
# necessary to call it in a normal user program.
|
252
307
|
def set_write_firmware_pointer(pointer)
|
253
|
-
|
308
|
+
check_validity
|
309
|
+
|
310
|
+
send_request FUNCTION_SET_WRITE_FIRMWARE_POINTER, [pointer], 'L', 8, ''
|
254
311
|
end
|
255
312
|
|
256
313
|
# Writes 64 Bytes of firmware at the position as written by
|
@@ -262,7 +319,9 @@ module Tinkerforge
|
|
262
319
|
# This function is used by Brick Viewer during flashing. It should not be
|
263
320
|
# necessary to call it in a normal user program.
|
264
321
|
def write_firmware(data)
|
265
|
-
|
322
|
+
check_validity
|
323
|
+
|
324
|
+
send_request FUNCTION_WRITE_FIRMWARE, [data], 'C64', 9, 'C'
|
266
325
|
end
|
267
326
|
|
268
327
|
# Sets the status LED configuration. By default the LED shows
|
@@ -273,22 +332,28 @@ module Tinkerforge
|
|
273
332
|
#
|
274
333
|
# If the Bricklet is in bootloader mode, the LED is will show heartbeat by default.
|
275
334
|
def set_status_led_config(config)
|
276
|
-
|
335
|
+
check_validity
|
336
|
+
|
337
|
+
send_request FUNCTION_SET_STATUS_LED_CONFIG, [config], 'C', 8, ''
|
277
338
|
end
|
278
339
|
|
279
340
|
# Returns the configuration as set by BrickletRS232V2#set_status_led_config
|
280
341
|
def get_status_led_config
|
281
|
-
|
342
|
+
check_validity
|
343
|
+
|
344
|
+
send_request FUNCTION_GET_STATUS_LED_CONFIG, [], '', 9, 'C'
|
282
345
|
end
|
283
346
|
|
284
|
-
# Returns the temperature
|
347
|
+
# Returns the temperature as measured inside the microcontroller. The
|
285
348
|
# value returned is not the ambient temperature!
|
286
349
|
#
|
287
350
|
# The temperature is only proportional to the real temperature and it has bad
|
288
351
|
# accuracy. Practically it is only useful as an indicator for
|
289
352
|
# temperature changes.
|
290
353
|
def get_chip_temperature
|
291
|
-
|
354
|
+
check_validity
|
355
|
+
|
356
|
+
send_request FUNCTION_GET_CHIP_TEMPERATURE, [], '', 10, 's'
|
292
357
|
end
|
293
358
|
|
294
359
|
# Calling this function will reset the Bricklet. All configurations
|
@@ -298,7 +363,9 @@ module Tinkerforge
|
|
298
363
|
# calling functions on the existing ones will result in
|
299
364
|
# undefined behavior!
|
300
365
|
def reset
|
301
|
-
|
366
|
+
check_validity
|
367
|
+
|
368
|
+
send_request FUNCTION_RESET, [], '', 8, ''
|
302
369
|
end
|
303
370
|
|
304
371
|
# Writes a new UID into flash. If you want to set a new UID
|
@@ -307,25 +374,32 @@ module Tinkerforge
|
|
307
374
|
#
|
308
375
|
# We recommend that you use Brick Viewer to change the UID.
|
309
376
|
def write_uid(uid)
|
310
|
-
|
377
|
+
check_validity
|
378
|
+
|
379
|
+
send_request FUNCTION_WRITE_UID, [uid], 'L', 8, ''
|
311
380
|
end
|
312
381
|
|
313
382
|
# Returns the current UID as an integer. Encode as
|
314
383
|
# Base58 to get the usual string version.
|
315
384
|
def read_uid
|
316
|
-
|
385
|
+
check_validity
|
386
|
+
|
387
|
+
send_request FUNCTION_READ_UID, [], '', 12, 'L'
|
317
388
|
end
|
318
389
|
|
319
390
|
# Returns the UID, the UID where the Bricklet is connected to,
|
320
391
|
# the position, the hardware and firmware version as well as the
|
321
392
|
# device identifier.
|
322
393
|
#
|
323
|
-
# The position can be 'a', 'b', 'c' or '
|
394
|
+
# The position can be 'a', 'b', 'c', 'd', 'e', 'f', 'g' or 'h' (Bricklet Port).
|
395
|
+
# The Raspberry Pi HAT (Zero) Brick is always at position 'i' and the Bricklet
|
396
|
+
# connected to an :ref:`Isolator Bricklet <isolator_bricklet>` is always as
|
397
|
+
# position 'z'.
|
324
398
|
#
|
325
399
|
# The device identifier numbers can be found :ref:`here <device_identifier>`.
|
326
400
|
# |device_identifier_constant|
|
327
401
|
def get_identity
|
328
|
-
send_request FUNCTION_GET_IDENTITY, [], '',
|
402
|
+
send_request FUNCTION_GET_IDENTITY, [], '', 33, 'Z8 Z8 k C3 C3 S'
|
329
403
|
end
|
330
404
|
|
331
405
|
# Writes characters to the RS232 interface. The characters can be binary data,
|