Help with addTag

If I use the following in the Script Playground, my tag gets created as expected:

    system.tag.addTag(parentPath="MyServer OPC DA", name="Test Tag3", tagType="OPC", dataType="Int4")

If I use the same syntax in a Gateway Startup Script, the tag is not created and in the wrapper.log I get the error:

    "TypeError: addTag(): takes no keyword arguments"

So I change the syntax to be:

    system.tag.addTag(MyServer OPC DA", Test Tag4", OPC", Int4")

But then I get the error:

   "TypeError: addTag(): expected 8 args; got 4"

What are the other required arguments when running as a Gateway Startup Script?

Thanks,
Bob

Hi,

It looks like there might be a problem with the use of keyword invocation on the gateway scoped portion of this module (that is, the gateway side isn’t set up to use keywords). Try calling the function normally, with a parameter for each field. In other words, much like your second attempt, but will a value (possibly ‘null’) for each argument. Here is the signature:

void addTag(String parentPath, String name, TagType tagType, DataType dataType, AccessRightsType accessRights, boolean enabled, BasicTagValue value, MetaTagValue[] attributes, AlarmStateList alarmList)

Regards,

I tried with:

system.tag.addTag(“MyServer OPC DA”, “Test Tag4”, “OPC”, “Int4”, ‘null’, ‘null’, ‘null’, ‘null’)

And then got the error:

TypeError: addTag(): 3rd arg can’t be coerced to com.inductiveautomation.ignition.common.sqltags.model.types.TagType

So I have tried various options using “6” for a TagType parameter (as shown below), or even “property” among other things but I always get the same error.

system.tag.addTag(“MyServer OPC DA”, “Test Tag4”, “6”, “Int4”, ‘null’, ‘null’, ‘null’, ‘null’)
system.tag.addTag(“MyServer OPC DA”, “Test Tag4”, 6, “Int4”, ‘null’, ‘null’, ‘null’, ‘null’)
system.tag.addTag(“MyServer OPC DA”, “Test Tag4”, “Property”, “Int4”, ‘null’, ‘null’, ‘null’, ‘null’)

What is this parameter expecting?

Thanks,
Bob

Ah, I had that thought when I posted, but hoped that it would coerce from the string form. Ultimately, the module should be updated to support keywords - which in turn uses more permissive coercion. However, in the mean time, if you want to use it as is, you’ll need to import the Java type objects into Jython and use them like this:

from com.inductiveautomation.ignition.common.sqltags.model.types import TagType, DataType, AccessRightsType

system.tag.addTag("MyServer OPC DA", "Test Tag4", TagType.OPC, DataType.Int4, AccessRightsType.Read_Write, true, null, null, null)

Regards,

Has your last statement been tested? If it works then perhaps I need to download a newer version of Ignition.

So far I needed to change “true” to “True” and the Null to ‘null’, and it had an error with having 9 arguments when it only wanted 8 arguments. My latest statement is:

system.tag.addTag(“MyServer OPC DA”, “Test Tag4”, TagType.OPC, DataType.Int4, AccessRightsType.Read_Write, True, ‘null’, ‘null’)

But I still get the error:

TypeError: addTag(): 7th arg can’t be coerced to com.inductiveautomation.ignition.common.sqltags.BasicTagValue

Thanks,
Bob

Sorry, I was trying to post quickly yesterday, and guessed wrong on a few things. Here’s the correct form, which I’ve tested:

from com.inductiveautomation.ignition.common.sqltags.model.types import TagType, DataType, AccessRightsType system.tag.addTag("MyServer OPC DA", "Test Tag4", TagType.OPC, DataType.Int4, AccessRightsType.Read_Write, True, None, None)

In Jython, null = None. You’re passing it a string that happens to have the value ‘null’, which is why it can’t coerce.

Now, that said, I think it’s probably going to be easier if you wait until the module is updated to support keyword invocation, because if you’re trying to create OPC tags, you’ll need to pass in parameters for the tag properties needed, such as opc server, and opc item path, and right now that’s going to be really annoying to create. I’ll see if we can get it updated today or tomorrow.

Regards,

Yes, that worked, thank you.

Right now I am just trying to do some basic proof of concept on our end, so this is good for immediate need. Though I will be interested when the final changes for the module are complete.

Cheers!
Bob

We will have the fix by the end of the week. I will post back once the changes are made.

Ok, we have fixed the module in version 1.1.0. You can download it here:

viewtopic.php?f=88&t=8823

Hi. I have some problems with tag, created by system.tag.addTag().

I have done this code in my gateway timer script:

from com.inductiveautomation.ignition.common.sqltags.model.types import TagType, DataType, AccessRightsType

if (system.tag.exists("[default]Ignition OPC-UA Server/LastPPO") == 0):
	system.tag.addTag("Ignition OPC-UA Server", "LastPPO", TagType.OPC, DataType.Int4, AccessRightsType.Read_Write, True, None, None)
if (system.tag.exists("[default]Ignition OPC-UA Server/PrevPPO") == 0):
	system.tag.addTag("Ignition OPC-UA Server", "PrevPPO", TagType.OPC, DataType.Int4, AccessRightsType.Read_Write, True, None, None)

if (system.tag.write("[default]Ignition OPC-UA Server/PrevPPO",value)) == 1: 
        if (system.tag.write("[default]Ignition OPC-UA Server/LastPPO",PPO)) == 1:
		if system.tag.read("[default]Ignition OPC-UA Server/PrevPPO").value != None:
			.... some kind of code...

It is very possible, that I have done something wrong, because after series of this script’s works, i saw next in Ignition Designer’s OPC browser:

And, I saw next in a OPC servers statuse page:

What am I need to do, to remove empty server and to work properly with tag, created by gateway script?

The addTag function doesn’t add OPC servers. Did you add those OPC servers manually?