[Question] Vision System Flags not working (?) with Client Event Startup and Shutdown Scripts

I created a project script the adds a row to a dataset and sets the columns text…this works fine, I tested it with a button in the Designer in Preview mode and from a Client window via a button script. The script name is addVersionNote (projectArea, topic, notes) and is provided at the bottom of this post.

I created project script isFlagTrue(flagName) (also shown at the bottom of the post) that returns a Boolean with for specific system flag. This works, I tested it in Designer in Preview mode and from a Client window via a button script.

I changed my button script to:

if sysUtil.isFlagTrue('Designer'):
	versioning.addVersionNote('button script', 'Designer', 'if sysUtil.isFlagTrue(Designer):')
if sysUtil.isFlagTrue('Client'):
	versioning.addVersionNote('button script', 'client', 'if sysUtil.isFlagTrue(Client):')

This also works fine, I tested it in Designer in Preview mode and from a Client window via a button script.

I copied the first ‘if’ (checking if the Designer is running) and pasted it in the Client Event Startup and Shutdown script area. When I start up and shut down the Designer my dataset doesn’t get a new row…its as if the first bit in the SystemFlags integer is zero.

Is there some special conditions on how the SystemFlag bits are set? Perhaps only after startup scripts are executed? What about when shutting down?

As usual, thanking you helpful people in advance.
Regards,
Ted.

def addVersionNote (projectArea, topic, notes):
	# =================================================================================================================
	# Adds a new version note row to the beginning of the version information dataset.
	# =================================================================================================================
	# Get the current dataset from the memory tag.  Remember, .readBlocking returns a List.
	currentDataSet = system.tag.readBlocking('[gw1]_Project Version Information/versionDataSet')[0].value
	# Create the data for the new row and make the row.
	date = system.date.now()
	projectName = system.tag.readBlocking('[System]Client/System/ProjectName')[0].value
	projectVersion = system.tag.readBlocking('[gw1]_Project Version Information/versionString')[0].value
	userName = system.tag.readBlocking('[System]Client/User/Username')[0].value
	newRow = [[date, projectName, projectVersion, userName, projectArea, topic, notes]]
	# Add the row to the dataset getting the new dataset.
	newDataSet = system.dataset.addRows(currentDataSet, 0, newRow)
	# Write the new dataset to the memory tag (because we need to remember it :)
	system.tag.writeBlocking('[gw1]_Project Version Information/versionDataSet', newDataSet)




def isFlagTrue(flagName):
	# =================================================================================================================
	# Find out if one to the system.util.getSystemFlags() flags is true..or not :) 
	# =================================================================================================================
	"""
	system.util.getSystemFlags() returns an integer that represents a bit field containing information about the
	currently running system.  Each bit corresponds to a specific flag as defined in the bitmask below. The integer
	return will be a total of all of the bits that are currently active. Note that tag[System]Client/System/SystemFlags
	contains the same value.
		Flag			Description / Bit Value
		====		=======================																
		Designer		Set if running in the Designer / 1
		Preview		Set if running in the Designer, and the Designer is in preview mode / 2
		Client		Set if running as a Client / 4
		Webstart		Set if running as a Client in Web Start mode / 8
		Applet		Set if running as a Client in Applet mode / 16
		Fullscreen	Set if running as a Client in full screen mode / 32
		SSL			Set if communication to the Gateway is encrypted with SSL / 64
		Mobile		Set if currently running a mobile-launched client / 128
	"""
	retVal = False
	flagList = []
	flags = system.util.getSystemFlags()
	for i in range(7,-1,-1):
		flagList.insert(0, flags >> i & 1)
	
	if (flagName == 'Designer' and (flagList[0] == 1)):
		retVal = True
	elif (flagName == 'Preview'and (flagList[1] == 1)):
		retVal = True
	elif (flagName == 'Client' and (flagList[2] == 1)):
		retVal = True
	elif (flagName == 'Webstart' and (flagList[3] == 1)):
		retVal = True
	elif (flagName == 'Applet' and (flagList[4] == 1)):
		retVal = True
	elif (flagName == 'Fullscreen' and (flagList[5] == 1)):
		retVal = True
	elif (flagName == 'SSL' and (flagList[6] == 1)):
		retVal = True
	elif (flagName == 'Mobile' and (flagList[7] == 1)):
		retVal = True
	
	return retVal

System flags should be set well before your startup script is executed. What do you get in the logs if you print the value of the flags?

@PGriffith , Hi Paul.
I added a logger and the print command to my isFlagTrue(flagName) script. This script is called on client startup, shutdown and when I press me test button. The Designer console and Diagnostics Logs show the flags values when I press the button. There isn’t anything in the client console and client logger when I start the designer. There’s also nothing in there for a shutdown…not surprising…the client logs are persisted from after a shutdown. Can the client log to the gateway? What next?

The designer is not a client. It doesn’t run those scripts. Run a real client to test that functionality.

@pturmel Hello again Phil.

Ahhh! I thought the Designer acted like a client, my mistake! I think I got that idea because tags are always updating ( I can see real PLC data in the tag browser) and Design behaves like a Client in preview mode. An of course just the name “Client Event Scripts” should have clued me in. Now I’m wishing there were Designer Event Scripts :wink: :thinking:

I guess I can close this thread and call it “Solved, sort of, what I was trying to do can’t be done.”.

Thanks again.
Regards,
Ted.

1 Like