-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStopGageForMastering.py
More file actions
57 lines (40 loc) · 2.42 KB
/
StopGageForMastering.py
File metadata and controls
57 lines (40 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
def logDebugMsg(msgID, message, msgSource):
params = {'msgID':msgID,
'message':message,
'msgSource':msgSource}
import system
system.db.runNamedQuery('Gages', 'Debug/LogMsg', params)
try:
if (initialChange == 1): # 1 means this script may have been 'saved' and that saving it generated the change event
quit()
pth = str(event.tagPath).replace('[default]', '')
pathAry = pth.split('/')
GageID = pathAry[0]
pathGageID = '[default]' + GageID + '/' + GageID
pathTotPart = pathGageID + '/Gage/Total Parts' # [default]G11/G11/Gage/Count/Batch Target
CurrentTick = int(event.getValue().value)
divRemain = divmod(CurrentTick, 10) # each 10th part
if (divRemain[1] != 0): # each 10th part
quit()
resultSet = system.db.runNamedQuery("Gages", "GageMaintenance/Get_Last_Tuneup_Tick", {"Gage":GageID})
# logDebugMsg('green_these_2', GageID, resultSet.getValueAt(0, 1))
LastMaintenanceTick = int(resultSet.getValueAt(0, 0))
if (LastMaintenanceTick == 0): # if this is the first time the Gage is reading this data
# Seed the table with the current (total part count) / Initialize the table with CurrentTick (total part count)
system.db.runNamedQuery("Gages", "GageMaintenance/Set_Last_Tuneup_Tick", {"Gage":GageID, "TotalParts":CurrentTick})
quit() # this was the first time the Gage read this data
partsThreshold = int(resultSet.getValueAt(0, 1)) # the number of parts ran through the Gage since the previous maintenance work / mes-lock (originally this number was 4000)
if (CurrentTick - LastMaintenanceTick >= partsThreshold):
mesLockPath = '[default]' + GageID + '/' + GageID + '/MES/MES Control Hold'
system.tag.writeBlocking([mesLockPath], [True])
# logDebugMsg('choca', GageID, 'MES Control Hold = True')
# write locking record to Gage_Locking
system.db.runNamedQuery("Gages", "GageLockingTable/Lock_Gage", {"Gage":GageID, "Lock_Type":Globals.lock_type_operator}) # update the lock details table
system.db.runNamedQuery("Gages", "GageMaintenance/Set_Last_Tuneup_Tick", {"Gage":GageID, "TotalParts":CurrentTick}) # update the counting logic / table
else:
system.db.runNamedQuery("Gages", "GageMaintenance/Set_Current_Tick", {"Gage":GageID, "TotalPartCount":CurrentTick})
except Exception as e:
eParams = {'msgID':'Gateway Script error',
'message':getattr(e, 'message', repr(e)),
'msgSource':'StopGageTuneupNeeded 3R9LAO'}
system.db.runNamedQuery("Gages", "Debug/LogMsg", eParams)