diff --git a/app.py b/app.py index ffb4aa0..445ba9d 100644 --- a/app.py +++ b/app.py @@ -313,6 +313,16 @@ def runReadPLC(): logger.error("数据 读取&上传 异常:%s", traceback.print_exc()) 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__': # --- 运行方式一 --- @@ -327,6 +337,7 @@ if __name__ == '__main__': pool = eventlet.GreenPool() pool.spawn_n(runWebSocket) pool.spawn_n(runReadPLC) + pool.spawn_n(writePLC_heartbeat) pool.waitall() diff --git a/config/config.ini b/config/config.ini index 189f0ef..bb95694 100644 --- a/config/config.ini +++ b/config/config.ini @@ -4,17 +4,17 @@ track_num = 2 [log] log_path = ./logs -stdout_log_level = INFO -file_log_level = INFO +stdout_log_level = DEBUG +file_log_level = DEBUG [plc] -ip_address = 10.227.181.106 +ip_address = 192.168.1.150 slot = 0 timeout = 0.9 -interval_plc = 6000 +interval_plc = 2000 [upload] -upload_type = 1 +upload_type = 0 login_web_url = http://192.168.2.167:20004/api/blade-auth/oauth/token upload_pinch_coal_url = http://xxxx upload_gross_weight_url = http://xxxx diff --git a/service/DetectService.py b/service/DetectService.py index eb49f72..da0d938 100644 --- a/service/DetectService.py +++ b/service/DetectService.py @@ -253,6 +253,11 @@ def upload_load_type(loadingDict: dict): else: 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(): """ @@ -262,6 +267,7 @@ def interval_read_PLC_up_web(): global g_read_plc if g_read_plc is None: g_read_plc = PLC_Tool(config.ip_address, config.slot) + interface = interfaceToWeb() login_result = "" diff --git a/service/interfaceToWeb.py b/service/interfaceToWeb.py index f43c77a..aa83d43 100644 --- a/service/interfaceToWeb.py +++ b/service/interfaceToWeb.py @@ -31,7 +31,7 @@ class interfaceToWeb: "grant_type": "password"} 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: jsonData = json.loads(res.text) @@ -68,7 +68,7 @@ class interfaceToWeb: "poundNo": track_name} 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: jsonData = json.loads(res.text) @@ -108,7 +108,7 @@ class interfaceToWeb: "houseStatus": 4, "poundNo": track_name} 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: jsonData = json.loads(res.text) @@ -145,7 +145,7 @@ class interfaceToWeb: "houseStatus": house_status, "poundNo": track_name} 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: jsonData = json.loads(res.text) @@ -172,7 +172,7 @@ class interfaceToWeb: """ headers = {'Content-Type': 'application/json', 'blade-auth': self.token} 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: jsonData = json.loads(res.text) diff --git a/utils/ConnectPLC.py b/utils/ConnectPLC.py index 7942a21..c225892 100644 --- a/utils/ConnectPLC.py +++ b/utils/ConnectPLC.py @@ -8,7 +8,7 @@ logger = Log(stdout_log_level=logging.FATAL, fil_log_level=logging.FATAL).getLogger() 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.plcSlot = plcSlot self.timeOut = timeOut @@ -305,9 +305,9 @@ class PLC_Tool: """ connect_count: int = 0 try: - logger.debug("开始获取PLC时间") + # logger.debug("开始获取PLC时间") time = self.comm.GetPLCTime(raw) - logger.debug("获取PLC时间成功:%s", str(time)) + # logger.debug("获取PLC时间成功:%s", str(time)) return time except IOError as io_error: if connect_count > 0: