v0.2.0.6(2024/08/09)

1. [t_change_ui: all files]
   - 修改了 logger 的实现
   - 尤其是 clibs.py,使用日志字典,重写了日志记录的功能
This commit is contained in:
2024-08-09 10:47:22 +08:00
parent 340d48876b
commit 3814d163c5
13 changed files with 106 additions and 57 deletions

View File

@ -6,11 +6,9 @@ from time import time, sleep
from pymodbus.client.tcp import ModbusTcpClient
from pymodbus.payload import BinaryPayloadDecoder, BinaryPayloadBuilder
from pymodbus.constants import Endian
from logging import getLogger, INFO
from commons import clibs
logger = getLogger(__file__)
logger.setLevel(INFO)
logger = clibs.log_prod
class ModbusRequest(object):
@ -263,7 +261,7 @@ class HmiRequest(object):
def msg_storage(self, response, flag=0):
# response是解码后的字符串
messages = self.c_msg if flag == 0 else self.c_msg_xs
logger.info(f"{loads(response)}")
logger.debug(f"{loads(response)}")
if 'move.monitor' in response:
pass
elif len(messages) < 10000:
@ -504,7 +502,7 @@ class HmiRequest(object):
def get_from_id(self, msg_id, flag=0):
for i in range(3):
with open(clibs.log_data, mode='r', encoding='utf-8') as f_log:
with open(clibs.log_data_hmi, mode='r', encoding='utf-8') as f_log:
for line in f_log:
if msg_id in line.strip():
return line
@ -512,7 +510,7 @@ class HmiRequest(object):
else: # 尝试在上一次分割的日志中查找,只做一次
sleep(1)
try:
with open(clibs.log_data+'.1', mode='r', encoding='utf-8') as f_log:
with open(clibs.log_data_hmi+'.1', mode='r', encoding='utf-8') as f_log:
for line in f_log:
if msg_id in line.strip():
return line
@ -617,7 +615,7 @@ class HmiRequest(object):
self.c.send(self.package(cmd))
sleep(0.5)
except Exception as Err:
self.w2t(f"{cmd}\n请求发送失败...{Err}", 0, 0, 'red', tab_name=self.tab_name)
self.w2t(f"{cmd}: 请求发送失败...{Err}", 0, 0, 'red', tab_name=self.tab_name)
return req['id']