8. [openapi.py] 增加心跳检测函数,并开启线程执行;取消在该文件中生成实例
9. [aio.py] 完成detect_network,并在main函数开启线程
10. 将templates文件夹移动到assets内
This commit is contained in:
2024-06-23 20:18:41 +08:00
parent 295894a843
commit a4009eb17c
14 changed files with 50 additions and 29 deletions

View File

@ -1,16 +1,19 @@
import openapi
hr = openapi.hr
hr = openapi.HmiRequest()
# 一、设置/检测机器人状态:
# 1. 上电
# 2. 软限位打开
# 3. 示教器断开
# 4. 操作模式
# 4. 操作模式/机器人类型
# 5. 控制器状态/工作任务控件/机器人动态
# 二、加载RL程序开始运行
# 1. 怎么触发急停
# 2. 怎么恢复急停
# 3. 怎么采集曲线
# 4.
# 三、运行过程中,收集数据,并处理出结果

View File

@ -10,25 +10,26 @@ MAX_FRAME_SIZE = 1024
class HmiRequest(object):
def __init__(self):
super().__init__()
self.c = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.c.connect(('192.168.0.160', 5050))
# self.c.connect(('192.168.84.129', 5050))
# self.c.connect(('192.168.0.160', 5050))
self.c.connect(('192.168.84.129', 5050))
self.c.setblocking(False)
self.c_msg = []
self.c_xs = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.c_xs.connect(('192.168.0.160', 6666))
# self.c_xs.connect(('192.168.84.129', 6666))
# self.c_xs.connect(('192.168.0.160', 6666))
self.c_xs.connect(('192.168.84.129', 6666))
self.c_xs.setblocking(False)
self.c_msg_xs = []
self.t_heartbeat = threading.Thread(target=self.__heartbeat)
self.t_heartbeat.daemon = True
self.t_heartbeat.start()
self.t_unpackage = threading.Thread(target=self.__unpackage, args=(self.c, ))
self.t_unpackage.daemon = True
self.t_unpackage.start()
self.t_unpackage_xs = threading.Thread(target=self.__unpackage_xs, args=(self.c_xs, ))
self.t_unpackage_xs.daemon = True
self.t_unpackage_xs.start()
# self.t = threading.Thread(target=self.__heartbeat)
# self.t.daemon = True
# self.t.start()
self.flag = 0
self.response = ''
self.leftover = 0
@ -52,6 +53,14 @@ class HmiRequest(object):
print("无法读取数据,需要确认")
exit(10)
def __heartbeat(self):
while True:
_id = self.excution('controller.heart')
_flag = 1 if self.get_from_id(_id) else 0
with open("./templates/heartbeat", "w", encoding='utf-8') as f_h:
f_h.write(str(_flag))
time.sleep(10)
def __msg_storage(self, response, flag=0):
messages = self.c_msg if flag == 0 else self.c_msg_xs
if len(messages) < 1000:
@ -154,7 +163,8 @@ class HmiRequest(object):
return msg
time.sleep(1)
else:
print(f'无法查询到{msg_id}对应的响应')
# print(f'无法查询到{msg_id}对应的响应')
return None
def __package(self, cmd):
_frame_head = (len(cmd)+6).to_bytes(length=2, byteorder='big')
@ -234,11 +244,3 @@ class HmiRequest(object):
return req['id']
else: # for xService
pass
hr = HmiRequest()

View File

@ -1,5 +0,0 @@
{
"id": "xxxxxxxxxxx",
"module": "system",
"command": "device.get_params"
}

View File

@ -1,5 +0,0 @@
{
"id": "xxxxxxxxxxx",
"module": "system",
"command": "state.get_state"
}

View File

@ -1,5 +0,0 @@
{
"id": "xxxxxxxxxxx",
"module": "system",
"command": "state.get_tp_mode"
}

View File

@ -1,8 +0,0 @@
{
"id": "xxxxxxxxxxx",
"module": "system",
"command": "state.set_tp_mode",
"data": {
"tp_mode": "with"
}
}

View File

@ -1,5 +0,0 @@
{
"id": "xxxxxxxxxxx",
"module": "system",
"command": "state.switch_auto"
}

View File

@ -1,5 +0,0 @@
{
"id": "xxxxxxxxxxx",
"module": "system",
"command": "state.switch_manual"
}

View File

@ -1,5 +0,0 @@
{
"id": "xxxxxxxxxxx",
"module": "system",
"command": "state.switch_motor_off"
}

View File

@ -1,5 +0,0 @@
{
"id": "xxxxxxxxxxx",
"module": "system",
"command": "state.switch_motor_on"
}