v0.1.7.5(2024/07/03)

1. [APIs: aio.py]
   - 增加触发急停和恢复急停功能逻辑
2. [APIs: do_current.py]
   - 重新调整运行顺序,增加数据处理的逻辑(惯量负载逻辑暂不实现,等待软件部解决了修改工程之后不生效的问题再考虑)
3. [APIs: btn_functions.py]
   - 增加触发急停和恢复急停的modbus实现,仅适用于自动化测试

v0.1.7.6(2024/07/04)
1. [APIs: aio.py]
   - Automatic Test逻辑中增加选择current时,需要选负载类型的逻辑
2. [APIs: do_current.py]
   - 单轴/场景电机电流的采集已完成
3. [APIs: openapi.py]
   - 增加了modbus读取浮点数的功能
   - 优化了get_from_id的逻辑
4. [autotest.xml]: 新增了scenario_time只写寄存器
This commit is contained in:
2024-07-04 13:34:04 +08:00
parent aedac4c90c
commit 524af160d8
6 changed files with 287 additions and 93 deletions

View File

@ -4,8 +4,9 @@ from threading import Thread
import selectors
from time import time, sleep
from os.path import dirname
from binascii import b2a_hex, a2b_hex
from pymodbus.client.tcp import ModbusTcpClient
from pymodbus.payload import BinaryPayloadDecoder
from pymodbus.constants import Endian
MAX_FRAME_SIZE = 1024
setdefaulttimeout(2)
@ -113,6 +114,16 @@ class ModbusRequest(object):
self.w2t(f"{Err}")
self.w2t("无法读取准备信号连接Modbus失败需要确认网络是否通畅或是未正确导入寄存器文件...", 0, 100, 'red', self.tab_name)
def read_scenario_time(self):
try:
results = self.c.read_holding_registers(41002, 2)
result = BinaryPayloadDecoder.fromRegisters(results.registers, byteorder=Endian.BIG, wordorder=Endian.LITTLE)
result = f"{result.decode_32bit_float():.3f}"
return result
except Exception as Err:
self.w2t(f"{Err}")
self.w2t("无法读取准备信号连接Modbus失败需要确认网络是否通畅或是未正确导入寄存器文件...", 0, 100, 'red', self.tab_name)
class HmiRequest(object):
def __init__(self, w2t):
@ -185,10 +196,10 @@ class HmiRequest(object):
return index + 8, _frame_size, _pkg_size
else:
print(data)
print(f"index = {index}")
print(f"reserve = {_reserved}")
print(f"protocol = {_protocol}")
print("head check 数据有误,需要确认")
# print(f"index = {index}")
# print(f"reserve = {_reserved}")
# print(f"protocol = {_protocol}")
# print("head check 数据有误,需要确认")
self.w2t("Header Check: 解包数据有误,需要确认!", 0, 1, 'red', tab_name=self.tab_name)
else:
self.half_length = len(data) - index
@ -208,12 +219,12 @@ class HmiRequest(object):
_flag = '0' if self.get_from_id(_id) is None else '1'
print(f"hb = {_flag}", end=' ')
print(f"len(c_msg) = {len(self.c_msg)}", end=' ')
print(f"len(c_msg_xs) = {len(self.c_msg_xs)}", end=' ')
print(f"len(c_msg_xs) = {len(self.c_msg_xs)}", end='\n')
with open(f"{current_path}/../../assets/templates/heartbeat", "w", encoding='utf-8') as f_hb:
f_hb.write(_flag)
if _flag == '0':
self.w2t(f"{_id} 心跳丢失,连接失败,重新连接中...", 0, 7, 'red', tab_name=self.tab_name)
sleep(1)
sleep(2)
# with open(f"{current_path}/../../assets/templates/c_msg.log", "w", encoding='utf-8') as f:
# for msg in self.c_msg:
# f.write(str(loads(msg)) + '\n')
@ -457,8 +468,8 @@ class HmiRequest(object):
self.flag_xs = 1
def get_from_id(self, msg_id, flag=0):
messages = self.c_msg if flag == 0 else self.c_msg_xs
for i in range(3):
messages = self.c_msg if flag == 0 else self.c_msg_xs
for msg in messages:
if msg_id is None:
return None
@ -552,7 +563,7 @@ class HmiRequest(object):
pass
req['id'] = self.gen_id(command)
print(f"req = {req}")
# print(f"req = {req}")
cmd = dumps(req, separators=(',', ':'))
try:
self.c.send(self.package(cmd))