Add Multiple Omron NJ address using script

Hi All,
i need to add Omron Nj device and multiple address using script .
i tried using system.device.addDevice function . I want to add multiple address in tagMap . Can anyone tell me how to add multiple address in a single script?

i have attached the script with one address in tagprops below.

props = {
"hostName" : "10.0.0.1",
"tagMap" : "HOST\tNAME\tDATATYPE\tADDRESS\tCOMMENT\tTAGLINK\tRW\tPOU\n\tfoo\tUINT_BCD[0..1]\t\t\tTRUE\tR\t\n"
}

system.device.addDevice(deviceType = "com.inductiveautomation.omron.NjDriver",
deviceName = "nj",
deviceProps = props)

If you take the escaped tagpMap (with all the \t, \n etc) and unescape it, you can visualize more clearly that it is essentially a TSV (tab separated volume):

So, you just need to start the next line, by following the header format and pasting the first tag again.

If you like, you can use the unescape tool above to convert it to a formatted text document that is easier to read, edit it and convert it back:

|HOST|NAME|DATATYPE|ADDRESS|COMMENT|TAGLINK|RW|POU|
|---|---|---|---|---|---|---|---|
||foo|UINT_BCD[0..1]|||TRUE|R||
||bar|UINT_BCD[0..2]|||TRUE|R||

1 Like

hi,
The script was working when i try to create one address in omron NJ
But when i try to create multiple tag address in a dictionary it is not working.

The reason is TSV is getting changed when i pass through a dictionary. I have attached the script and result for your reference.

a="HOST\\tNAME\\tDATATYPE\\tADDRESS\\tCOMMENT\\tTAGLINK\\tRW\\tPOU\\n"
dict={"k1":["foo","UINT_BCD[0..1]","TRUE","R"],
      "K2":["poo","UINT_BCD[0..1]","TRUE","R"]
      }
c=[   ]
for k, v in dict.items():
    b=r"\t"+str(v[0])+ r"\t" +str(v[1])+ r"\t\t\t"+str(v[2])+r"\t"+str(v[3])+r"\t\n"
    c.append(b)

addstr="".join(c)
tagMap= str(a)+addstr
print tagMap

props = {
            "hostName" : "10.0.0.1",
            "tagMap" : tagMap
        }

print props

Output received:

HOST\tNAME\tDATATYPE\tADDRESS\tCOMMENT\tTAGLINK\tRW\tPOU\n\tfoo\tUINT_BCD[0..1]\t\t\tTRUE\tR\t\n\tpoo\tUINT_BCD[0..1]\t\t\tTRUE\tR\t\n
{'hostName': '10.0.0.1', 'tagMap':

'HOST\\tNAME\\tDATATYPE\\tADDRESS\\tCOMMENT\\tTAGLINK\\tRW\\tPOU\\n\tfoo\\tUINT_BCD[0..1]\\t\\t\\tTRUE\\tR\\t\\n\\tpoo\\tUINT_BCD[0..1]\\t\\t\\tTRUE\\tR\\t\\n'}

The problem is when TSV format is passed in dictionary the single \ is changed to \\.
this is the reason the address is not created in gateway, when directly mentioning the format in string it is created.

it would be great if someone gives solution.
Thanks in advance.

You can remove the double backslashes in your headers (variable a) and the raw prefix "r" for everything after b=

You might also like to use the string formatting to make it more readible.

# Iterate over the dictionary and format the strings
for k, v in dict.items():
    b = "\t%s\t%s\t\t\t%s\t%s\t\n" % (str(v[0]), str(v[1]), str(v[2]), str(v[3]))
    c.append(b)

Also, I would be avoid using dict as variable name, as it is a built-in python function, and it is being re-assigned in your code.

1 Like