Shared script access to gateway

I am using version 7.9.13.
I have one gateway with four vision projects. The four projects are very similar and are all using the one gateway. One client is running on the same computer as the gateway computer. The other three projects (clients) will be running on three other computers within the same network. I am currently using a shared script which when called finds a specific folder within the D drive on the gateway computer, accesses a csv file and parses out data containing recipe information.
I currently have a file folder structure set up on the D drive as follows:

Here is some of the code running on the shared script relating to csv file parsing:

def LoadRecipeFromDNC():
	import system
	import app
	
	#turn off New Recipe
	system.tag.write("Cell/Control/New Recipe",0)

	#read in Forge Press Brass Tag Number
	btNum = system.tag.read("Cell/Maint/BrassTags/Forge_Press").value
	
	#prep the CSV file being used
#	filePath = "D:\DNC-in\WG-CSV.CSV"
	filePath = "D:\\DNC-in\\" + str(btNum) + "\\WG-CSV.CSV"
	file = system.file.readFileAsString(filePath)
	fileLines = file.strip().replace('"',"").replace("'","").split('\r\n')
	
	system.tag.write("Cell/commissioning/csvfile", filePath)

A csv file will be placed into one of the four folders based on the unique number of the folder names. Each project relates to one of the four unique numbers and the file path is dynamic by passing this number (referenced as btNum in scripting) to the Global shared script.

The project/client running on the gateway computer has already been tested relating to this code. My question is will the other three clients, which are all using the same Global shared script, be able to access its unique folder on the gateway computer when the script is called from one of the three projects/clients running outside of the gateway computer?

I’m thinking since its a global shared script that this will work for the other three? Would I have to setup this same folder structure on the three other individual computers? Would I have to allow any FTP permissions in order for this to work?

This will work as long as the script is called in the gateway scope. It will not work from a script console on the client machine for instance. It has to be a tag change event, or some other gateway event script.

Wouldn’t it be easier to loop over all the folders from a single gateway timer script, parse the contents, then write the results to an associated tag or run whatever logic you need on it?

import os

tagBasename = 'Cell/commissioning/csvfile/'
tagPaths = []
tagValues = []
inputDir = 'D:\\DNC-in\\'

for btNum in os.listdir(inputDir):
	filePath = inputDir + btNum + '\\WG-CSV.CSV'
	csv = system.file.readFileAsString(filePath)
	tagValues.append(file.strip().replace('"',"").replace("'","").split('\r\n'))
	tagPath.append(tagBasename + btNum)

system.tag.writeAll(tagPaths,tagValues)

Script modules exist in all scopes. The “shared” global isn’t a scope, it just means all projects and tags have access to them. It has no bearing on where the script executes. It executes in the scope from which it is called. To reliably be in gateway scope, this code should be called from a gateway message handler. And the files need to be accessible to the gateway service.

Running a designer and client on the same computer as the gateway has misled you. (I don’t recommend doing so with any gateway, other than Edge Panel edition.)

1 Like