From cbc7fcd1be905e71b8e9ae82522f7b316153163f Mon Sep 17 00:00:00 2001 From: Dwi Swandhana Date: Sun, 1 Feb 2026 09:57:12 +0700 Subject: [PATCH] update --- listener/app.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/listener/app.py b/listener/app.py index 80b1575a..806ac5ce 100644 --- a/listener/app.py +++ b/listener/app.py @@ -779,7 +779,7 @@ def manage_vitek_port(config): logging.info(f"[{port_name}] Frame Start. Reading...") print(f"[{port_name}] Frame Start. Reading...") original_timeout = ser.timeout - ser.timeout = 1.5 + ser.timeout = 8 body = ser.read_until(b'\x03') ser.timeout = original_timeout @@ -790,9 +790,7 @@ def manage_vitek_port(config): if full_frame.endswith(b'\x03'): is_valid = True - elif b'\x1d' in full_frame[-10:]: - # Cek 10 karakter terakhir, ada GS gak? - # Log Anda: ...|zz|\x1de7 (GS ada di posisi -3) + elif b'\x1d' in full_frame[-20:]: is_valid = True logging.warning(f"[{port_name}] Frame tanpa ETX tapi ada Checksum. Menerima paksa...") print(f"[{port_name}] Frame tanpa ETX tapi ada Checksum. Menerima paksa...") @@ -832,7 +830,8 @@ def manage_vitek_port(config): else: # Kita masuk sini jika ser.in_waiting == 0 (Sepi) # Pastikan kolom flag diset di config - if flag_col: + if flag_col: + session = None try: session = SessionLocal() # Cari order yang belum dikirim @@ -903,14 +902,13 @@ def manage_vitek_port(config): logging.warning(f"[{port_name}] Alat Sibuk/Stuck. Kirim Force EOT.") print(f"[{port_name}] Alat Sibuk/Stuck. Kirim Force EOT.") ser.write(b'\x04') - time.sleep(1) - - session.close() + time.sleep(2.0) except Exception as e: logging.error(f"[{port_name}] Sending Error: {e}") print(f"[{port_name}] Sending Error: {e}") - if 'session' in locals(): session.close() + finally: + if session: session.close() # Sleep penting agar CPU tidak 100% saat idle time.sleep(0.1) @@ -918,6 +916,7 @@ def manage_vitek_port(config): except Exception as e: logging.critical(f"[{port_name}] Serial Crash: {e}") + print(f"[{port_name}] Serial Crash: {e}") time.sleep(5) # ==========================================