20240623
8. [openapi.py] 增加心跳检测函数,并开启线程执行;取消在该文件中生成实例 9. [aio.py] 完成detect_network,并在main函数开启线程 10. 将templates文件夹移动到assets内
This commit is contained in:
parent
295894a843
commit
a4009eb17c
@ -259,6 +259,9 @@ v0.1.7.0(2024/06/29)
|
||||
- 输入框:文件路径/角速度/减速比
|
||||
- OptionMenu:负载
|
||||
- 进度条
|
||||
8. [openapi.py] 增加心跳检测函数,并开启线程执行;取消在该文件中生成实例
|
||||
9. [aio.py] 完成detect_network,并在main函数开启线程
|
||||
10. 将templates文件夹移动到assets内
|
||||
|
||||
> **关于HMI接口**
|
||||
> - 封包解包顺序:帧长度二字节/包长度四字节/协议二字节/预留二字节,\x04\x00:\x00\x00\tR:\x02:\x00
|
||||
|
5
aio/assets/templates/controller.heart.json
Normal file
5
aio/assets/templates/controller.heart.json
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"id": "xxxxxxxxxxx",
|
||||
"module": "system",
|
||||
"command": "controller.heart"
|
||||
}
|
1
aio/assets/templates/heartbeat
Normal file
1
aio/assets/templates/heartbeat
Normal file
@ -0,0 +1 @@
|
||||
0
|
@ -4,7 +4,7 @@ from os import getcwd
|
||||
from threading import Thread
|
||||
import tkinter.messagebox
|
||||
import customtkinter
|
||||
from time import time, strftime, localtime
|
||||
from time import time, strftime, localtime, sleep
|
||||
from urllib.request import urlopen
|
||||
from socket import setdefaulttimeout
|
||||
import data_process.brake as brake
|
||||
@ -70,9 +70,6 @@ widgits_at = {
|
||||
class App(customtkinter.CTk):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.net_detect = Thread(target=self.detect_network)
|
||||
self.net_detect.daemon = True
|
||||
self.net_detect.start()
|
||||
self.my_font = customtkinter.CTkFont(family="Consolas", size=16, weight="bold")
|
||||
self.w_param = 84
|
||||
# =====================================================================
|
||||
@ -209,7 +206,11 @@ class App(customtkinter.CTk):
|
||||
pass
|
||||
|
||||
def detect_network(self):
|
||||
pass
|
||||
while True:
|
||||
with open('./automatic_test/templates/heartbeat', 'r', encoding='utf-8') as f_h:
|
||||
pb_color = 'green' if f_h.read().strip() == '1' else 'red'
|
||||
self.progressbar.configure(progress_color=pb_color)
|
||||
sleep(3)
|
||||
|
||||
def thread_it(self, func, *args):
|
||||
""" 将函数打包进线程 """
|
||||
@ -489,5 +490,11 @@ class App(customtkinter.CTk):
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
with open("./automatic_test/templates/heartbeat", "w", encoding='utf-8') as f_h:
|
||||
f_h.write('0')
|
||||
|
||||
aio = App()
|
||||
aio.net_detect = Thread(target=aio.detect_network)
|
||||
aio.net_detect.daemon = True
|
||||
aio.net_detect.start()
|
||||
aio.mainloop()
|
||||
|
@ -1,16 +1,19 @@
|
||||
import openapi
|
||||
|
||||
hr = openapi.hr
|
||||
hr = openapi.HmiRequest()
|
||||
|
||||
# 一、设置/检测机器人状态:
|
||||
# 1. 上电
|
||||
# 2. 软限位打开
|
||||
# 3. 示教器断开
|
||||
# 4. 操作模式
|
||||
# 4. 操作模式/机器人类型
|
||||
# 5. 控制器状态/工作任务控件/机器人动态
|
||||
|
||||
# 二、加载RL程序开始运行
|
||||
|
||||
# 1. 怎么触发急停
|
||||
# 2. 怎么恢复急停
|
||||
# 3. 怎么采集曲线
|
||||
# 4.
|
||||
|
||||
# 三、运行过程中,收集数据,并处理出结果
|
||||
|
||||
|
@ -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()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user