system.opc.readValue / Values is not reading

Hi All,

I’m using IGNITION 8.0.5 RC1
I have a script in Gateway Event Scripts that has to collect some tags and insert them inside the DB.
The script is the following:

if not initialChange:
	if newValue.getValue():
	
		Server = 'Ignition OPC UA Server'
		#opcPathTest = '[S1500]DB1002,STRING140.100' #Nome Test
		opcPathNCiclo = '[S1500]DB1005,DI8012.0' # Numero del ciclo 
		#Tag_N_Sample = '[S1500]DB1005,DI0.0' #campionamenti totali per il singolo ciclo ( per far un for mirato )
		TagPathsPressure = ['[S1500]DB1005,REAL%2.1f' % x for x in range(4,4008,4)]
		TagPathsTime = ['[S1500]DB1005,DI%2.1f' % x for x in range(4008,8012,4)]
		
		#NomeTest = system.opc.readValue(Server,opcPathTest).value
		NomeTest = system.tag.readBlocking(['[default]PLC/Esperimento/Name Test'])[0].value
		N_Ciclo = system.opc.readValue(Server,opcPathNCiclo).value
		#N_Sample =  system.opc.readValue(Server,Tag_N_Sample).value
		N_Sample = system.tag.readBlocking(['[default]PLC/Campionamenti/Impulsi TOT'])[0].value
		PressureValues = [x.value for x in system.opc.readValues(Server,TagPathsPressure)]
		TimeValues = [x.value for x in system.opc.readValues(Server,TagPathsTime)]
		
		Query = system.db.runPrepQuery('SELECT [ID] FROM [Test_Impulso] WHERE [Name] = ?',[NomeTest])
		ID_Test = Query[0][0]
		
		for j in range(0,N_Sample):
			stmt = 'INSERT INTO [ImpulsoToKeep]([ID_Test],[N_Ciclo],[Time],[Pressure]) VALUES (?,?,?,?)'
			system.db.runPrepUpdate(stmt,[ID_Test,N_Ciclo,TimeValues[j],PressureValues[j]])
		
		# Bit di HandShake
		system.tag.writeBlocking(['[default]PLC/Esperimento/Reset Impulsi'],[False])
		system.opc.writeValue(Server,'[S1500]DB1006,X14.4',0)

If I run the script inside the Script Console everything is done perfectly.
If it runs from the Gateway Event Script I received an error that says that it cannot insert NULL value inside the database, because this line PressureValues = [x.value for x in system.opc.readValues(Server,TagPathsPressure)] is returning an array of None value.

Any idea?

Put the tag provider on ALL of your tag paths.
Tag Event Scripts need to know what provider to issue the read call to.
[default] if using the default tag provider.

Sorry, but I don’t quite understand…
You are talking about Tag Event Script. but I have this script on Gateway Event Script, also the tag provider is specified on all the TAGs

your tag paths for opcPathNCiclo,TagPathsPressure, and TagPathsTime do not have the provider in them.

		Server = 'Ignition OPC UA Server'
		#opcPathTest = '[S1500]DB1002,STRING140.100' #Nome Test
		opcPathNCiclo = '[S1500]DB1005,DI8012.0' # Numero del ciclo 
		#Tag_N_Sample = '[S1500]DB1005,DI0.0' #campionamenti totali per il singolo ciclo ( per far un for mirato )
		TagPathsPressure = ['[S1500]DB1005,REAL%2.1f' % x for x in range(4,4008,4)]
		TagPathsTime = ['[S1500]DB1005,DI%2.1f' % x for x in range(4008,8012,4)]

There’s some confusion over terminology… try to avoid using the keyword ‘tag’ for OPC items, as they aren’t tags in Ignition. They may be pointing at what are called tags in the target device, but tags in Ignition are something else.

Anyways, for the system.opc.readValues() calls, you should not use that list comprehension to extract .value unless you can handle None when your quality is bad. Consider logging the list returned by readValues() so you can inspect the quality codes to troubleshoot further.

1 Like

Sorry about the terminology @MMaynard, as @pturmel said the paths without Provider are OPC Items and not TAG.

About the issue, I’ll try what you suggest