Hello witman,
below the script that sometimes runs, sometimes does not:
from time import sleep
dbconn = system.tag.read("[~]TAN_Globals/IgnitionRuntimeConnection").value
if (currentValue.value == True and previousValue.value==False):
requested_project = system.tag.read("[.]in_projectnumber").value
while requested_project == 0:
requested_project = system.tag.read("[.]in_projectnumber").value#int(hex(system.tag.read("[.]in_projectnumber_test").value)[2:])
sleep(0.2)
requested_mould = 0 # = int(hex(system.tag.read("[.]in_projectnumber").value)[2:])
data = shared.T07_CONVEYOR.get_data_for_project(requested_project, mouldnumber = 0 )#get_data_for_project(requested_project,requested_mould)
word9 = shared.T07_CONVEYOR.conveyorize_word9(data[5],data[4],data[3])#conveyorize_word9(data[5],data[4],data[3])
result = 0
result += system.tag.write("[.]out_alloy",data[0])
result += system.tag.write("[.]out_wheeldiameter",shared.T07_CONVEYOR.to_conv_format(int(data[1])))
result += system.tag.write("[.]out_wheelheight",shared.T07_CONVEYOR.to_conv_format(int(data[2])))
result += system.tag.write("[.]out_wheeltype_template_diameterdrill",word9)
if result < 4:
#pass #TODO: raise an alarm! - writing data failed!
shared.T07_CONVEYOR.track_event('writing data failed')
else:
system.tag.write("[.]out_data_sent_correctly",True)
shared.T07_CONVEYOR.track_event('written data sent correctly')
str_sql_get_id = "SELECT machineid FROM TAN_MAC_CFG WHERE RTRIM(LTRIM(Description)) = (?)"
result = system.db.runPrepQuery(str_sql_get_id,[system.tag.read("[.]station_name").value],dbconn)
str_sql_insert = "INSERT INTO [T07_CONVEYOR_QTY]([Counter],[MachineID],[timestamp],[ShiftStartTS],[projectnumber],[mouldnumber]) VALUES ( (?),(?),SYSDATETIMEOFFSET(),(?),(?),(?) )"
args = [0,result[0][0],system.tag.read("TAN_Globals/MasterClock/ShiftStartTS").value,requested_project,requested_mould]
tx_insert = system.db.beginTransaction()
system.db.runPrepUpdate(str_sql_insert,args,dbconn,tx=tx_insert)
system.db.commitTransaction(tx_insert)
system.db.closeTransaction(tx_insert)
I know it calls external methods, e.g. shared.T07_CONVEYOR.conveyorize_word9(…). I am convinced these methods are flawless, they have been run multiple times with various parameters. Never failed.
Does this mean that when it fails it fails after writing something? If so, point us to the line where the last value that does work is written.
No - the whole code either goes through or does not go through at all… To me it looked like the event is not firing despite the fact the tag turned True.
Problem is currently solved by workaround - I am running the script not in valueChanged() in UDT, I rather run the script as gateway event script reacting to tag value change. After the re-design to gateway event script based on tag change, it is significantly better. The script wasn’t run properly only once out of approx. 30 attempts. Attempt means putting an item to production line, which effectively renders the in_ready_to_receive_data tag True (PLC says that).
The system resources can’t be the problem. If the script is fired, it takes less then 150ms from beginning to end (i know that, b/c I am logging events in the script to DB table).
I am however unhappy because I don’t know what is wrong with the UDT valueChanged() not firing. The tag screenshot is taken below:
Actually, I don’t know what does the icon next to the tag name mean.
Thank you for the effort, much appreciated.