Connecting a SCADA or HMI over OPC UA

The program in the simulator's PLC panel keeps running here, and the simulator publishes its variables on an OPC UA server, the way a real PLC does. Your SCADA, HMI or any OPC UA client connects to it, watches the line and presses its buttons.

In this guide your client presses Start, a belt carries a box to a sensor, and the program stops it. No PLC is needed, and it takes about ten minutes.

You need

1. Build the scene and wire it to the program

In the desktop app, start a new scene and place three parts from the library:

  1. A Belt Conveyor.
  2. A Box, sitting on the belt near the end it starts from.
  3. A Photo Eye beside the belt, about two thirds of the way along, facing across it.

Select each device, find the Comms group in the Inspector, and type the program variable it connects to:

PartFieldType inMeaning
Photo EyePresence TagMain.EyeTrue while the sensor sees the box.
Belt ConveyorRun TagMain.RunThe belt runs while it is true.
Belt ConveyorSpeed TagMain.SpeedThe belt's speed, a setpoint your client can change.
The Inspector's Comms group for the Belt Conveyor, with Speed Tag set to Main.Speed and Run Tag set to Main.Run.
The Belt Conveyor's Comms group, wired to the program.

These are names, not I/O addresses. The parts talk to the program running in the simulator, and the client talks to the program. Nothing here travels over a fieldbus.

2. Write the program

Open the PLC panel, replace whatever is in its code editor with this, and check the panel reports no errors:

PROGRAM Main
VAR
  Start : BOOL;
  Eye : BOOL;
  Run : BOOL;
  Speed : REAL := 0.5;
END_VAR

Run := Start AND NOT Eye;
END_PROGRAM

The belt runs once Start is true and stops while the sensor sees the box. Nothing in the scene sets Start. Your client presses it.

3. Start the OPC UA server

Open Simulation > PLC Controllers… (or double-click the Controller node at the top of the PLC panel's organizer). Leave Runs on at This simulator, and in the OPC UA server section:

  1. Tick Publish the program's variables. The server starts at once; you do not need to press Play.
  2. Port: 4843 is the default. OPC UA's standard port, 4840, is often taken by a discovery server that other OPC software installs.
  3. Reachable from the network: leave it off if the client runs on this computer. Tick it if it does not, and allow the app through the Windows firewall when Windows asks.
The OPC UA server section of Controller Properties: Publish the program's variables ticked, Port 4843, Reachable from the network off, and the status line saying it is serving.
The OPC UA server section, serving.

The status line under it should read:

Serving opc.tcp://127.0.0.1:4843: no client connected, 4 variables, 3 writable. Stopped: they read as out of service until Play.

Like the other connection settings, these are saved on this computer, not in the scene.

4. Connect the client

In your client, add a connection to the simulator:

SettingValue
Endpoint URLopc.tcp://127.0.0.1:4843 on the same computer, otherwise this computer's address and the same port
Security policyNone (the server offers no other)
Message security modeNone
AuthenticationAnonymous

The server calls itself Open Industry Project simulator. Browse Objects > PLC > Main and you find the program's four variables:

VariableNodeIdTypeYour client may
Startns=1;s=Main.StartBooleanread and write
Eyens=1;s=Main.EyeBooleanread only: the sensor feeds it
Runns=1;s=Main.RunBooleanread and write
Speedns=1;s=Main.SpeedFloatread and write

Subscribe to Eye and Run. Back in the simulator, the status line now names your client: Serving opc.tcp://127.0.0.1:4843: 1 connected (...).

5. Run the line from the client

  1. Before Play, your client reads every variable as BadOutOfService and a write is refused with BadInvalidState. A stopped PLC is not running a line, and a SCADA must not show one that is.
  2. Press Play in the simulator. The values turn good, with no need to reconnect or subscribe again: Start, Eye and Run false, Speed 0.5. The belt waits.
  3. Write true to Start. The belt runs, the box reaches the sensor, your subscription sees Eye turn true, and the belt stops.
  4. Optional: press Stop and Play to start again, write 0.2 to Speed and then true to Start. The belt carries the box at the new speed.
The box has ridden the belt conveyor and stopped in front of the photo eye.
After the write to Start, the belt carried the box to the photo eye and stopped.

The PLC panel's watch table shows what your client writes, and Controller Properties shows the last write, for example Last write from a client: Main.Start := TRUE.

Stop and Play keep the connection. On Stop every value goes back to BadOutOfService; on Play the same subscriptions turn good again. The server stays up for as long as the box is ticked, not for one run, because a SCADA stays connected while you edit and restart.

Troubleshooting

"Publish the program's variables" is greyed out.
You are in a browser tab. The server needs the desktop app.
"Could not start the server: ..."
Something else uses the port. Pick another one, and use it in the client's endpoint URL.
The client refuses to connect, or finds no endpoint.
Allow the None security policy and anonymous login in its connection settings. The server offers nothing else. If the client is on another computer, tick Reachable from the network, use this computer's address instead of 127.0.0.1, and check the Windows firewall allows the app.
Every value reads BadOutOfService.
The simulation is stopped, or the program is not running here (an error in the PLC panel, or "Runs on" set to an external PLC). Press Play.
A write comes back BadNotWritable.
The variable is one a part feeds, a constant, or a timer's output. Write the variable the program reads instead, like Start.
The variables are missing, or show "no variables yet".
The program has not compiled. Fix the errors the PLC panel shows. A variable appears under its program's name, so Main.Start is under PLC / Main.