I have a Tag change script where there are multiple individual tag readblocking statements and I am trying to group them together, but it doesn't seem to read.
Are you positive that the tag change script is being triggered and actually executing? If not I'd add some logging in to be sure.
Also, it would be helpful if you could share the entire tag change script. I don't see anything wrong with the snippet you shared, the issue you are having could be due to something else.
'''
current = system.tag.readBlocking('[HighVol_Lower]NEQ/Sta32_BarcodeDINT_Current')
previous = system.tag.readBlocking('[HighVol_Lower]NEQ/Sta32_CamStoredPrevious')
section = system.tag.readBlocking("[HighVol_Lower]User_Interface/Sta32_User/Layer_Insert")
section_pos = system.tag.readBlocking("[HighVol_Lower]User_Interface/Sta32_User/Layer_pos_Insert")
part_pos = system.tag.readBlocking("[HighVol_Lower]User_Interface/Sta32_User/Stack_pos_Insert")
pallet = system.tag.readBlocking('[HighVol_Lower]User_Interface/Sta32_User/PalletID_Insert')
'''
ID = system.tag.readBlocking("[HighVol_Lower]User_Interface/Sta32_User/DEMO_Serial")
sta = "32"
timestamp = system.tag.readBlocking("[HighVol_Lower]Time_Stamp")
paths6 = [ '[HighVol_Lower]NEQ/Sta32_BarcodeDINT_Current',
'[HighVol_Lower]NEQ/Sta32_CamStoredPrevious',
'[HighVol_Lower]User_Interface/Sta32_User/Layer_Insert',
'[HighVol_Lower]User_Interface/Sta32_User/Layer_pos_Insert',
'[HighVol_Lower]User_Interface/Sta32_User/Stack_pos_Insert',
'[HighVol_Lower]User_Interface/Sta32_User/PalletID_Insert']
ValuesPaths6 = system.tag.readBlocking(paths6)
current = ValuesPaths6[0].value
previous = ValuesPaths6[1].value
section = ValuesPaths6[2].value
section_pos = ValuesPaths6[3].value
part_pos = ValuesPaths6[4].value
pallet = ValuesPaths6[5].value
import time
if current[0].value != previous[0].value:
if current[0].value != 0:
start = system.tag.readBlocking('[HighVol_Lower]Bar Grade/Sta32_BarcodeGrade')
if start[0].value > 2:
system.tag.writeBlocking(['[HighVol_Lower]Start_Text/Sta32_Cam02_Pass'], [0])
barcode = system.tag.readBlocking('[HighVol_Lower]Camera_Data/Sta32Cam_I_Data')
if barcode[0].value[:16] > 0:
query = "SELECT COUNT(data) FROM barcodes_data WHERE data = ?"
count = system.db.runScalarPrepQuery(query, [barcode[0].value[:16]])
if count < 1:
Number_String = system.tag.readBlocking('[HighVol_Lower]Camera_Data/Sta32Cam_I_Data')
julian = Number_String[0].value[2:7]
StaNO = 32
query = "INSERT INTO barcodes_data(data, Julian_Date, Station) VALUES (?,?,?)"
system.db.runPrepUpdate(query, [barcode[0].value[:16], julian, StaNO])
system.tag.writeBlocking(['[HighVol_Lower]Script_Pass/Sta32_EntryScan_Complete'], [1])
So, I just commented out the readblocking group that I have issues with and ran with individual readblockings and it works. When I activate the readblocking group, the script doesn't run and return the last writeblocking bit that I monitor in PLC. @lrose@ryan.perretta
When you changed this to reading all the tags as a group you are pulling out the tags from the returned array of Qualified Values and pulling the value from the QV at the top here:
Then it seems you are doing it again in the first if statement here:
I suspect this would be causing some issues.
You will need to make some changes to the block of code beneath the grouped tag read to address this. In the example I provided I believe your if statement should read
@ryan.perretta That did the trick. It's the qualified values being called again causing issues.
I have lot of other script down below using syntax like 'part_pos[0].value'. I have to figure out a way to clean up assuming this group readblocking saves lot of script execution time.
Basically, anywhere you use these variables that you define at the top you can drop the [0].value off the end because you have already taken that step when initializing them.
Ok, good, otherwise the database operations would not have been good.
It appears you may be mixing tabs and spaces. Technically this is allowed so long as it is syntactically consitent, however, it will bite you when you least expect it so it's best to choose one and go with that.
You should do all of your reads at the start of the script, and all of your writes at the end. Which is perhpas what you're working towards. There are some arguments for having separate writes, when you need. I would ask, is there any reason you would want to write the Pass, without writing Complete?
You can use a list comprehension to extract the values from the List of Qualified Values, and then unpack those directly into variables. This will make things more readable (IMO).
Do not import packages inside of functions, especially if you're not using them.
You should move this script to a Library Function, so you can avoid the Legacy Scoping issues that come with Gateway Event Scripts.
Here is how I would write your script:
readPaths = [ '[HighVol_Lower]User_Interface/Sta32_User/DEMO_Serial',
'[HighVol_Lower]NEQ/Sta32_BarcodeDINT_Current',
'[HighVol_Lower]NEQ/Sta32_CamStoredPrevious',
'[HighVol_Lower]User_Interface/Sta32_User/Layer_Insert',
'[HighVol_Lower]User_Interface/Sta32_User/Layer_pos_Insert',
'[HighVol_Lower]User_Interface/Sta32_User/Stack_pos_Insert',
'[HighVol_Lower]User_Interface/Sta32_User/PalletID_Insert',
'[HighVol_Lower]Time_Stamp',
'[HighVol_Lower]Bar Grade/Sta32_BarcodeGrade',
'[HighVol_Lower]Camera_Data/Sta32Cam_I_Data']
userID,barcodeCur,storedPrev,section,sectionPos,partPos,pallet,timestamp,start,barcode = [qv.value for qv in system.tag.readBlocking(readPaths)]
if barcodeCur != storedPrev:
if barcodeCur:
if start > 2:
system.tag.writeBlocking(['[HighVol_Lower]Start_Text/Sta32_Cam02_Pass'], [0])
if barcode[:16] > 0:
query = "SELECT COUNT(data) FROM barcodes_data WHERE data = ?"
count = system.db.runScalarPrepQuery(query, [barcode[:16]])
if count < 1:
julian = barcode[2:7]
StaNO = 32
query = "INSERT INTO barcodes_data(data, Julian_Date, Station) VALUES (?,?,?)"
system.db.runPrepUpdate(query, [barcode[:16], julian, StaNO])
system.tag.writeBlocking(['[HighVol_Lower]Script_Pass/Sta32_EntryScan_Complete'], [1])