IMDHMIControls LibraryShop main store

How-to

Exposing Modbus coil addresses as named OPC UA symbols

SCADA and data logging Published 5 min read

Short answer

Machine Expert's Symbol Configuration does not list directly addressed %QX variables, so Modbus coil bits cannot be exported as they stand. Declare one ordinary named Boolean per coil, copy between the coil area and those variables in the task, and export the variables with read or write access set per point. The AT %QW word-array trick exposes 256 unnamed bits per 16 words, not named coils.

On this page
  1. What Symbol Configuration exports
  2. Why the word array is the wrong shape
  3. Build the named coil interface
  4. Synchronize the coil area in the task
  5. Commission the symbols end to end
  6. Questions asked

Machine Expert's Symbol Configuration does not list directly addressed %QX variables, and it carries no direct I/O access allowance matching the one documented for plain CODESYS — so stop hunting for that toggle. Export ordinary named Boolean application variables instead, and copy them to and from the coil area in the task. Modbus keeps its coils where the map expects them; OPC UA clients browse one named, typed point per signal, with access rights you set per point. The AT %QW word array that does select as a symbol hands the client 16 words — 256 unnamed bits — where you wanted 16 named coils.

What Symbol Configuration exports #

Plain CODESYS allows its symbol configuration to list direct I/O addresses in IEC syntax alongside application variables — the documentation's example is %IX0.0 — and gates that allowance because a remote client would then reach I/O memory directly. Machine Expert's Symbol Configuration lists no directly addressed variables at all: your %QX coils never appear among the selectable entries, and no equivalent option presents itself in the tool. Commit to the named-variable route regardless, because it is the better answer even where direct export exists. A client browsing a direct export sees %QX100.0, not FeederRunning; you trade a naming problem for an addressing problem, and a writable symbol bound to output memory writes straight past your command validation. Hiding direct addresses behind named application memory is the same move as exposing PLC values to an OPC server through guest memory blocks on the OFS side: the client browses names, never memory.

Why the word array is the wrong shape #

bool_coils AT %QW10: ARRAY [1..16] OF WORD; is accepted where %QX addressing is refused because it declares words, and it is the wrong shape for exactly that reason. Work a 16-coil block mapped at %QX100.0 through %QX101.7, illustrative addresses from an example map: 2 bytes × 8 bits per byte = 16 bits, and 16 bits ÷ 16 bits per WORD = 1 WORD. The block needs one word; the array reserves 16 × 16 = 256 bits, sixteen times the block, and not one bit of it carries a name.

A client reading element value 5 must compute 5 = 2^0 + 2^2 = 1 + 4, conclude bits 0 and 2 are set, then learn from your controller's addressing convention which physical end of the word bit 0 lands on. Whether word 10 in %QW10 covers bytes 10–11 or a different range depends on that same convention, and the word number alone will not tell you. Verify with one coil toggle online before trusting any packing.

Representation What the OPC UA client sees Consequence
%QX direct addressing Not listed in Machine Expert Symbol Configuration No symbol to export
AT %QW word array 16 WORD elements, 256 unnamed bits Client unpacks bits; bit and byte order verified online
Named BOOL variables One named Boolean per coil PLC does the mapping once, testable in code

Keep the word array only for a client that deliberately consumes packed words. For named SCADA points, extract the bits in the PLC and export the named results.

Build the named coil interface #

  1. Freeze the coil map. List every coil SCADA touches with its address, its role — status or command — and its single writer. Confirm each address by watching the controller value while you toggle one known coil through the existing Modbus connection.
  2. Classify every point before writing code. Status: the PLC produces it, OPC UA reads it. Command: OPC UA writes it, the PLC consumes it through the machine's existing validation and interlocks. A point that Modbus and OPC UA would both write gets one owner; the other protocol reads.
  3. Declare one BOOL per point, no AT address, with a process name such as bFeeder_Running, and put the coil address in the comment so the link stays traceable.
  4. Add the copy code to the task that owns the data.
  5. Select those variables in Symbol Configuration: read access for status points, read/write only for the command points whose ownership step 2 settled.
  6. Build, download the application and its symbol configuration together, and confirm the online application contains the new variables.

Synchronize the coil area in the task #

A status point gets one producer and two consumers: the assignment that computes the state feeds the named variable, and the named variable feeds the coil for Modbus.

VAR
    bFeeder_Running    : BOOL := FALSE;  // status, exported read-only
    bDoor_Open         : BOOL := FALSE;  // status, exported read-only
    bStart_Request     : BOOL := FALSE;  // command, exported read/write
    bStart_Request_Old : BOOL := FALSE;  // edge memory, not exported
END_VAR

feeder_feedback, fault_active, door_switch and start_sequence below stand for signals your program already owns:

// status: one producer, two consumers
bFeeder_Running := feeder_feedback AND NOT fault_active;
%QX100.0 := bFeeder_Running;      // example address in this map
bDoor_Open := door_switch;
%QX100.1 := bDoor_Open;

// command: consume the client write once, through validation
IF bStart_Request AND NOT bStart_Request_Old THEN
    IF NOT bDoor_Open THEN        // interlock example
        start_sequence := TRUE;
    END_IF
END_IF
bStart_Request_Old := bStart_Request;

The test that proves it: force feeder_feedback TRUE and confirm bFeeder_Running follows in the same task, %QX100.0 follows for the Modbus reader, and the OPC UA subscription reports the false-to-true transition; then repeat from TRUE to FALSE, because one-direction testing hides a copy wired backwards.

Never copy status back into a variable a client writes: the status assignment runs every scan and erases the command before the command logic consumes it. Two writers on one point is also the failure you meet when fixing SCADA coil oscillation through a Modbus gateway — the point flips every scan because each writer undoes the other, and the cure is ownership, not timing. A copied status value is a snapshot from the moment the assignment executes; end-to-end delay is that task's execution plus the sampling and publishing the OPC UA client configured.

Commission the symbols end to end #

Connect the OPC UA client to the controller's endpoint with its configured security and user settings, browse the application variables, and confirm three things per point: the name, the Boolean type, and the access you set. Subscribe to each status point and drive its source through the existing Modbus path; verify both transitions in the controller and in the client, reading quality and timestamp alongside the value. Test command points only under approved machine conditions and judge acceptance by the resulting PLC state, not by a successful client write.

Fix the names before you export. A client tag binds to the variable's browse path, and renaming the variable later breaks it exactly the way PLC symbol changes break SCADA tags in OFS — recoverable, but every client configuration pays for it.

The decision, case by case: status coils become read-only named variables fed by the same assignment that drives the coil; command coils become read/write named variables consumed once through validation; a client that genuinely wants packed words gets an array sized by bits ÷ 16, rounded up; and direct %QX export is both unavailable here and not worth wanting — an address is not a name.

Questions asked

Is there a direct I/O access setting in Machine Expert like the CODESYS one?

No. Plain CODESYS documents an allowance in its symbol configuration to list direct I/O addresses in IEC syntax, with %IX0.0 as the example, and gates it because remote clients would reach I/O memory directly. Machine Expert's Symbol Configuration lists no directly addressed variables and shows no matching option. Even where the allowance exists, you would browse an address like %QX100.0 rather than a process name, and a writable address would bypass command validation, so moving to named variables is work you would do anyway.

How many WORDs does my coil block need if a client really wants packed data?

Divide the coil count by 16 and round up. Sixteen coils is 16 divided by 16, so 1 WORD. Forty coils is 40 divided by 16, which is 2.5, so 3 WORDs carrying 48 bits with 8 spare. Declare only the words the block spans, confirm in the controller's addressing documentation whether %QW10 covers bytes 10 to 11 or a word-numbered range, and toggle one coil online to prove which bit moves before the client trusts the packing.

My OPC UA status value lags the coil. Is the symbol misconfigured?

Usually not. The value is a snapshot taken when the task executes the copy, and the client sees it on its subscription's sampling and publishing intervals. Work the chain in order: task cycle time, then server sampling, then client publishing interval, measuring the source and the client side together. A symbol that browses correctly proves nothing about how often the copy runs, so watch the variable in the controller first.

Can SCADA keep writing some coils over Modbus while OPC UA writes others?

Yes, provided each individual point has exactly one writer. Split the map: Modbus-owned command coils stay exactly as they are, OPC UA-owned commands arrive through their named variables and the machine's validation, and status points are read-only on both protocols. Refuse the one case of a single coil written by both protocols, because that setup oscillates, and the fix is ownership, not scan-time tuning.

Keep reading

  • How-to

    Serve generic Modbus devices to SCADA through OFS with the PL7 driver

    OFS does serve generic Modbus devices: select the PL7 driver in the device alias, not Unity, because Unity issues Schneider-extended function codes a standard slave rejects while PL7 issues the public read/write set. Import the tag definitions as a .SCY file, make OFS the only Modbus master on the link, and point Citect and every OPC DA or UA client at that one server.

    SCADA and data logging

  • Troubleshooting

    When Aveva Edge cannot browse S7-1500 OPC UA tags

    AVEVA Edge connecting but showing no S7-1500 tags is a browse fault, not a comms fault: UAExpert reading the same server proves the tags are exposed. Match Edge's endpoint and security settings to the working client, verify the CPU's X1 Ethernet addresses, put a virtual machine on the PLC subnet, and check the browse timeout before rebuilding the datasheet.

    SCADA and data logging

  • How-to

    Connect an S7-1500 to SCADA over OPC UA from TIA Portal

    The S7-1500 has a built-in OPC UA server from firmware V2.0, deactivated by default. Enable it in the CPU device properties in TIA Portal, select the installed server license, copy the endpoint URL, and download. Paste the opc.tcp address into any OPC UA SCADA client, trust the certificates on both sides, then browse the PLC variables and map them to SCADA tags.

    SCADA and data logging