| Algorithm 1. OPC UA Server Development Algorithm. |
| Input: Request messages from the OPC UA clients/middleware module. |
| Output: OPC UA server endpoint URI and node credentials in UA binary format. |
| 1: function StartOPCUAServer() |
| 2: Construct server endpoint URI as opc.tcp://platform IP address:port |
| 3: Create address space and define nine objects with associated variable nodes. |
| 4: Start the OPC UA server with discoverable endpoint URI. |
| 5: while (server.is_listening) do |
| 6: Call Rand() function to get periodic simulated random numbers. |
| 7: Update variable nodes by node.set_value(variables) |
| 8: Wait 1000 ms for the next iteration. |
| 9: end while |
| 10: function Listening(Request) |
| 11: Listen continuously for the OPC UA client requests. |
| 12: while (Request.available) do |
| 13: Parse the NodeID, value, credentials from the request. |
| 14: root = server.get_root_node() |
| 15: Objects = len(root.get_children()) |
| 16: if (Request == “Read”) then |
| 17: for (i = 0; Objects; i++) do |
| 18: if (NodeID in root.get_children(i)) then |
| 19: Name = root.get_children()[i].get_browser_name() |
| 20: Value = root.get_children()[i].get_value() |
| 21: Concatenate = Name + ‘=’ + Value |
| 22: TagCredentials += Concatenate + ‘,’ |
| 23: end if |
| 24: end for |
| 25: Send TagCredentials to the client |
| 26: elif (Request == “Write”) then |
| 27: for (j = 0; Objects; j++) do |
| 28: if (NodeID in root.get_children(j)) then |
| 29: Write = root.get_node(NodeID).set_value(Value) |
| 30: end if |
| 31: end for |
| 32: end if |
| 33: end while |
| Begin |
| 34: Start a thread calling StartOPCUAServer() to run the OPC UA server. |
| 35: Start another thread calling Listening() to handle OPC UA client requests. |
| Finish |