str(event.tagPath) throws error

I am trying to create a gateway On Change script and get an error with the following line:

[code]strTag = str(event.tagPath) # This line throws the error

if initialChange == 1:
str = str + “\r\nInitialized”
else:
lineNumber = 0
if strTag == “[PMIServer]L2/IndexAlarmBell”: lineNumber = 2
if strTag == “[PMIServer]L5/Alarms/Alarm_StrobeRedWinderIndexing”: lineNumber = 5
if strTag == “[PMIServer]L6/Alarms/L6_Alarm_StrobeRedWinderIndexing”: lineNumber = 6
if strTag == “[PMIServer]L7/L7_IndexMotorStarter”: lineNumber = 7
if strTag == “[PMIServer]L8/Alarms/Alarm_StrobeRedWinderIndexing”: lineNumber = 8
if strTag == “[PMIServer]IsraCart/bTestButton”: lineNumber = 99[/code]

[quote]11:40:40 AM TagChangeScriptManager Error executing tag change script: IsraVision/IndexOnChange

Traceback (most recent call last):
File “TagChangeScript:IsraVision/IndexOnChange”, line 3, in
TypeError: ‘unicode’ object is not callable

at org.python.core.PyException.fillInStackTrace(PyException.java:70)
at java.lang.Throwable.<init>(Throwable.java:181)
at java.lang.Exception.<init>(Unknown Source)
at java.lang.RuntimeException.<init>(Unknown Source)
at org.python.core.PyException.<init>(PyException.java:46)
at org.python.core.PyException.<init>(PyException.java:43)
at org.python.core.PyException.<init>(PyException.java:61)
at org.python.core.Py.TypeError(Py.java:235)
at org.python.core.PyObject.__call__(PyObject.java:316)
at org.python.core.PyObject.__call__(PyObject.java:387)
at org.python.core.PyObject.__call__(PyObject.java:391)
at org.python.pycode._pyx91.f$0(<TagChangeScript:IsraVision/IndexOnChange>:48)
at org.python.pycode._pyx91.call_function(<TagChangeScript:IsraVision/IndexOnChange>)
at org.python.core.PyTableCode.call(PyTableCode.java:165)
at org.python.core.PyCode.call(PyCode.java:18)
at org.python.core.Py.runCode(Py.java:1275)
at com.inductiveautomation.ignition.common.script.ScriptManager.runCode(ScriptManager.java:548)
at com.inductiveautomation.ignition.common.script.TagChangeScriptManager$TagChangeScriptHandler$Runner.run(TagChangeScriptManager.java:222)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)[/quote]

I followed the information from this post and in the manual.
http://inductiveautomation.com/forum/viewtopic.php?f=70&t=9360&hilit=event.tagPath

[quote=“Travis.Cox”]You can look at the tag’s name or tag path. Take a look at this page:

inductiveautomation.com/supp … cripts.htm

You can use event.tagPath.itemName or str(event.tagPath) in your script.[/quote]
Can you point me in the right direction here? I am not sure why it doesn’t work. I am using Ignition 7.5.6 and Java 6 update 31

Thanks,

Are you sure that line is causing the error? Have you posted the entire script? That doesn’t look like line 3 to me, which is where the error is supposed to be occurring.

I didn’t post the entire script because I am still writing and cleaning it up. Here is the whole thing.

[code]strStatus = system.tag.read("[PMIServer]IsraCart/strTestStatus")
str = strStatus.value
strTag = str(event.tagPath)
if len(str)>1500: str=""

if initialChange == 1: # value = 1 only when run for the first time after each save or gateway restart
str = str + “\r\nInitialized”
else:
lineNumber = 0
if strTag == “[PMIServer]L2/IndexAlarmBell”: lineNumber = 2
if strTag == “[PMIServer]L5/Alarms/Alarm_StrobeRedWinderIndexing”: lineNumber = 5
if strTag == “[PMIServer]L6/Alarms/L6_Alarm_StrobeRedWinderIndexing”: lineNumber = 6
if strTag == “[PMIServer]L7/L7_IndexMotorStarter”: lineNumber = 7
if strTag == “[PMIServer]L8/Alarms/Alarm_StrobeRedWinderIndexing”: lineNumber = 8
if strTag == “[PMIServer]IsraCart/bTestButton”: lineNumber = 99
str = str + “\r\ntagPath = %s,%d, button path = [PMIServer]IsraCart/bTestButton,%d” % (strTag,len(strTag),len("[PMIServer]IsraCart/bTestButton"))

str = str + "\r\nGateway Received tag change event for %s on Line %d" % (event.tagPath,lineNumber)
value = newValue.value
quality = newValue.quality
timestamp = newValue.timestamp
str =  str + "\r\nvalue=%s, quality=%s, timestamp=%s" %(value, quality, timestamp)
	
strLotQuery = "SELECT TOP 1 \
STR(OrderNumber) + '-' + LTRIM(STR(OrderLineNumber)) \
FROM CurrentIndexDetail \
WHERE ProductionLineNumber = %d \
ORDER BY CurrentIndexDetail_Timestamp desc" % (lineNumber)

isOnline = system.opc.readValue("KepServer_UA","ns=2:s=IsraVisionClient.IsraCart1._System._NoError")
str = str + "\r\nIsra Cart Online Status  = %s" %(isOnline.value)
if isOnline.value: # Proceed only if Isra Cart is Online
	# Check what line it is on
	onProdLine = system.opc.readValue("KepServer_UA","ns=2:s=IsraVisionClient.IsraCart1.Devices.[ComTunneller].IsraVision.Prod.This User Defined 1")
	str = str + "\r\nRunning on Line %s" %(onProdLine.value)
	# Compare to trigger
	if onProdLine == lineNumber:
		pass
	#if onProdLine.value == "2":
		#rollReset = system.opc.writeValue("KepServer_UA","ns=2:s=IsraVisionClient.IsraCart1.Devices.[ComTunneller].IsraVision.Control.Roll Reset",0)
		#if rollReset.isGood():
		#	str = str+"\r\nRoll successfully reset"
		#else:
		#	str = str+"\r\nError writing reset!"
	else:
		str = str+"\r\NO RESET! Cart is on Line %s, not Line %d"%(onProdLine,lineNumber)

system.tag.writeSynchronous("[PMIServer]IsraCart/strTestStatus",str + “\r\n”) [/code]

Well I had no problem using str() on event.tagPath in my quick test.

Anyways, your problem is almost certainly due to you assigning a string to a variable named ‘str’ immediately before then trying to use the built-in str() function, which is being shadowed by your variable named ‘str’. Stop using that name and everything should be ok.

You are absolutely correct! I created a duplicate On Change script and only added a few lines shown below and it worked. I then realized I was doing something wrong. After reading your post I renamed the “str” variable to something else and it worked. I usually use str to preface another variable name like “strMessage” but this time I was lazy and it cost me valuable time.

strTag = str(event.tagPath) lineNumber = 0 if strTag == "[PMIServer]L2/IndexAlarmBell": lineNumber = 2 if strTag == "[PMIServer]L5/Alarms/Alarm_StrobeRedWinderIndexing": lineNumber = 5 if strTag == "[PMIServer]L6/Alarms/L6_Alarm_StrobeRedWinderIndexing": lineNumber = 6 if strTag == "[PMIServer]L7/L7_IndexMotorStarter": lineNumber = 7 if strTag == "[PMIServer]L8/Alarms/Alarm_StrobeRedWinderIndexing": lineNumber = 8 if strTag == "[PMIServer]IsraCart/bTestButton": lineNumber = 99

Thank you!