127.0.0.1
parent
9bf754273a
commit
4b26c2963b
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"api": {
|
"api": {
|
||||||
"base_url": "http://localhost:5000",
|
"base_url": "http://127.0.0.1:5000",
|
||||||
"description": "后端API服务地址,例如:http://localhost:5000 或 http://192.168.1.100:5000"
|
"description": "后端API服务地址,例如:http://localhost:5000 或 http://192.168.1.100:5000"
|
||||||
},
|
},
|
||||||
"wrench": {
|
"wrench": {
|
||||||
|
|
@ -21,7 +21,7 @@
|
||||||
"description": "延时配置(秒):wrench_init=扳手初始化延时, param_set=参数设置延时, retry=重试延时, bolt_complete=螺栓完成延时, status_check_interval=状态检测间隔"
|
"description": "延时配置(秒):wrench_init=扳手初始化延时, param_set=参数设置延时, retry=重试延时, bolt_complete=螺栓完成延时, status_check_interval=状态检测间隔"
|
||||||
},
|
},
|
||||||
"test_mode": {
|
"test_mode": {
|
||||||
"enabled": true,
|
"enabled": false,
|
||||||
"description": "测试模式:失败也算成功,用于无钉子测试"
|
"description": "测试模式:失败也算成功,用于无钉子测试"
|
||||||
},
|
},
|
||||||
"bolt_default_config": {
|
"bolt_default_config": {
|
||||||
|
|
|
||||||
|
|
@ -55,6 +55,9 @@ class WrenchGUI:
|
||||||
self.api_base_url = self.load_api_config()
|
self.api_base_url = self.load_api_config()
|
||||||
self.poll_interval = 3 # 轮询间隔(秒)
|
self.poll_interval = 3 # 轮询间隔(秒)
|
||||||
|
|
||||||
|
# 创建Session复用连接
|
||||||
|
self.session = requests.Session()
|
||||||
|
|
||||||
# 数据
|
# 数据
|
||||||
self.work_order = None
|
self.work_order = None
|
||||||
self.current_bolt_index = 0
|
self.current_bolt_index = 0
|
||||||
|
|
@ -501,7 +504,7 @@ class WrenchGUI:
|
||||||
|
|
||||||
def load_api_config(self):
|
def load_api_config(self):
|
||||||
"""从配置文件读取API地址,如果没有则使用默认值"""
|
"""从配置文件读取API地址,如果没有则使用默认值"""
|
||||||
default_url = "http://localhost:5000/api"
|
default_url = "http://127.0.0.1:5000/api"
|
||||||
try:
|
try:
|
||||||
config_path = self.get_config_path()
|
config_path = self.get_config_path()
|
||||||
if os.path.exists(config_path):
|
if os.path.exists(config_path):
|
||||||
|
|
@ -551,8 +554,12 @@ class WrenchGUI:
|
||||||
"""后台线程查询工单"""
|
"""后台线程查询工单"""
|
||||||
try:
|
try:
|
||||||
url = f"{self.api_base_url}/work-orders"
|
url = f"{self.api_base_url}/work-orders"
|
||||||
response = requests.get(url, timeout=10)
|
import time
|
||||||
|
|
||||||
|
start = time.time()
|
||||||
|
print("开始查询工单:", time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(start)),self.api_base_url)
|
||||||
|
response = self.session.get(url, timeout=10)
|
||||||
|
print("总耗时:", time.time() - start)
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
data = response.json()
|
data = response.json()
|
||||||
if data.get("success"):
|
if data.get("success"):
|
||||||
|
|
@ -659,7 +666,7 @@ class WrenchGUI:
|
||||||
while self.is_polling:
|
while self.is_polling:
|
||||||
try:
|
try:
|
||||||
url = f"{self.api_base_url}/work-orders"
|
url = f"{self.api_base_url}/work-orders"
|
||||||
response = requests.get(url, timeout=10)
|
response = self.session.get(url, timeout=10)
|
||||||
|
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
data = response.json()
|
data = response.json()
|
||||||
|
|
@ -774,7 +781,7 @@ class WrenchGUI:
|
||||||
"process_id": process_id,
|
"process_id": process_id,
|
||||||
"operator": operator
|
"operator": operator
|
||||||
}
|
}
|
||||||
response = requests.post(url, json=data, timeout=2)
|
response = self.session.post(url, json=data, timeout=2)
|
||||||
|
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
result = response.json()
|
result = response.json()
|
||||||
|
|
@ -823,7 +830,7 @@ class WrenchGUI:
|
||||||
try:
|
try:
|
||||||
url = f"{self.api_base_url}/work-orders/unclaim"
|
url = f"{self.api_base_url}/work-orders/unclaim"
|
||||||
data = {"trace_id": trace_id, "process_id": process_id}
|
data = {"trace_id": trace_id, "process_id": process_id}
|
||||||
response = requests.post(url, json=data, timeout=2)
|
response = self.session.post(url, json=data, timeout=2)
|
||||||
|
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
result = response.json()
|
result = response.json()
|
||||||
|
|
@ -863,7 +870,7 @@ class WrenchGUI:
|
||||||
try:
|
try:
|
||||||
url = f"{self.api_base_url}/work-orders/delete"
|
url = f"{self.api_base_url}/work-orders/delete"
|
||||||
data = {"trace_id": trace_id, "process_id": process_id}
|
data = {"trace_id": trace_id, "process_id": process_id}
|
||||||
response = requests.post(url, json=data, timeout=2)
|
response = self.session.post(url, json=data, timeout=2)
|
||||||
|
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
result = response.json()
|
result = response.json()
|
||||||
|
|
@ -1203,7 +1210,7 @@ class WrenchGUI:
|
||||||
print(f" device_name: {device_name}")
|
print(f" device_name: {device_name}")
|
||||||
print(f" bolts数量: {len(bolt_results)}")
|
print(f" bolts数量: {len(bolt_results)}")
|
||||||
|
|
||||||
response = requests.post(url, json=data, timeout=10)
|
response = self.session.post(url, json=data, timeout=10)
|
||||||
|
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
result = response.json()
|
result = response.json()
|
||||||
|
|
@ -1253,7 +1260,7 @@ class WrenchGUI:
|
||||||
"""加载扳手设备列表"""
|
"""加载扳手设备列表"""
|
||||||
try:
|
try:
|
||||||
url = f"{self.api_base_url}/wrench-devices"
|
url = f"{self.api_base_url}/wrench-devices"
|
||||||
response = requests.get(url, timeout=5)
|
response = self.session.get(url, timeout=5)
|
||||||
|
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
data = response.json()
|
data = response.json()
|
||||||
|
|
@ -1312,7 +1319,7 @@ class WrenchGUI:
|
||||||
try:
|
try:
|
||||||
# 从后端获取设备列表
|
# 从后端获取设备列表
|
||||||
url = f"{self.api_base_url}/wrench-devices"
|
url = f"{self.api_base_url}/wrench-devices"
|
||||||
response = requests.get(url, timeout=5)
|
response = self.session.get(url, timeout=5)
|
||||||
|
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
data = response.json()
|
data = response.json()
|
||||||
|
|
@ -1394,7 +1401,7 @@ def main():
|
||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
url = f"{app.api_base_url}/work-orders/unclaim"
|
url = f"{app.api_base_url}/work-orders/unclaim"
|
||||||
requests.post(url, json={"trace_id": trace_id, "process_id": process_id}, timeout=1)
|
app.session.post(url, json={"trace_id": trace_id, "process_id": process_id}, timeout=1)
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
app.stop_polling()
|
app.stop_polling()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue