Typecasting / coercion?

I’m trying to do the following in a project script:

def debugTest(): tester = system.tag.read("[Client]prevSt") tester=tester + 1 system.tag.write("[Client]prevSt",tester)

but I get:

[code]Traceback (most recent call last):
File “”, line 1, in
File “module:project.stateMachine”, line 17, in debugTest
TypeError: unsupported operand type(s) for +: ‘com.inductiveautomation.ignition.common.sqltags.BasicTagValue’ and ‘int’

[/code]

The help file speaks of the toInt command when looking to do typecasting. A bit of rearranging gives me:

def debugTest(): tester = system.tag.read("[Client]prevSt") intTester=toInt(tester) + 1 system.tag.write("[Client]prevSt",intTester)

Brilliant, yes?

No:

[code]Traceback (most recent call last):
File “”, line 1, in
File “module:project.stateMachine”, line 17, in debugTest
NameError: global name ‘toInt’ is not defined

[/code]

So how do I read a tag of type int, add one to it, and write it back from within a project script? This should be scripting 101, but I am at a loss.

Thanks!

Joe

The value you get back from system.tag.read is a “qualified value”, a structure that contains the value, quality, and timestamp. You need to access the value attribute before attempting to use it the way you are.

Hi,
Kevin is right. It should be like this.

def debugTest():
   tester = system.tag.read("[Client]prevSt").value
   tester=tester + 1
   system.tag.write("[Client]prevSt",tester)

Notice that the “value” property was used.