Nothing - this is a holdover from legacy scripting. You can call import system inside your defined function and run the system functions correctly. This (should) only apply to defined functions inside gateway event scripts.
This problem just cropped up for me on Ignition 8.0.2.
It’s easily solved by doing: import system
But I’ve never had to do it before today using several prior versions of Ignition
Gateway event scripts are working without it, as recently as 30 minutes ago but now it is suddenly needed? Very strange…
I have the same error with the gateway event script - Tag Change below :
import StringIO
import csv
import os
import ftplib
import sys
import system
from datetime import date
from datetime import datetime
from datetime import timedelta
if newValue.value==0:
sys.exit()
today=date.today() #Récupère la date du jour au format 'aaaa-mm-jj'
datejour= str(today).replace('-','') #Remplace les - par rien
yesterday=date.today() - timedelta(days=1) #Récupère la date de la veille
yesterday_jour=str(yesterday).replace('-','') #Remplace les - par rien
#print datejour,yesterday_jour
ftp = ftplib.FTP('myip')
ftp.login('user','password')
files = [] #créé liste vide
ftp.retrlines('NLST', files.append) #Récupère la liste des fichiers dans le dossier du FTP et alimente la liste
#print files
def callback(buf):
ftmp=system.file.getTempFile("data")
#print ftmp
f=open(ftmp, 'wb')
f.write(buf)
system.file.writeFile("C:\\TempTest\\NewTest.data",buf)
#print buf
dataIn= StringIO.StringIO(buf)
reader=csv.reader(dataIn, delimiter=';', quotechar="\"")
dataOut=[]
headers=["Poste","Nom","Date","DJU"]
for row in reader:
dataOut.append(row)
#print dataOut
date=datetime.strptime(dataOut[-1][2]+'000000','%Y%m%d%H%M%S')
dju=dataOut[-1][3].replace(',','.')
#print dataOut[-1][2], dju,date
f.close()
query="INSERT INTO dju (t_stamp,dju) VALUES (?,?)"
system.db.runPrepUpdate(query,[date,dju])
filename="DJU_"+yesterday_jour+".data"
#print filename
ftp.retrbinary('RETR '+filename, callback)
ftp.voidcmd('QUIT')
ftp.close()
Better, move all of that script to a project script module function. The legacy scoping issue where def doesn’t pick up the normal pre-defined imports only happens in the script in the event editor. It doesn’t happen in project script modules.