Good day, I am trying to get a gateway script to execute via tag value change. I can get it to run when I use a boolean, but I need a memory tag that contains text to execute it. The tag gets changed when my RFID antenna reads the RFID tag.
Here is what I have so far, can anyone help me troubleshoot this?
Now heres the script:
import datetime
python_time = datetime.datetime.now()
sql_datetime = python_time.strftime('%Y-%m-%d %H:%M:%S')
#START of data parse for WS to YSF for ticket number
if system.tag.readBlocking("[default]RFID/Waste Scale/Green Light")[0].value == True:
TID = system.tag.readBlocking("[default]RFID/Waste Scale/TagID")[0].value #'A2163400' test tag number
dataset = system.db.runPrepQuery("SELECT TOP 1 * FROM WasteBarrelStatus WHERE TID = ? ORDER BY TIME DESC", [TID], 'IgnitionHud')
Time = sql_datetime #Time weight was recorded into table
Status = dataset[0][8]
MachineNum = dataset[0][6]
FinishLot = 'O5177I22' #dataset[0][4] test lot
Dept = dataset[0][5]
BarrelType = dataset[0][7]
PosNum = dataset[0][3]
TID = dataset[0][0]
BarrelNum = dataset[0][1]
ComponentNum = dataset[0][10]
Denier = dataset[0][11]
GrossWeight = int(system.tag.readBlocking("[default]RFID/Waste Scale/Scale Weight Lbs")[0].value) #200
#END of data parse for WS to YSF for ticket number
#START of WS to YSF for ticket number
if Status == 'newFill':
system.tag.writeBlocking("[default]RFID/Waste Scale/Red Light", 0)
wsdata = system.ws.runWebService("YSF/RecordInProcessQA",
None,
{
'recordInProcessDetailRequest': {
'userName': "IGNITION",
'department': Dept,
# x 'productionDate': "2023-05-23",
# 'shift': "J", #Use Start or completion shift
'machine': MachineNum,
# x 'employeeNumber': "",
'finishedLot': FinishLot,
# x 'scheduledLot': "",
# x 'component': "",
'reasonCode': "003", # Asp Waste Code = 003
# x 'positionDesc': "",
'buggyType': BarrelType,
# x 'buggyWeight': 0,
'cones': 0, # Leave as zero
'detailClass': "wast", # must be lower case
'grossWeight': GrossWeight,
# x 'netWeight': 0
}
})
Status = 'Weighed'
TicketNum = wsdata.getChild(0).toDict()['recordInProcessDetailResponse']['ticketNumber']
#END of WS to YSF for ticket number
system.db.runPrepUpdate("INSERT INTO WasteBarrelStatus (Time, Status, GrossWeight, MachineNum, FinishLot, Dept, BarrelType, PosNum, TID, BarrelNum, ComponentNum, Denier, TicketNum) Values(?,?,?,?,?,?,?,?,?,?,?,?,?)",[Time, Status, GrossWeight, MachineNum, FinishLot, Dept, BarrelType, PosNum, TID, BarrelNum, ComponentNum, Denier, TicketNum])
# else:
# system.tag.writeBlocking("[default]RFID/Waste Scale/Red Light", 1)
As stated before I can get this to run either with a boolean driving it or executing in the script console, just not when the tag value changes.