Extract reusable byte work panel with configurable terminal addressing

This commit is contained in:
2026-10-09 08:56:16 +03:00
parent fe9b5a246e
commit 86ece3ea90
6 changed files with 493 additions and 69 deletions

View File

@@ -322,8 +322,10 @@ class SerialTab(QWidget):
MACROS_FILE = "macros.json" # Файл для сохранения макросов
def __init__(self, serial_bus, raw_protocol, raw_widget):
super().__init__()
def __init__(self, serial_bus, raw_protocol, raw_widget, parent=None, *,
device_address=10, macros_file=None):
super().__init__(parent)
self.device_address = device_address
self.serial_bus = serial_bus
self.raw_protocol = raw_protocol
self.raw_widget = raw_widget
@@ -333,7 +335,8 @@ class SerialTab(QWidget):
self._macro_generation = 0
from pathlib import Path
self.MACROS_FILE = str(Path(QStandardPaths.writableLocation(QStandardPaths.AppDataLocation)) / "pysetterminal" / "macros.json")
self.MACROS_FILE = str(macros_file if macros_file is not None else
Path(QStandardPaths.writableLocation(QStandardPaths.AppDataLocation)) / "pysetterminal" / "macros.json")
Path(self.MACROS_FILE).parent.mkdir(parents=True, exist_ok=True)
# Загружаем сохраненные макросы
self.load_macros()
@@ -455,7 +458,7 @@ class SerialTab(QWidget):
def write_to_bus(self):
"""Запись в шину через регистры"""
try:
device_addr = 10
device_addr = self.device_address() if callable(self.device_address) else self.device_address
data = int(self.bus_data_edit.text(), 16)
tetrad = int(self.bus_tetrad_edit.text())
register_num = int(self.bus_register_edit.text())
@@ -477,7 +480,7 @@ class SerialTab(QWidget):
def read_from_bus(self):
"""Чтение из шины через регистры"""
try:
device_addr = 10
device_addr = self.device_address() if callable(self.device_address) else self.device_address
tetrad = int(self.bus_tetrad_edit.text())
register_num = int(self.bus_register_edit.text())
@@ -652,6 +655,7 @@ class SerialTab(QWidget):
return
from protocan.tms_terminal import bus_steps
try:
controller = self.device_address() if callable(self.device_address) else self.device_address
jobs = []
for command in commands:
if command['type'] not in ('write', 'read'):
@@ -664,6 +668,7 @@ class SerialTab(QWidget):
if not jobs:
self.raw_widget.append_text("Макрос пуст")
return
self._macro_controller = controller
self._macro_jobs = jobs
self._macro_index = 0
self._macro_running = True
@@ -686,7 +691,7 @@ class SerialTab(QWidget):
return
generation = self._macro_generation
address, value = self._macro_jobs[self._macro_index]
self.raw_protocol.request_async(address, value, 10,
self.raw_protocol.request_async(address, value, self._macro_controller,
lambda success, result: self._macro_reply(generation, success, result))
def _macro_reply(self, generation, success, result):