From 5d0090c3b4a539af9e6d63751bfc9941c83f9a9c Mon Sep 17 00:00:00 2001 From: sasha80 Date: Fri, 1 Nov 2024 14:32:06 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=BA=D0=B0.=20=D0=9E=D1=82=D0=BE=D0=B1=D1=80=D0=B0=D0=B6?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D1=81=D0=BE=D1=81=D1=82=D0=BE=D1=8F?= =?UTF-8?q?=D0=BD=D0=B8=D1=8F=20=D0=A93=20(=D0=A9-3)=20=D0=B2=20=D1=80?= =?UTF-8?q?=D0=B5=D0=B6=D0=B8=D0=BC=D0=B5=20=D0=9A=D0=BE=D0=BD=D1=82=D1=80?= =?UTF-8?q?=D0=BE=D0=BB=D1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- project.godot | 1 - scenes/pribor-uyep/pribor-uyep.tscn | 2 +- scenes/pribor-uyep/sch3-view.gd | 21 ++++- scenes/pribor-uyep/sch3.tscn | 55 ++++++------ scripts/modbus.gd | 126 --------------------------- scripts/network.gd | 2 +- scripts/sch3.gd | 130 +++++++++++++++++++++++----- 7 files changed, 159 insertions(+), 178 deletions(-) delete mode 100644 scripts/modbus.gd diff --git a/project.godot b/project.godot index 843a9c78..2cf8809e 100644 --- a/project.godot +++ b/project.godot @@ -57,7 +57,6 @@ yemsconsts="*res://scripts/yems-consts.gd" interfer="*res://scripts/interfer.gd" hotkeys="*res://scripts/hotkeys.gd" mercator="*res://scripts/mercator.gd" -modbus="*res://scripts/modbus.gd" tcp5p28="*res://scripts/tcp5p28.gd" sch3="*res://scripts/sch3.gd" spt25="*res://scripts/spt25.gd" diff --git a/scenes/pribor-uyep/pribor-uyep.tscn b/scenes/pribor-uyep/pribor-uyep.tscn index 499b0c49..92f1e025 100644 --- a/scenes/pribor-uyep/pribor-uyep.tscn +++ b/scenes/pribor-uyep/pribor-uyep.tscn @@ -117,7 +117,7 @@ offset_top = 275.0 offset_right = 225.0 offset_bottom = 367.0 -[node name="sch3" parent="." instance=ExtResource("7_13r50")] +[node name="sch3" parent="." groups=["bit_items"] instance=ExtResource("7_13r50")] offset_left = 175.0 offset_top = 714.0 offset_right = 680.0 diff --git a/scenes/pribor-uyep/sch3-view.gd b/scenes/pribor-uyep/sch3-view.gd index d67a9c60..2c9a55cb 100644 --- a/scenes/pribor-uyep/sch3-view.gd +++ b/scenes/pribor-uyep/sch3-view.gd @@ -3,5 +3,22 @@ extends "res://scenes/контроль/элемент-я.gd" -func on_data_received(): - pass +func on_line_changed(_unit): + var items = get_tree().get_nodes_in_group('bit_items') + for item in items: + item.texture = textures[STATE_VAL.NONE] + + +func on_data_received(data: PackedByteArray): + var items = get_tree().get_nodes_in_group('bits_items') + for item in items: + var bits: Array = item.get_meta('bits') + var byte0: int = bits[0] + var bit0: int = bits[1] + var byte1: int = bits[2] + var bit1: int = bits[3] + var v = STATE_VAL.GOOD \ + if (data[byte0] & (1 << bit0)) \ + == (data[byte1] & (1 << bit1)) \ + else STATE_VAL.ERROR + item.texture = textures[v] diff --git a/scenes/pribor-uyep/sch3.tscn b/scenes/pribor-uyep/sch3.tscn index 20394596..fb96f27c 100644 --- a/scenes/pribor-uyep/sch3.tscn +++ b/scenes/pribor-uyep/sch3.tscn @@ -51,7 +51,7 @@ anchors_preset = 0 offset_left = 125.0 offset_top = 635.0 offset_right = 635.0 -offset_bottom = 855.0 +offset_bottom = 865.0 script = ExtResource("1_mb0l2") textures = [ExtResource("2_qglal"), ExtResource("3_gqvwf"), ExtResource("4_2lj00")] unit_name = "уарэп-щ3" @@ -59,7 +59,7 @@ unit_name = "уарэп-щ3" [node name="rect" type="NinePatchRect" parent="."] layout_mode = 2 offset_right = 510.0 -offset_bottom = 220.0 +offset_bottom = 230.0 size_flags_horizontal = 3 size_flags_vertical = 3 texture = ExtResource("5_eanbw") @@ -73,7 +73,7 @@ patch_margin_bottom = 15 [node name="margin" type="MarginContainer" parent="."] layout_mode = 2 offset_right = 510.0 -offset_bottom = 220.0 +offset_bottom = 230.0 theme_override_constants/margin_left = 8 theme_override_constants/margin_top = 8 theme_override_constants/margin_right = 8 @@ -86,6 +86,7 @@ layout_mode = 2 [node name="grid" type="GridContainer" parent="margin/vbox"] layout_mode = 2 +size_flags_vertical = 2 columns = 3 [node name="state" type="TextureRect" parent="margin/vbox/grid"] @@ -100,12 +101,11 @@ layout_mode = 2 size_flags_horizontal = 3 size_flags_vertical = 6 theme_override_font_sizes/font_size = 17 -horizontal_alignment = 1 vertical_alignment = 1 [node name="rname" type="Label" parent="margin/vbox/grid"] layout_mode = 2 -size_flags_horizontal = 10 +size_flags_horizontal = 3 size_flags_vertical = 6 theme_override_font_sizes/font_size = 22 horizontal_alignment = 2 @@ -113,9 +113,10 @@ vertical_alignment = 1 [node name="table" type="GridContainer" parent="margin/vbox"] layout_mode = 2 +size_flags_vertical = 6 columns = 8 -[node name="state0" type="TextureRect" parent="margin/vbox/table"] +[node name="state0" type="TextureRect" parent="margin/vbox/table" groups=["bits_items"]] custom_minimum_size = Vector2(24, 24) layout_mode = 2 size_flags_horizontal = 4 @@ -130,7 +131,7 @@ layout_mode = 2 theme_override_font_sizes/font_size = 17 text = "УФ" -[node name="state1" type="TextureRect" parent="margin/vbox/table"] +[node name="state1" type="TextureRect" parent="margin/vbox/table" groups=["bits_items"]] custom_minimum_size = Vector2(24, 24) layout_mode = 2 size_flags_horizontal = 4 @@ -145,7 +146,7 @@ layout_mode = 2 theme_override_font_sizes/font_size = 17 text = "РТР" -[node name="state2" type="TextureRect" parent="margin/vbox/table"] +[node name="state2" type="TextureRect" parent="margin/vbox/table" groups=["bits_items"]] custom_minimum_size = Vector2(24, 24) layout_mode = 2 texture = ExtResource("2_qglal") @@ -158,7 +159,7 @@ layout_mode = 2 theme_override_font_sizes/font_size = 17 text = "ПРД-Н.1" -[node name="state3" type="TextureRect" parent="margin/vbox/table"] +[node name="state3" type="TextureRect" parent="margin/vbox/table" groups=["bits_items"]] custom_minimum_size = Vector2(24, 24) layout_mode = 2 size_flags_horizontal = 4 @@ -173,7 +174,7 @@ layout_mode = 2 theme_override_font_sizes/font_size = 17 text = "ПРД-Н.2" -[node name="state4" type="TextureRect" parent="margin/vbox/table"] +[node name="state4" type="TextureRect" parent="margin/vbox/table" groups=["bits_items"]] custom_minimum_size = Vector2(24, 24) layout_mode = 2 size_flags_horizontal = 4 @@ -188,7 +189,7 @@ layout_mode = 2 theme_override_font_sizes/font_size = 17 text = "ПРД-Н.3" -[node name="state5" type="TextureRect" parent="margin/vbox/table"] +[node name="state5" type="TextureRect" parent="margin/vbox/table" groups=["bits_items"]] custom_minimum_size = Vector2(24, 24) layout_mode = 2 texture = ExtResource("2_qglal") @@ -201,7 +202,7 @@ layout_mode = 2 theme_override_font_sizes/font_size = 17 text = "ПРД-Н.4" -[node name="state6" type="TextureRect" parent="margin/vbox/table"] +[node name="state6" type="TextureRect" parent="margin/vbox/table" groups=["bits_items"]] custom_minimum_size = Vector2(24, 24) layout_mode = 2 size_flags_horizontal = 4 @@ -216,7 +217,7 @@ layout_mode = 2 theme_override_font_sizes/font_size = 17 text = "ПРД-В.1" -[node name="state7" type="TextureRect" parent="margin/vbox/table"] +[node name="state7" type="TextureRect" parent="margin/vbox/table" groups=["bits_items"]] custom_minimum_size = Vector2(24, 24) layout_mode = 2 size_flags_horizontal = 4 @@ -231,7 +232,7 @@ layout_mode = 2 theme_override_font_sizes/font_size = 17 text = "ПРД-В.2" -[node name="state8" type="TextureRect" parent="margin/vbox/table"] +[node name="state8" type="TextureRect" parent="margin/vbox/table" groups=["bits_items"]] custom_minimum_size = Vector2(24, 24) layout_mode = 2 texture = ExtResource("2_qglal") @@ -244,7 +245,7 @@ layout_mode = 2 theme_override_font_sizes/font_size = 17 text = "ПРД-В.3" -[node name="state9" type="TextureRect" parent="margin/vbox/table"] +[node name="state9" type="TextureRect" parent="margin/vbox/table" groups=["bits_items"]] custom_minimum_size = Vector2(24, 24) layout_mode = 2 size_flags_horizontal = 4 @@ -259,7 +260,7 @@ layout_mode = 2 theme_override_font_sizes/font_size = 17 text = "ПРД-В.4" -[node name="state10" type="TextureRect" parent="margin/vbox/table"] +[node name="state10" type="TextureRect" parent="margin/vbox/table" groups=["bits_items"]] custom_minimum_size = Vector2(24, 24) layout_mode = 2 size_flags_horizontal = 4 @@ -274,7 +275,7 @@ layout_mode = 2 theme_override_font_sizes/font_size = 17 text = "ПРД-К.1" -[node name="state11" type="TextureRect" parent="margin/vbox/table"] +[node name="state11" type="TextureRect" parent="margin/vbox/table" groups=["bits_items"]] custom_minimum_size = Vector2(24, 24) layout_mode = 2 texture = ExtResource("2_qglal") @@ -287,7 +288,7 @@ layout_mode = 2 theme_override_font_sizes/font_size = 17 text = "ПРД-К.2" -[node name="state12" type="TextureRect" parent="margin/vbox/table"] +[node name="state12" type="TextureRect" parent="margin/vbox/table" groups=["bits_items"]] custom_minimum_size = Vector2(24, 24) layout_mode = 2 size_flags_horizontal = 4 @@ -302,7 +303,7 @@ layout_mode = 2 theme_override_font_sizes/font_size = 17 text = "ПРД-К.3" -[node name="state13" type="TextureRect" parent="margin/vbox/table"] +[node name="state13" type="TextureRect" parent="margin/vbox/table" groups=["bits_items"]] custom_minimum_size = Vector2(24, 24) layout_mode = 2 texture = ExtResource("2_qglal") @@ -315,7 +316,7 @@ layout_mode = 2 theme_override_font_sizes/font_size = 17 text = "ПРД-К.4" -[node name="state14" type="TextureRect" parent="margin/vbox/table"] +[node name="state14" type="TextureRect" parent="margin/vbox/table" groups=["bits_items"]] custom_minimum_size = Vector2(24, 24) layout_mode = 2 size_flags_horizontal = 4 @@ -330,7 +331,7 @@ layout_mode = 2 theme_override_font_sizes/font_size = 17 text = "Бл. по вент." -[node name="state15" type="TextureRect" parent="margin/vbox/table"] +[node name="state15" type="TextureRect" parent="margin/vbox/table" groups=["bits_items"]] custom_minimum_size = Vector2(24, 24) layout_mode = 2 size_flags_horizontal = 4 @@ -345,7 +346,7 @@ layout_mode = 2 theme_override_font_sizes/font_size = 17 text = "ДУ" -[node name="state16" type="TextureRect" parent="margin/vbox/table"] +[node name="state16" type="TextureRect" parent="margin/vbox/table" groups=["bits_items"]] custom_minimum_size = Vector2(24, 24) layout_mode = 2 texture = ExtResource("2_qglal") @@ -358,7 +359,7 @@ layout_mode = 2 theme_override_font_sizes/font_size = 17 text = "Вент. РТР" -[node name="state17" type="TextureRect" parent="margin/vbox/table"] +[node name="state17" type="TextureRect" parent="margin/vbox/table" groups=["bits_items"]] custom_minimum_size = Vector2(24, 24) layout_mode = 2 size_flags_horizontal = 4 @@ -373,7 +374,7 @@ layout_mode = 2 theme_override_font_sizes/font_size = 17 text = "Вент. ПРД.1" -[node name="state18" type="TextureRect" parent="margin/vbox/table"] +[node name="state18" type="TextureRect" parent="margin/vbox/table" groups=["bits_items"]] custom_minimum_size = Vector2(24, 24) layout_mode = 2 texture = ExtResource("2_qglal") @@ -386,7 +387,7 @@ layout_mode = 2 theme_override_font_sizes/font_size = 17 text = "Вент. ПРД.2" -[node name="state19" type="TextureRect" parent="margin/vbox/table"] +[node name="state19" type="TextureRect" parent="margin/vbox/table" groups=["bits_items"]] custom_minimum_size = Vector2(24, 24) layout_mode = 2 texture = ExtResource("2_qglal") @@ -399,7 +400,7 @@ layout_mode = 2 theme_override_font_sizes/font_size = 17 text = "Вент. ПРД.3" -[node name="state20" type="TextureRect" parent="margin/vbox/table"] +[node name="state20" type="TextureRect" parent="margin/vbox/table" groups=["bits_items"]] custom_minimum_size = Vector2(24, 24) layout_mode = 2 texture = ExtResource("2_qglal") @@ -415,7 +416,7 @@ text = "Вент. ПРД.4" [node name="button" type="Button" parent="."] layout_mode = 2 offset_right = 510.0 -offset_bottom = 220.0 +offset_bottom = 230.0 theme_override_styles/normal = SubResource("StyleBoxEmpty_ox0yw") theme_override_styles/hover = SubResource("StyleBoxEmpty_xxyaa") theme_override_styles/pressed = SubResource("StyleBoxEmpty_cd4fw") diff --git a/scripts/modbus.gd b/scripts/modbus.gd deleted file mode 100644 index 46730f37..00000000 --- a/scripts/modbus.gd +++ /dev/null @@ -1,126 +0,0 @@ -class_name mod_bus extends Node - -const ONLINE_TIMEOUT = 5.0 ## Время ожидания пакета от ячейки, секунды. - -class ModbusClient: - - ## Состояние автомата выполнения команды. - enum CmdState { - DONE, ## Команда выполнена. - FAIL, ## Команда не выполнена. - SEND, ## Буфер готов для отправки. - WAIT ## Ожидание выполнения. - } - - var name: String - var unit: = 1 ## Адрес устройства Modbus. - var cmd_state: = CmdState.DONE ## Код текущей команды. - var tx_data: PackedByteArray ## Данные для отправки. - var online: = false ## Флаг. Если установлен, устройство на связи. Активный уровень - [b]true[/b]. - var tick_rx: = 0 ## Время приёма крайнего сообщения. - var tick_tx: = 0 ## Время отправки крайнего сообщения. - - static var json_conv: = JSON.new() - - signal command_done() ## Вызывается при успешном выполнении команды. - signal command_fail(unit: ModbusClient) ## Вызывается при возникновении ошибки во время выполнения команды. - signal line_changed(unit: ModbusClient) ## Вызывается при смене состояния связи с ячейкой. - signal data_received() ## Вызывается при приёме сообщения, до его разбора. - signal parse_failed(msg: String) ## Вызывается при возникновении ошибки во время разбора пакета. Передаёт сообщение об ошибке. - - signal responce_received(addr: int, data: Array) ## Вызывается при получении сообщения c данными из регистров хранения. - signal info_received(msg: String) ## Вызывается при получении информационного сообщения. - signal except_received(msg: String) ## Вызывается при получении сообщения об исключительной ситуации. - - func _init(nm: String, u: int = 1): - unit = u - name = nm - - ## Изменяет состояние. Вызывать периодически.[br] - ## [param tick] - Текущщее время в мс.[br] - func process(tick: int): - if online and ((tick - tick_rx) > ONLINE_TIMEOUT): - online = false - emit_signal('line_changed', self) - if (cmd_state == CmdState.WAIT) or (cmd_state == CmdState.SEND): - cmd_state = CmdState.FAIL - emit_signal('command_fail', self) - var rc = Error.ERR_BUSY - if cmd_state == CmdState.SEND: - rc = Error.OK - tick_tx = tick - cmd_state = CmdState.WAIT - return rc - - ## Производит разбор принятых данных. Вызывать при приёме данных на сокете.[br] - ## [param data] - Данные принятые на сокете.[br] - ## [param tick] - Текущщее время в мс.[br] - func parse(data: PackedByteArray, tick: int) -> bool: - tick_rx = tick - if not online: - online = true - emit_signal('line_changed', self) - var utf8_data = data.get_string_from_utf8() - if Error.OK == json_conv.parse(utf8_data): - emit_signal('data_received') - var message: Dictionary = json_conv.get_data() - if message.has('code') and message.has('data'): - var rc: = true - var message_code = message['code'] - var message_data = message['data'] - match message_code: - 'response': - var addr = message_data[0] - var regs = message_data.slice(1) - emit_signal('responce_received', addr, regs) - 'info': - var msg = message['data'] - emit_signal('info_received', msg) - 'exception': - var msg = message['data'] - emit_signal('except_received', msg) - rc = false - _: - var msg: String = 'код команды \"%s\" - не распознан' % message_code - emit_signal('parse_failed', msg) - rc = false - if (cmd_state == CmdState.WAIT) and rc: - cmd_state = CmdState.DONE - emit_signal('command_done') - elif (cmd_state == CmdState.WAIT) and (not rc): - cmd_state = CmdState.FAIL - emit_signal('command_fail', self) - else: - var message = json_conv.get_error_message() - emit_signal('parse_failed', message) - return true - - ## Отправляет команду "записать в регистры".[br] - ## [param addr] - Начальный адрес регистров.[br] - ## [param count] - Данные для записи в регистры от начального адреса.[br] - func write(addr: int, data: Array) -> bool: - if cmd_state != CmdState.DONE: return false - var json_dict = {'code': 'write', 'data': [addr] + data} - tx_data = JSON.stringify(json_dict).to_utf8_buffer() - cmd_state = CmdState.SEND - return true - - ## Отправляет команду "читать регистры хранения".[br] - ## [param addr] - Начальный адрес регистров.[br] - ## [param count] - Количество регистров от начального адреса.[br] - func read_holdind(addr: int, count: int = 1) -> bool: - if cmd_state != CmdState.DONE: return false - var json_dict = {'code': 'read_holding', 'data': [addr, count]} - tx_data = JSON.stringify(json_dict).to_utf8_buffer() - cmd_state = CmdState.SEND - return true - - ## Отправляет команду "читать регистры входов".[br] - ## [param addr] - Начальный адрес регистров.[br] - ## [param count] - Количество регистров от начального адреса.[br] - func read_input(addr: int, count: int = 1) -> bool: - if cmd_state != CmdState.DONE: return false - var json_dict = {'code': 'read_input', 'data': [addr, count]} - tx_data = JSON.stringify(json_dict).to_utf8_buffer() - cmd_state = CmdState.SEND - return true diff --git a/scripts/network.gd b/scripts/network.gd index 1179492e..3d806324 100644 --- a/scripts/network.gd +++ b/scripts/network.gd @@ -1,7 +1,7 @@ class_name rep_network extends Node -const PROTOCOL_TYPES: = {'yau07tx': yau07.YaU07, 'json-capsrpb': capsrpb.CapsRpb, 'udp-json-mbcs': modbus.ModbusClient} +const PROTOCOL_TYPES: = {'yau07tx': yau07.YaU07, 'json-capsrpb': capsrpb.CapsRpb, 'udp-json-mbcs': sch3.Sch3} const TCP_PROTO: = {'5p28': tcp5p28.TCP5P28} const SERIAL_PROTO: = {'uart': spt25.SPT25 } diff --git a/scripts/sch3.gd b/scripts/sch3.gd index 55469832..a2b2e205 100644 --- a/scripts/sch3.gd +++ b/scripts/sch3.gd @@ -1,26 +1,116 @@ -extends Node +class_name sch_3 extends Node -var cnt: int = 0 -var rw: bool = true +const ONLINE_TIMEOUT = 5.0 ## Время ожидания пакета от ячейки, секунды. -func _ready(): - var unit_key = settings.get_unit_key('уарэп-щ3') - var unit = network.units[unit_key] - var timer = Timer.new() - add_child(timer) - unit.connect('command_fail', Callable(self, 'on_command_fail')) - timer.connect('timeout', Callable(self, 'on_timer').bind(unit)) - timer.start(1.0) +class Sch3 extends unit.Unit: + ## Состояние автомата выполнения команды. + enum CmdState { + DONE, ## Команда выполнена. + FAIL, ## Команда не выполнена. + SEND, ## Буфер готов для отправки. + WAIT ## Ожидание выполнения. + } -func on_timer(unit): - cnt +=1 - if rw: - unit.write(0x0000, [cnt]) - else: - unit.read_holdind(0x0000) - rw = not rw + var unit: = 1 ## Адрес устройства Modbus. + var cmd_state: = CmdState.DONE ## Код текущей команды. + var tick_rx: = 0 ## Время приёма крайнего сообщения. + var tick_tx: = 0 ## Время отправки крайнего сообщения. + static var json_conv: = JSON.new() + signal responce_received(addr: int, data: Array) ## Вызывается при получении сообщения c данными из регистров хранения. + signal info_received(msg: String) ## Вызывается при получении информационного сообщения. + signal except_received(msg: String) ## Вызывается при получении сообщения об исключительной ситуации. -func on_command_fail(unit): - unit.cmd_state = unit.CmdState.DONE + func _init(nm: String, u: int = 1): + unit = u + name = nm + + ## Изменяет состояние. Вызывать периодически.[br] + ## [param tick] - Текущщее время в мс.[br] + func process(tick: int): + if online and ((tick - tick_rx) > ONLINE_TIMEOUT): + online = false + emit_signal('line_changed', self) + if (cmd_state == CmdState.WAIT) or (cmd_state == CmdState.SEND): + cmd_state = CmdState.FAIL + emit_signal('command_fail', self) + var rc = Error.ERR_BUSY + if cmd_state == CmdState.SEND: + rc = Error.OK + tick_tx = tick + cmd_state = CmdState.WAIT + return rc + + ## Производит разбор принятых данных. Вызывать при приёме данных на сокете.[br] + ## [param data] - Данные принятые на сокете.[br] + ## [param tick] - Текущщее время в мс.[br] + func parse(data: PackedByteArray, tick: int) -> bool: + tick_rx = tick + if not online: + online = true + emit_signal('line_changed', self) + var utf8_data = data.get_string_from_utf8() + if Error.OK == json_conv.parse(utf8_data): + emit_signal('data_received') + var message: Dictionary = json_conv.get_data() + if message.has('code') and message.has('data'): + var rc: = true + var message_code = message['code'] + var message_data = message['data'] + match message_code: + 'response': + var addr = message_data[0] + var regs = message_data.slice(1) + emit_signal('responce_received', addr, regs) + 'info': + var msg = message['data'] + emit_signal('info_received', msg) + 'exception': + var msg = message['data'] + emit_signal('except_received', msg) + rc = false + _: + var msg: String = 'код команды \"%s\" - не распознан' % message_code + emit_signal('parse_failed', msg) + rc = false + if (cmd_state == CmdState.WAIT) and rc: + cmd_state = CmdState.DONE + emit_signal('command_done') + elif (cmd_state == CmdState.WAIT) and (not rc): + cmd_state = CmdState.FAIL + emit_signal('command_fail', self) + else: + var message = json_conv.get_error_message() + emit_signal('parse_failed', message) + return true + + ## Отправляет команду "записать в регистры".[br] + ## [param addr] - Начальный адрес регистров.[br] + ## [param count] - Данные для записи в регистры от начального адреса.[br] + func write(addr: int, data: Array) -> bool: + if cmd_state != CmdState.DONE: return false + var json_dict = {'code': 'write', 'data': [addr] + data} + tx_data = JSON.stringify(json_dict).to_utf8_buffer() + cmd_state = CmdState.SEND + return true + + ## Отправляет команду "читать регистры хранения".[br] + ## [param addr] - Начальный адрес регистров.[br] + ## [param count] - Количество регистров от начального адреса.[br] + func read_holdind(addr: int, count: int = 1) -> bool: + if cmd_state != CmdState.DONE: return false + var json_dict = {'code': 'read_holding', 'data': [addr, count]} + tx_data = JSON.stringify(json_dict).to_utf8_buffer() + cmd_state = CmdState.SEND + return true + + ## Отправляет команду "читать регистры входов".[br] + ## [param addr] - Начальный адрес регистров.[br] + ## [param count] - Количество регистров от начального адреса.[br] + func read_input(addr: int, count: int = 1) -> bool: + if cmd_state != CmdState.DONE: return false + var json_dict = {'code': 'read_input', 'data': [addr, count]} + tx_data = JSON.stringify(json_dict).to_utf8_buffer() + cmd_state = CmdState.SEND + return true