I created a script to run a sql database query to insert data.
This script is supposed to run whenever a tag from the machine changes, basically the tag signals the process is finished, thus I try to capture some variables and send them to the database.
This script works if I put it under a button mouseclick event. but if I put it under a tag change event it does not work.
I’ve played with the tag change event, and unless I make my script super simple, it is not reliable.
By using my script however, it never runs, not even once have I been able to write to the data base.
My Script runs on value tag change from [Ignition-raspberrypi_edge]FILL_COMPLETE
Here is my script:
"complete = system.tag.getTagValue(’[Ignition-raspberrypi_edge]FILL_COMPLETE’)
batch_id = system.tag.read(’[Ignition-raspberrypi_edge]BATCH_ID’)
cont_num = system.tag.read(’[Ignition-raspberrypi_edge]Total_Containers’)
weight = system.tag.read(’[Ignition-raspberrypi_edge]Weight’)
target = system.tag.read(’[Ignition-raspberrypi_edge]Target_Weight’)
deviation = target.value - weight.value
date = system.date.now()
if complete == 1:
system.db.runPrepUpdate(“INSERT into BATCH_INFO (Batch_ID,Container_num,Weight,Deviation,Date_Time) VALUES(?,?,?,?,?)”, [batch_id.value,cont_num.value,weight.value,deviation,date.value])"