Readblocking help

Hello,

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.

paths6 = [ "[HighVol_Lower]NEQ/DINT1",
           "[HighVol_Lower]NEQ/DINT2" ]

ValuesPaths6 = system.tag.readBlocking(paths6)
current = ValuesPaths6[0].value
previous = ValuesPaths6[1].value

What am I doing wrong here? Please throw some light.

TIA

What do you mean by this? Are you getting an error when the tag change script executes or are the results not what you are expecting?

The script executes based on these two values not being equal and clearly the script does not seem to run because these values haven't been updated

You need to show your entire script.

There is nothing syntactially incorrect in the snipit that you included in the OP

2 Likes

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 say tag change script do you mean Tag Value Change Script (on the tag itself), or Gateway Tag Change Script (In the Project).

There are a number of things that I might change depending on the answer to that question.

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

if current != previous:
 ......
1 Like

Gateway tag change script. I monitor Cam_I_Data to run the script on a change

@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.

Thank you!

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.

1 Like

Ok, good, otherwise the database operations would not have been good.

  1. 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.

  2. 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?

  3. 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).

  4. Do not import packages inside of functions, especially if you're not using them.

  5. 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])
3 Likes

Thank you @lrose. It has already bitten me and keeps biting whenever I try stuff like this on the existing script lol

Point 2: I am writing a '0' to Cam Pass bit that's set in PLC and does some data moving.

Point 4,5: I am very new to Ignition and have to start learning more. What I am doing now is to support production.