积累更新

This commit is contained in:
何 泽隆
2024-10-31 09:01:49 +08:00
parent eeb476a538
commit 73a36c35bb
13 changed files with 175 additions and 165 deletions

View File

@@ -1,8 +1,8 @@
import time
from serial import Serial
from function.tools.ByteConv import conv_int_to_array, trans_list_to_str
from function.frame import make_frame_modbus, check_frame_modbus, print_display
from . import tools
from . import function
class DeviceSerial:
""" 串口通信设备原型
@@ -52,20 +52,20 @@ class DeviceSerial:
flag_frame = True
frame_recv += bytes_read
try:
self.output = check_frame_modbus(frame_recv, self.block['data'])
self.output = function.frame.check_frame_modbus(frame_recv, self.block['data'])
if self.flag_print:
print("Read Frame: ", trans_list_to_str(frame_recv))
print("Read Frame: ", tools.ByteConv.trans_list_to_str(frame_recv))
except Exception as ex:
print("Error Info: ", ex)
if self.flag_print and frame_recv:
print("Fail Data: " , trans_list_to_str(frame_recv))
print("Fail Data: " , tools.ByteConv.trans_list_to_str(frame_recv))
self.output['result'] = False
return self.output['result']
def __transfer_data(self, frame: bytearray) -> bool:
""" 串口收发报文, 包含重试逻辑与数据打印 """
if self.__com is None:
print(trans_list_to_str(frame))
print(tools.ByteConv.trans_list_to_str(frame))
return False
fail_count = 0
@@ -77,12 +77,12 @@ class DeviceSerial:
if self.flag_print and frame_discard:
print("Discard Data: " , frame_discard)
if self.flag_print:
print("Send Frame: ", trans_list_to_str(frame))
print("Send Frame: ", tools.ByteConv.trans_list_to_str(frame))
time.sleep(10 * self.time_gap)
if self.__read_frame():
if (self.flag_print is not None) and 'Regs' in self.output.keys():
print_display(self.output['Regs'])
function.frame.print_display(self.output['Regs'])
self.log['read'] += 1
break
else: