BNA8/.resources/0f529dd3b96ad8d11b38e1ee17111d89976750a3f44ad21352a708d2769be144
2025-08-18 15:23:02 +04:00

63 lines
2.3 KiB
Plaintext

################################################################
################################################################
## Version: 1.0 / Author: Dillon Uzar
##
## DESC: For use in WCS Sorting Lane Lookup & Recording
## WARN: Modifying code may cause system to function incorrectly
################################################################
################################################################
import time
#######################################################
#######################################################
#######################################################
#### Constants
#######################################################
# Logger:
LOG = system.util.logger("PE BreakCount Handler")
# For inserting data into database:
CONFIRM_INSERT_QUERY = "INSERT IGNORE INTO pe_history (lane_id,count) VALUES (?,?)"
#######################################################
#######################################################
#######################################################
#### Parsing Utils
#######################################################
def logTime(title, trackID, seconds):
millisec = round(seconds * 1000, 1)
if millisec > 4:
LOG.info("%s[ID=%s] took longer than expected (%sms to process)" % (title, trackID, millisec))
#######################################################
#######################################################
#######################################################
#### PLC Event Handling
#######################################################
def processBreak(laneID, count):
# This function handles confirm events, and logs the event in SQL
# Ensure ID is valid
if count > 0:
start_time = time.time()
# Log confirm event in SQL:
# Insert into Package History:
system.db.runPrepUpdate(CONFIRM_INSERT_QUERY, [laneID, count])
logTime("PE_BREAK[DB_INSERT]", laneID, time.time() - start_time)
def processBreakAsync(laneID, count):
# This function handles confirm events, and logs the event in SQL
# Ensure ID is valid
if count > 0:
def processConfirmInner():
start_time = time.time()
# Log confirm event in SQL:
# Insert into Package History:
system.db.runPrepUpdate(CONFIRM_INSERT_QUERY, [laneID, count])
logTime("PE_BREAK[DB_INSERT]", laneID, time.time() - start_time)
system.util.invokeAsynchronous(processConfirmInner)