Documentation on system.opcua.addConnection/removeConnection?

I found in the nightly build summaries this:


2174: system.opcua.addConnection and system.opcua.removeConnection
New scripting functions for adding/removing OPC UA connections: system.opcua.addConnection and system.opcua.removeConnection.

I also updated the designer software. However, there is no help info to tell me what parameters it takes or how to use these functions.

1 Like

I can read the removeConnection image (2nd one), but I saved the first image and zoomed in and it is illegible.
Strike that, I downloaded it wrong. I can read both just fine.

I got my inside source on the documentation team to publish the pages, too :slight_smile:

1 Like

Thank you!

I am trying to run the function: system.opcua.addConnection
It is giving me an error that opcua is not an attribute of system.
I installed this nightly: from Tuesday. The change log said it was put into the nightlys a few days ago. Do I have to do an import or something to make this work. The version in the gateway just says: (Dev Version)

It’s only available in gateway scope. Where are you trying to run the script?

1 Like

From the project library. I guess I need to make this a gateway script then.

You can write it in a project library, that’s not a scope. It’s where you invoke it from that matters.


Yeah, I need to go make a gateway message handler. Thanks

I am attempting to use system.util.sendMessage to call a gateway scoped script on the gateway.
I have created a message script on the gateway called: addServer. I can see this in the script status page on the gateway:

**Project	                        Name	        Last Execution	Duration	Status**
AmetConferenceDemo	addServer	Never

I have a response from the call to sendMessage:

type=Gateway,project=AmetConferenceDemo,messageHandler=addServer,filterParams={userZones=, userRoles=Administrator, scope=G},isRequest=no,sendStatus=SENT

This seems to me to indicate it is trying to call the script. But the Last Execution of the script continues to be Never.
I set the security zones to be:
Any and Administrator
I also added:
Any and Any for testing.

I watched the video on sendMessage, but it only covers sending messages to the client. Is there some project permissions that need to be set for using sendMessage?

Here is the actual command:

resps = system.util.sendMessage(str(projectName), "addServer", payload, "G")

I also checked and RW is allowed to gateway in this project.

Found an error in call.

Exception while attempting to run Python function: Traceback (most recent call last): File "<MessageHandlerScript:AmetConferenceDemo/addServer >", line 18, in handleMessage TypeError: addConnection(): 4th arg can't be coerced to String 

It seems 4th arg is not a list, but a string.

		discUrl, [discUrl],
		secPolicy, secMode,

Changed discUrl to just a string

Yeah, that looks like a mistake in the manual. @Paul.Scott


Everything is working now. Woot!

Where is an appropriate place to provide feedback on the system.opcua.addConnection and system.opcua.removeConnection commands? They do work, but they don’t return anything to indicate failure or type of failure. I have seen 3 failure modes for addConnection so far: host does not exist, host exists and doesn’t have opcua server, server already exists in the opcua server list.

I think I can check for existence of the server in the list before hand, but the other failures are just a guess at this point.

Don’t those failures all throw exceptions you can catch in your calling code?

Now that I look at this closer I am not sure it failed at all. The host, no server, and no host conditions did in fact create entries. The entries are just faulted. I build a list and those entries are only active servers. So I was a bit confused. I actually like this behavior as we can pre-configure servers without them being online. The duplicate entry may have in fact created the same connection again. I just tested the duplicate connection again and I am not seeing any kind of message or fault in the gateway script log. So it doesn’t appear to be failing. So maybe none of these are failing. Interesting.

I should have read your first post a little more closely. The only one of your scenarios that should actually result in an error is trying to add a connection with a duplicate name.