重构设备类定义, 使用继承简化代码;
This commit is contained in:
@@ -54,11 +54,11 @@ class EnergyRouter:
|
||||
time.sleep(self.time_out)
|
||||
frame_recv = self.tcp_socket.recv(128)
|
||||
|
||||
self.output = function.frame.check_frame_modbus(frame_recv, self.block)
|
||||
self.output = function.protocols.check_frame_modbus(frame_recv, self.block)
|
||||
if self.flag_print:
|
||||
print("Read Frame: ", tools.ByteConv.trans_list_to_str(frame_recv))
|
||||
if 'Regs' in self.output.keys():
|
||||
function.frame.print_display(self.output['Regs'])
|
||||
function.protocols.print_display(self.output['Regs'])
|
||||
except Exception as ex:
|
||||
print("Error Info: ", ex)
|
||||
if self.flag_print and frame_recv:
|
||||
@@ -71,7 +71,7 @@ class EnergyRouter:
|
||||
self.block['type'] = 'read'
|
||||
self.block['data_addr'] = daddr
|
||||
self.block['data_len'] = dlen
|
||||
frame = function.frame.make_frame_modbus(self.block)
|
||||
frame = function.protocols.make_frame_modbus(self.block)
|
||||
|
||||
return self.__transfer_data(frame)
|
||||
|
||||
@@ -86,7 +86,7 @@ class EnergyRouter:
|
||||
self.block['file'] = Path(path_bin).read_bytes()
|
||||
self.block['header_offset'] = 128
|
||||
# 启动帧
|
||||
frame_master = function.frame.make_frame_modbus(self.block)
|
||||
frame_master = function.protocols.make_frame_modbus(self.block)
|
||||
|
||||
if not self.__transfer_data(frame_master):
|
||||
self.flag_print, self.retry, self.time_out = param_saved
|
||||
@@ -116,7 +116,7 @@ class EnergyRouter:
|
||||
continue
|
||||
seq_window[i] = 1
|
||||
self.block['index'] = seq_offset + i
|
||||
seq_frame_master[i] = function.frame.make_frame_modbus(self.block)
|
||||
seq_frame_master[i] = function.protocols.make_frame_modbus(self.block)
|
||||
self.tcp_socket.send(seq_frame_master[i])
|
||||
# 接收帧回复
|
||||
tmp = list(zip(range(len(seq_window)), seq_window))
|
||||
@@ -126,7 +126,7 @@ class EnergyRouter:
|
||||
# 接收到空数据, 对端已关闭连接
|
||||
if seq_frame_slave[i] == '':
|
||||
raise Exception("TCP closed.")
|
||||
self.output = function.frame.check_frame_modbus(seq_frame_slave[i], None)
|
||||
self.output = function.protocols.check_frame_modbus(seq_frame_slave[i], None)
|
||||
seq_current, seq_hope = self.output['upgrade']['index'], self.output['upgrade']['hope']
|
||||
if seq_current < seq_offset:
|
||||
raise Exception("Error.")
|
||||
@@ -152,14 +152,14 @@ class EnergyRouter:
|
||||
|
||||
# 结束升级
|
||||
self.block['step'] = 'end'
|
||||
frame_master = function.frame.make_frame_modbus(self.block)
|
||||
frame_master = function.protocols.make_frame_modbus(self.block)
|
||||
|
||||
while self.output['result'] is False:
|
||||
self.tcp_socket.send(frame_master)
|
||||
frame_slave = self.tcp_socket.recv(8)
|
||||
if frame_slave == '':
|
||||
raise Exception("TCP closed.")
|
||||
self.output = function.frame.check_frame_modbus(frame_slave[:18], self.block)
|
||||
self.output = function.protocols.check_frame_modbus(frame_slave[:18], self.block)
|
||||
|
||||
|
||||
def GeneratePackage_Demo_Xilinx(path_bin: Path):
|
||||
|
||||
Reference in New Issue
Block a user