update
This commit is contained in:
+7
-8
@@ -779,7 +779,7 @@ def manage_vitek_port(config):
|
|||||||
logging.info(f"[{port_name}] Frame Start. Reading...")
|
logging.info(f"[{port_name}] Frame Start. Reading...")
|
||||||
print(f"[{port_name}] Frame Start. Reading...")
|
print(f"[{port_name}] Frame Start. Reading...")
|
||||||
original_timeout = ser.timeout
|
original_timeout = ser.timeout
|
||||||
ser.timeout = 1.5
|
ser.timeout = 8
|
||||||
body = ser.read_until(b'\x03')
|
body = ser.read_until(b'\x03')
|
||||||
ser.timeout = original_timeout
|
ser.timeout = original_timeout
|
||||||
|
|
||||||
@@ -790,9 +790,7 @@ def manage_vitek_port(config):
|
|||||||
|
|
||||||
if full_frame.endswith(b'\x03'):
|
if full_frame.endswith(b'\x03'):
|
||||||
is_valid = True
|
is_valid = True
|
||||||
elif b'\x1d' in full_frame[-10:]:
|
elif b'\x1d' in full_frame[-20:]:
|
||||||
# Cek 10 karakter terakhir, ada GS gak?
|
|
||||||
# Log Anda: ...|zz|\x1de7 (GS ada di posisi -3)
|
|
||||||
is_valid = True
|
is_valid = True
|
||||||
logging.warning(f"[{port_name}] Frame tanpa ETX tapi ada Checksum. Menerima paksa...")
|
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...")
|
print(f"[{port_name}] Frame tanpa ETX tapi ada Checksum. Menerima paksa...")
|
||||||
@@ -833,6 +831,7 @@ def manage_vitek_port(config):
|
|||||||
# Kita masuk sini jika ser.in_waiting == 0 (Sepi)
|
# Kita masuk sini jika ser.in_waiting == 0 (Sepi)
|
||||||
# Pastikan kolom flag diset di config
|
# Pastikan kolom flag diset di config
|
||||||
if flag_col:
|
if flag_col:
|
||||||
|
session = None
|
||||||
try:
|
try:
|
||||||
session = SessionLocal()
|
session = SessionLocal()
|
||||||
# Cari order yang belum dikirim
|
# 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.")
|
logging.warning(f"[{port_name}] Alat Sibuk/Stuck. Kirim Force EOT.")
|
||||||
print(f"[{port_name}] Alat Sibuk/Stuck. Kirim Force EOT.")
|
print(f"[{port_name}] Alat Sibuk/Stuck. Kirim Force EOT.")
|
||||||
ser.write(b'\x04')
|
ser.write(b'\x04')
|
||||||
time.sleep(1)
|
time.sleep(2.0)
|
||||||
|
|
||||||
session.close()
|
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error(f"[{port_name}] Sending Error: {e}")
|
logging.error(f"[{port_name}] Sending Error: {e}")
|
||||||
print(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
|
# Sleep penting agar CPU tidak 100% saat idle
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
@@ -918,6 +916,7 @@ def manage_vitek_port(config):
|
|||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.critical(f"[{port_name}] Serial Crash: {e}")
|
logging.critical(f"[{port_name}] Serial Crash: {e}")
|
||||||
|
print(f"[{port_name}] Serial Crash: {e}")
|
||||||
time.sleep(5)
|
time.sleep(5)
|
||||||
|
|
||||||
# ==========================================
|
# ==========================================
|
||||||
|
|||||||
Reference in New Issue
Block a user