IMDHMIControls LibraryShop main store

Troubleshooting

Why CODESYS writes miss the process image offsets

Industrial networks Published 7 min read

Short answer

Your CODESYS GVL carries process image offsets from a different piCtory topology, so LED and relay writes land on the wrong bytes. Run piTest -d on the running controller, export the offsets of the active configuration into the GVL, keep both Modbus masters configured in CODESYS rather than piCtory, and expose the serial device prefix in CODESYSControl.cfg before testing the RTU master.

On this page
  1. Why do CODESYS writes not change the LEDs?
  2. What does the running process image actually report?
  3. Which offsets belong in the CODESYS GVL?
  4. Should CODESYS or piCtory own the Modbus masters?
  5. Why does the Modbus RTU master stay silent?
  6. Why does piCtory read the temperature but CODESYS does not?
  7. How do you prove each stage before buying the I/O modules?
  8. Questions asked

Your LEDs and relay ignore CODESYS writes because the global variable list carries process image offsets from a five-module piCtory topology, while the controller is actually running a Connect-only image. Run piTest -d on the device, export the offsets of the active configuration into the GVL, keep the Modbus TCP and RTU masters configured in CODESYS instead of piCtory, and map the serial device prefix in /etc/CODESYSControl.cfg before you test the RTU master. Those three steps take the project from LED proof through Modbus TCP to Modbus RTU, and they tell you the AIO and DIO modules can wait until the first two stages work.

Why do CODESYS writes not change the LEDs? #

The LED offsets in your global variable list come from a five-module image, where the Connect output region starts at 1232; on a Connect-only image it starts at 6, so each write addresses bytes the LEDs do not occupy.

An offset here is a byte position in the RevPi central process image, not a time value. Each configured device receives its own input region and output region, and the reported five-module example put the Connect input region at offset 1226 with length 6 and its output region at offset 1232 with length 5. On a Connect-only image the six input bytes occupy positions 0 through 5, so the output region begins at 0 + 6 = 6. A GVL still holding the five-module numbers writes into bytes the LEDs never occupy, and the hardware correctly ignores them. The relay shares the Connect output region; the exported evidence names the region but not the relay's bit position, so take the bit from your exported onboard I/O definition.

Disconnect whatever load the relay switches before you exercise it, so a mis-aimed write cannot drive a live actuator.

A configured object that stays physically dead is a pattern this controller shares with other CODESYS targets: the same class of fault appears when CODESYS variables do not map to Neuron outputs like GPIO, and the fix there is also to trust the runtime's own view of the image over the project's.

What does the running process image actually report? #

Run piTest -d on the controller itself and read the reported input and output offsets: on a Connect-only image the Connect reports input offset 0 with length 6 and output offset 6 with length 5, and those are the numbers your code must match.

piTest -d lists every device in the active image with its address, input offset and length, and output offset and length. Compare the two configurations from the reported setup. First, the five-module image whose Connect offsets the failing project had copied:

Address Device Input offset / length Output offset / length
0 RevPi Connect V1.0 1226 / 6 1232 / 5
31 RevPi AIO V1.3 1137 / 20 1157 / 4
30 RevPi DIO V1.4 1024 / 70 1094 / 18
29 Gateway ModbusTCP V1.3 0 / 512 512 / 512
32 RevPi CON CAN V0.0 0 / 0 0 / 0

Then the image after the change, with only the Connect plus the two virtual Modbus masters:

Address Device Input offset / length Output offset / length
0 RevPi Connect V1.0 0 / 6 6 / 5
64 ModbusTCP Master Adapter V0.0 11 / 101 112 / 73
65 ModbusRTU Master Adapter V0.0 203 / 101 304 / 75

Reading the running image with piTest alongside the piCtory configuration is the same pair of tools used when commissioning a gate module; a guide to configuring a gate module in piCtory and checking it with piTest walks through both on one device.

Which offsets belong in the CODESYS GVL? #

Take every offset from an export of the piCtory configuration that is actually running; for the Connect-only image the LED array value [6,0] points the first LED write at output byte 6, and nothing in the list may be left over from the five-module project.

The exported values for that image are:

VAR_GLOBAL
    aby_CPI                : ARRAY[0..4095] OF BYTE;
    g_uiIn0Offset          : UINT := 0;
    g_uiOut0Offset         : UINT := 6;
    g_aui_RevPiStatusOffs  : ARRAY[1..2] OF UINT := [0,0];
    g_aui_RevPiIOCycleOffs : ARRAY[1..2] OF UINT := [1,0];
    g_auiRevPiLEDOffs      : ARRAY[1..2] OF UINT := [6,0];
    g_uiIn64Offset         : UINT := 11;
    g_uiOut64Offset        : UINT := 112;
END_VAR

The variable names are the export's own; before the update, those same names carried the five-module image's numbers, which is precisely what broke the LED writes. When the AIO and DIO modules are installed and added to piCtory, every offset below the Connect can move again, so the export step repeats rather than being done once.

Should CODESYS or piCtory own the Modbus masters? #

Configure one owner per interface: the setup that works runs the Modbus TCP and RTU masters as CODESYS objects and keeps only the Connect module in piCtory, because a virtual piCtory master and a CODESYS master will both try to drive the same traffic.

Two architectures work, but they cannot overlap. If piCtory owns Modbus, you add the virtual Modbus TCP and RTU master modules there, and CODESYS reads the values from the adapters' input regions. If CODESYS owns Modbus, piCtory holds only the Connect module and the CODESYS Modbus TCP Master and Modbus RTU Master objects issue the requests themselves. The reported setup settled this by success: the CODESYS TCP master already reached the router, so CODESYS became the sole owner and the virtual masters were left out of piCtory. Commit to one owner per interface before you write application code; a slave that answers one master while another polls the same serial port is a troubleshooting problem you create for yourself.

Why does the Modbus RTU master stay silent? #

The runtime does not see any serial adapter until /etc/CODESYSControl.cfg maps the device prefix: add the SysCom section with the device file line and no trailing digit, because the adapters enumerate as ttyUSB0, ttyUSB1 and ttyUSB2 while the setting takes the shared prefix.

[SysCom]
Linux.Devicefile=/dev/ttyUSB

Leave the trailing digit out: the setting passes the prefix, and the runtime opens whichever adapter matches the port configured in the CODESYS RTU master object. A port assignment written directly in code, portnum := COM.SysCom.SYS_COMPORT1, was tried in the reported setup and changed nothing; the configuration-file entry is what exposes the port. With the port exposed, the master object carries the slave address, register offset, register length and serial format, and the reported setup confirmed those already matched what piCtory had used, so a silent master after that points at the prefix mapping rather than at the register definitions.

Why does piCtory read the temperature but CODESYS does not? #

A value piCtory shows can sit in a region your code never reads: the received temperature belongs to the RTU adapter's input region, which starts at offset 203 with length 101, while offset 304 begins that same adapter's output region for request-side data.

Worked example from the reported setup. The RTU adapter sits at address 65 with input offset 203, length 101, output offset 304, length 75, and the regions are contiguous: 203 + 101 = 304. A two-byte read of the temperature register through piTest returned 256, displayed as 0100 hexadecimal. That is received slave data, so it lives in the input region beginning at 203. A variable aimed at the output region reads request-side bytes instead, so the application sees stale or zero data while piTest and piCtory show the live value. Under the CODESYS-owned architecture from the previous section, neither adapter region is the application's interface at all: read the temperature from the CODESYS RTU master's receive channel, and treat the piTest read as commissioning proof rather than the data path.

How do you prove each stage before buying the I/O modules? #

Prove the image first and the serial port second, with a write and a read at every stage: the reported setup confirmed the LEDs, then Modbus TCP to the router, then Modbus RTU to the slave, each step checked against piTest.

  • Run piTest -d and record each device's address, input offset and length, and output offset and length.
  • Export the offsets of the active piCtory configuration and replace the matching values in the GVL; delete any value left over from another topology.
  • Write and read back the LEDs through the exported Connect output region, with the relay load disconnected, before touching Modbus.
  • Configure the CODESYS Modbus TCP master with the router's address, port, unit identifier and register definitions, and confirm a live register read.
  • Add the serial prefix mapping, configure the CODESYS Modbus RTU master, and confirm a frame from the slave before writing application logic.
  • Install the AIO and DIO modules, add them to piCtory, re-export, and repeat the offset update; the Connect-only numbers stop being valid the moment the module list changes.

Decision, case by case: the dead LEDs and relay are a stale GVL, fixed by exporting the active image's offsets; the silent RTU master is an unmapped serial prefix, fixed by the SysCom entry in the configuration file; and the unreadable temperature is a wrong region, fixed by reading the CODESYS master's receive channel. None of the three is an application-logic fault.

Questions asked

Is a process image offset a time value?

No. An offset is a byte position in the central process image. Each configured device receives an input region and an output region, and changing the module list moves both regions, which is why the offsets must be re-exported after any topology change and why values copied from an older configuration write into the wrong bytes.

Does portnum := COM.SysCom.SYS_COMPORT1 fix the silent RTU master?

In the reported setup that assignment made no difference, and one fix removed it together with all other SysCom configuration from /etc/CODESYSControl.cfg to get the port working. The SysCom entry with the device prefix is what exposes the serial adapters; the slave address, register offset, register length and serial format belong in the CODESYS RTU master object itself.

Can piCtory's virtual Modbus masters read the same devices instead?

Yes, as the alternative architecture. Add the virtual Modbus TCP and RTU master modules in piCtory, and the received values arrive in the adapters' input regions, which CODESYS then consumes. Do not also run the CODESYS masters on the same interfaces; one interface has one master, and the choice must be made before application code is written.

What changes when the AIO and DIO modules are finally installed?

The module list changes, so the offsets move. Add the modules in piCtory once they are physically present, run piTest -d again, and export the new offsets into the GVL before testing. The values that worked on the Connect-only image stop being valid at that moment, and the same applies to any Modbus adapter regions in the image.

Keep reading

  • Troubleshooting

    How to poll many Modbus RTU slaves from one serial master

    Poll each slave with its own MRX read or MWX write sequence, one active transaction on the port at a time, and pick the function code from the slave's data access type. A timeout means the serial path; a Modbus exception means the slave answered and rejected the request. Twenty-two slaves at 9600 baud poll in about one second.

    Industrial networks

  • Troubleshooting

    Speeding Up Modbus RTU Writes Behind Polled Reads

    The writes are slow because the Modbus client driver owns the serial port and services one enabled instruction at a time, so a write queues behind every enabled read. Put each transaction in its own stage, put the write stages first, and advance the chain on completion; a write then waits at most one in-flight transaction.

    Industrial networks

  • Explainer

    Why an S7-200 cannot share one RS-485 port with a PC and Modbus

    A CPU224 can serve a programming PC and four Modbus devices, but never through one shared RS-485 pair: a port runs either PPI programming traffic or the Modbus RTU master. Put the PC on port 0 and the Modbus master on port 1, wire the four devices as one terminated RS-485 trunk with unique addresses, and bring up each path separately before running them together.

    Industrial networks

Why IO-Link hub outputs stay off despite a valid process image