Here is the script, as posted.
def valueChanged(tag, tagPath, previousValue, currentValue, initialChange, missedEvents):
if currentValue.value == True:
date = system.tag.readBlocking("[~]Program:MainProgram/RO/RO_1_/BATCH_DSCALE_DATE.value")[0].value
time = system.tag.readBlocking("[~]Program:MainProgram/RO/RO_1_/BATCH_DSCALE_TIME.value")[0].value
job = system.tag.readBlocking("[~]Program:MainProgram/RO/RO_1_/BATCH_DSCALE_BANO.value")[0].value
roaster = 1
item = system.tag.readBlocking("[~]Program:MainProgram/RO/RO_1_/BATCH_DSCALE/BATCH_DSCALE_1_.value")[0].value
destcheck = system.tag.readBlocking("[~]GA_STATUS_40_.value")[0].value
greenwt = system.tag.readBlocking("[~]Program:MainProgram/RO/RO_1_/BATCH_DSCALE/BATCH_DSCALE_3_.value")[0].value
processed = 0
destcheck = system.tag.readBlocking("[~]GA_STATUS_40_.value")[0].value
dest = ''
desttype = ''
roastwt = 0
while currentValue.value == True:
roastwt = system.tag.readBlocking("[~]Program:MainProgram/RO/RO_1_/BATCH_DSCALE/BATCH_DSCALE_4_.value")[0].value
if destcheck == 1:
desttype = "Silo"
dest = system.tag.readBlocking("[~]Program:MainProgram/RT_ROAST_AUTO_DEST.value")[0].value
if dest != 0 and roastwt > 15:
params = {'RoastDate': date, 'RoastTime': time, 'Job': job, 'Roaster': roaster, 'Item': item, 'Dest_Type': desttype, 'Dest': dest, 'Green_Wt': greenwt, 'Roast_Wt': roastwt, 'Processed': processed}
system.db.runNamedQuery("Plant", "Insert Record to Roaster Production", params)
break
else:
desttype = "Bag"
dest = system.tag.readBlocking("[~]R1_Bag_Count")[0].value
if dest != 0 and roastwt > 15:
params = {'RoastDate': date, 'RoastTime': time, 'Job': job, 'Roaster': roaster, 'Item': item, 'Dest_Type': desttype, 'Dest': dest, 'Green_Wt': greenwt, 'Roast_Wt': roastwt, 'Processed': processed}
system.db.runNamedQuery("Plant", "Insert Record to Roaster Production", params)
break
Should be something more like this, although personally I think this script is better suited in a Gateway Tag Change Event.
def valueChanged(tag, tagPath, previousValue, currentValue, initialChange, missedEvents):
if currentValue.value:
tagPaths = ["[~]Program:MainProgram/RO/RO_1_/BATCH_DSCALE_DATE",
"[~]Program:MainProgram/RO/RO_1_/BATCH_DSCALE_TIME",
"[~]Program:MainProgram/RO/RO_1_/BATCH_DSCALE_BANO",
"[~]Program:MainProgram/RO/RO_1_/BATCH_DSCALE/BATCH_DSCALE_1_",
"[~]Program:MainProgram/RO/RO_1_/BATCH_DSCALE/BATCH_DSCALE_3_",
"[~]GA_STATUS_40_",
"[~]Program:MainProgram/RO/RO_1_/BATCH_DSCALE/BATCH_DSCALE_4_",
"[~]Program:MainProgram/RT_ROAST_AUTO_DEST",
"[~]R1_Bag_Count"]
qVals = system.tag.readBlocking(tagPaths)
date = qVals[0].value
time = qVals[1].value
job = qVals[2].value
roaster = 1
item = qVals[3].value
destcheck = qVals[5].value
greenwt = qVals[4].value
processed = 0
destcheck = qVals[5].value
roastwt = qVals[6].value
if destcheck == 1:
desttype = "Silo"
dest = qVals[7].value
if dest != 0 and roastwt > 15:
params = {'RoastDate': date, 'RoastTime': time, 'Job': job, 'Roaster': roaster, 'Item': item, 'Dest_Type': desttype, 'Dest': dest, 'Green_Wt': greenwt, 'Roast_Wt': roastwt, 'Processed': processed}
system.db.runNamedQuery("Plant", "Insert Record to Roaster Production", params)
else:
desttype = "Bag"
dest = qVals[8].value
if dest != 0 and roastwt > 15:
params = {'RoastDate': date, 'RoastTime': time, 'Job': job, 'Roaster': roaster, 'Item': item, 'Dest_Type': desttype, 'Dest': dest, 'Green_Wt': greenwt, 'Roast_Wt': roastwt, 'Processed': processed}
system.db.runNamedQuery("Plant", "Insert Record to Roaster Production", params)