generated from zhangwei/Train_Identify
同PLC的通讯改为两条长连接,分别读写。本次优化部分
This commit is contained in:
parent
3d4b918a93
commit
23d0de4e38
11
app.py
11
app.py
|
|
@ -313,6 +313,16 @@ def runReadPLC():
|
||||||
logger.error("数据 读取&上传 异常:%s", traceback.print_exc())
|
logger.error("数据 读取&上传 异常:%s", traceback.print_exc())
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
def writePLC_heartbeat():
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
detect.writePLC_heartbeat()
|
||||||
|
except Exception as e:
|
||||||
|
logger.error("心跳(PLC时间读取)数据 读取&上传 异常:%s", traceback.print_exc())
|
||||||
|
continue
|
||||||
|
finally:
|
||||||
|
time.sleep(30)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
# --- 运行方式一 ---
|
# --- 运行方式一 ---
|
||||||
|
|
@ -327,6 +337,7 @@ if __name__ == '__main__':
|
||||||
pool = eventlet.GreenPool()
|
pool = eventlet.GreenPool()
|
||||||
pool.spawn_n(runWebSocket)
|
pool.spawn_n(runWebSocket)
|
||||||
pool.spawn_n(runReadPLC)
|
pool.spawn_n(runReadPLC)
|
||||||
|
pool.spawn_n(writePLC_heartbeat)
|
||||||
pool.waitall()
|
pool.waitall()
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,17 +4,17 @@ track_num = 2
|
||||||
|
|
||||||
[log]
|
[log]
|
||||||
log_path = ./logs
|
log_path = ./logs
|
||||||
stdout_log_level = INFO
|
stdout_log_level = DEBUG
|
||||||
file_log_level = INFO
|
file_log_level = DEBUG
|
||||||
|
|
||||||
[plc]
|
[plc]
|
||||||
ip_address = 10.227.181.106
|
ip_address = 192.168.1.150
|
||||||
slot = 0
|
slot = 0
|
||||||
timeout = 0.9
|
timeout = 0.9
|
||||||
interval_plc = 6000
|
interval_plc = 2000
|
||||||
|
|
||||||
[upload]
|
[upload]
|
||||||
upload_type = 1
|
upload_type = 0
|
||||||
login_web_url = http://192.168.2.167:20004/api/blade-auth/oauth/token
|
login_web_url = http://192.168.2.167:20004/api/blade-auth/oauth/token
|
||||||
upload_pinch_coal_url = http://xxxx
|
upload_pinch_coal_url = http://xxxx
|
||||||
upload_gross_weight_url = http://xxxx
|
upload_gross_weight_url = http://xxxx
|
||||||
|
|
|
||||||
|
|
@ -253,6 +253,11 @@ def upload_load_type(loadingDict: dict):
|
||||||
else:
|
else:
|
||||||
return -1, ""
|
return -1, ""
|
||||||
|
|
||||||
|
def writePLC_heartbeat():
|
||||||
|
global g_write_plc
|
||||||
|
if g_write_plc is None:
|
||||||
|
g_write_plc = PLC_Tool(config.ip_address, config.slot)
|
||||||
|
g_write_plc.get_plc_time()
|
||||||
|
|
||||||
def interval_read_PLC_up_web():
|
def interval_read_PLC_up_web():
|
||||||
"""
|
"""
|
||||||
|
|
@ -262,6 +267,7 @@ def interval_read_PLC_up_web():
|
||||||
global g_read_plc
|
global g_read_plc
|
||||||
if g_read_plc is None:
|
if g_read_plc is None:
|
||||||
g_read_plc = PLC_Tool(config.ip_address, config.slot)
|
g_read_plc = PLC_Tool(config.ip_address, config.slot)
|
||||||
|
|
||||||
interface = interfaceToWeb()
|
interface = interfaceToWeb()
|
||||||
|
|
||||||
login_result = ""
|
login_result = ""
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ class interfaceToWeb:
|
||||||
"grant_type": "password"}
|
"grant_type": "password"}
|
||||||
|
|
||||||
try:
|
try:
|
||||||
res = requests.post(url=url, headers=headers, data=data)
|
res = requests.post(url=url, headers=headers, data=data, timeout=1)
|
||||||
|
|
||||||
if res.status_code == requests.codes.ok:
|
if res.status_code == requests.codes.ok:
|
||||||
jsonData = json.loads(res.text)
|
jsonData = json.loads(res.text)
|
||||||
|
|
@ -68,7 +68,7 @@ class interfaceToWeb:
|
||||||
"poundNo": track_name}
|
"poundNo": track_name}
|
||||||
|
|
||||||
try:
|
try:
|
||||||
res = requests.post(url=url, headers=headers, json=data)
|
res = requests.post(url=url, headers=headers, json=data, timeout=1)
|
||||||
|
|
||||||
if res.status_code == requests.codes.ok:
|
if res.status_code == requests.codes.ok:
|
||||||
jsonData = json.loads(res.text)
|
jsonData = json.loads(res.text)
|
||||||
|
|
@ -108,7 +108,7 @@ class interfaceToWeb:
|
||||||
"houseStatus": 4,
|
"houseStatus": 4,
|
||||||
"poundNo": track_name}
|
"poundNo": track_name}
|
||||||
try:
|
try:
|
||||||
res = requests.post(url=url, headers=headers, json=data)
|
res = requests.post(url=url, headers=headers, json=data, timeout=1)
|
||||||
|
|
||||||
if res.status_code == requests.codes.ok:
|
if res.status_code == requests.codes.ok:
|
||||||
jsonData = json.loads(res.text)
|
jsonData = json.loads(res.text)
|
||||||
|
|
@ -145,7 +145,7 @@ class interfaceToWeb:
|
||||||
"houseStatus": house_status,
|
"houseStatus": house_status,
|
||||||
"poundNo": track_name}
|
"poundNo": track_name}
|
||||||
try:
|
try:
|
||||||
res = requests.post(url=url, headers=headers, json=data)
|
res = requests.post(url=url, headers=headers, json=data, timeout=1)
|
||||||
|
|
||||||
if res.status_code == requests.codes.ok:
|
if res.status_code == requests.codes.ok:
|
||||||
jsonData = json.loads(res.text)
|
jsonData = json.loads(res.text)
|
||||||
|
|
@ -172,7 +172,7 @@ class interfaceToWeb:
|
||||||
"""
|
"""
|
||||||
headers = {'Content-Type': 'application/json', 'blade-auth': self.token}
|
headers = {'Content-Type': 'application/json', 'blade-auth': self.token}
|
||||||
try:
|
try:
|
||||||
res = requests.post(url=url, headers=headers, json=data)
|
res = requests.post(url=url, headers=headers, json=data, timeout=1)
|
||||||
|
|
||||||
if res.status_code == requests.codes.ok:
|
if res.status_code == requests.codes.ok:
|
||||||
jsonData = json.loads(res.text)
|
jsonData = json.loads(res.text)
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ logger = Log(stdout_log_level=logging.FATAL,
|
||||||
fil_log_level=logging.FATAL).getLogger()
|
fil_log_level=logging.FATAL).getLogger()
|
||||||
|
|
||||||
class PLC_Tool:
|
class PLC_Tool:
|
||||||
def __init__(self, plcIp: str, plcSlot: int = 0, timeOut: float = 1):
|
def __init__(self, plcIp: str, plcSlot: int = 0, timeOut: float = 2):
|
||||||
self.plcIp = plcIp
|
self.plcIp = plcIp
|
||||||
self.plcSlot = plcSlot
|
self.plcSlot = plcSlot
|
||||||
self.timeOut = timeOut
|
self.timeOut = timeOut
|
||||||
|
|
@ -305,9 +305,9 @@ class PLC_Tool:
|
||||||
"""
|
"""
|
||||||
connect_count: int = 0
|
connect_count: int = 0
|
||||||
try:
|
try:
|
||||||
logger.debug("开始获取PLC时间")
|
# logger.debug("开始获取PLC时间")
|
||||||
time = self.comm.GetPLCTime(raw)
|
time = self.comm.GetPLCTime(raw)
|
||||||
logger.debug("获取PLC时间成功:%s", str(time))
|
# logger.debug("获取PLC时间成功:%s", str(time))
|
||||||
return time
|
return time
|
||||||
except IOError as io_error:
|
except IOError as io_error:
|
||||||
if connect_count > 0:
|
if connect_count > 0:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue