Troubleshooting
Why CODESYS cannot write the RevPi gateway output image
Short answer
When piTest can write the gateway's output image but the CODESYS application cannot, the module and its region are proven and the fault is in the outbound software path. The write block's missing error only means the value was buffered; with PEV_OUT called before the WRITE_OUTPUT calls, each commit sends stale data and one-time writes never transfer. Write first, transfer last, in one cyclic task, then read the bytes back with piTest while the application is stopped.

On this page
- What does the working piTest write prove?
- Which device and region sit behind offset 512?
- Does the CODESYS task actually execute the write?
- Is PEV_OUT called before the writes it should carry?
- Do the offsets and byte order match the image?
- How do you prove the corrected sequence works?
- When is the fault downstream of the image?
- Questions asked
When piTest -w 512,2,3333 changes the RevPi gateway's output image but the CODESYS application cannot, the module, its byte range and the bus-side path are proven, and the fault sits on the CODESYS-to-image boundary. A write block that reports no error has only accepted a value into a buffer; nothing has shown the transfer to the image. In the sequence behind this symptom, PEV_OUT runs before the three WRITE_OUTPUT calls it should carry, so each commit sends stale data and a one-time write never leaves. The decision: write first, transfer last, in one cyclic task, then prove it with a readback while the application is stopped.
What does the working piTest write prove? #
It proves the region exists, accepts writes and holds the value you give it, so the gateway module, its image mapping and that byte range are good; the fault is not in any of them. The command's own report, value d05 hex, decimal 3333, laid down as two bytes, is the tool's claim; reading those bytes back is what makes it evidence. The working CODESYS reads are the second proof: the same runtime reaches the image inbound, so the installation, the task and the image handle are alive, and only the outbound sequence is in question.
One caution belongs here: the gateway's output region is the input data the PROFIBUS master polls, so a test word can act on real machine logic; run both tests with the master side in a safe state. The same boundary check, run from the command line against a directly driven output rather than a gateway region, is covered in a comparison of piTest with the revpi-output tool.
Which device and region sit behind offset 512? #
The gateway's output region: piTest -d on this unit lists the PROFIBUS gateway at output offset 512 with a length of 512 bytes, while the controller's own outputs sit at 1030 with a length of 5 bytes.
Device in piTest -d |
Local address | Input region | Output region |
|---|---|---|---|
| RevPi Connect V1.0, type 105 (0x69) | 0 | Offset 1024, length 6 bytes | Offset 1030, length 5 bytes |
| Gateway Profibus V0.0, type 77 (0x4d) | 31 | Offset 0, length 512 bytes | Offset 512, length 512 bytes |
These are one unit's readings: module order and configuration move them, so your own listing sets your offsets. The gateway's output region runs from its base up to byte 1023, the base plus the length minus one, and every write in the failing sequence falls inside it. The local address 31 is the gateway's position in the controller's inventory, nothing more: it is neither the PROFIBUS station address nor an image offset, and the station address the master polls is configured at the master, so verify it there. If the gateway were missing from the listing, stop and fix its attachment and local configuration before testing CODESYS at all.
Does the CODESYS task actually execute the write? #
Check it online before blaming the library: log in, run the application and watch WRITE_OUTPUT execute in its task, because a call that is never reached produces exactly this symptom and no image setting will fix it. A call behind a false run condition, or in a task that is not configured to run, executes zero times while the project looks correct offline. The working reads do not prove this call executes: input and output use separate blocks, and the write can sit in a task or branch the reads never touch. Licensing is not the suspect either: a Raspberry Pi runtime without a valid license runs for two hours and then shuts down, a failure that would take the reads down with it. Note also where the sequence lives: placed in an initialization path or behind a one-shot edge, it executes exactly once, which combines badly with a transfer call in front of it.
Is PEV_OUT called before the writes it should carry? #
Yes, in the sequence that produces this symptom: PEV_OUT runs first, then OFFSET_W is loaded and WRITE_OUTPUT is called three times, so the transfer call commits the previous cycle's buffer instead of the new values. The IEC 61131-3 Structured Text, in call order:
PEV_OUT(resErr:=reset, eError=>ER_02);
OFFSET_W[1]:=512;
WRITE_OUTPUT(auiOffset:=OFFSET_W, iOut:=1111);
OFFSET_W[1]:=514;
WRITE_OUTPUT(auiOffset:=OFFSET_W, iOut:=2222);
OFFSET_W[1]:=516;
WRITE_OUTPUT(auiOffset:=OFFSET_W, iOut:=3333);
WRITE_OUTPUT is the library's output block, rpi.REVPI_PIOUT_INT, and its silence means the call accepted its inputs, array in bounds and offset readable, not that the bytes reached the image. This library is experimental and unsupported, so record its version beside the runtime version and retest the sequence after any update. The first call has two candidate roles, initialization or commit, and one test decides between them: stop the application, read the region, run a single pass of writes followed by PEV_OUT, read again. Bytes that appear only in the second reading prove the first call is the commit and the order was the fault.
The resolving change is the same task, the same cycle, writes first and PEV_OUT last. In a cyclic task the old order costs one cycle of staleness; executed once, as an initialization, a recipe load or an edge-triggered command, it costs the transfer entirely, which matches an image that never changes. A buffered write is the pattern covered in why an Ethernet/IP gateway process image needs an application copy: the block's data and the image are two stores, and only the commit makes them equal. Close one masking trap as well: read the documented meaning of reset, and if it clears diagnostics, hold it inactive while you collect the failure state; otherwise ER_02 stays clean because it is being wiped, not because nothing is wrong.
Do the offsets and byte order match the image? #
The offsets do: the entries in OFFSET_W are byte offsets, so the three writes occupy bytes 512-513, 514-515 and 516-517, distinct, non-overlapping slots inside the gateway's output region. The command-line value shows the byte-order arithmetic to check. Decimal 3333 is 13 x 256 + 5, so its word is 0x0D05. The input path rotates every word by 8 bits with ROL(DATPOINT,8); on a 16-bit operand that swaps the two bytes, evidence that the gateway's word order differs from the controller's native order, so confirm the operand's declared type first, because on a wider type the same rotation does something else. If the output path needs the same swap, the application places 0x050D, which is 5 x 256 + 13 = 1293, for the master to read 3333.
Decision on order: a byte-order fault produces a value that changes but reads wrong at the master, while the reported symptom is a region that never changes, so fix the transfer first, then read the raw output bytes back once and match their order to the master's configured interpretation before adding any swap. Two input-side habits are worth checking in the same code: OFFSET[1]:=I*2 walks word positions, so confirm the loop's start index does not skip the first word; and uiMaxIndex:=4096 is a library indexing limit, not the module's payload, because the inventory above fixes each direction's length and no library setting enlarges the gateway's cyclic data. When writes land at the wrong image offsets altogether, the mapping itself is the suspect, covered in why CODESYS writes miss the process image offsets; here the offsets are correct, so the search stays on execution and transfer.
How do you prove the corrected sequence works? #
Stop the application after one pass of the reordered sequence and read the same word back with piTest's read function: bytes that match the written value close the CODESYS-to-image path, and whatever is still missing lies downstream of the image.
- Reduce the test to one write, the same value at the same offset as the command-line test, so the path is the only difference left.
- Reorder: the write, then PEV_OUT, in the same task and cycle, with every other writer stopped so the reading is interpretable.
- Run one pass, stop the application, read the bytes back at the region's base.
- Judge the reading: identical bytes mean the path is proven; the value in swapped byte order means the transfer works and the order is next; nothing or a stale value sends you back to the execution and commit checks above.
- Compare with what the PROFIBUS master receives only after the image itself is proven.
When is the fault downstream of the image? #
Only when the readback holds your bytes: the remaining path is then the gateway's cyclic exchange and the master's mapping of those words, and because the working reads prove the inbound exchange is alive, the first suspect is the master's mapping, not the cable. PROFIBUS carries input and output data in the same cycle, so fresh input data at the controller means the bus is running; a stale output at the master with a correct image points at which words the master's configuration assigns to the gateway. Check the master's configured station address for the gateway first, then the gateway's configured output size against the words the master polls. Cabling, termination and station addressing belong to a bus that is down, which fresh inputs rule out; the bus-level status and its LED meaning are covered in why a RevPi PROFIBUS gateway offline LED flashes red.
Questions asked
Can the writes and the transfer call run in different tasks?
Keep them in one task and one cycle. A transfer call in another task can commit the buffer before the writes fill it, or after a later task has refilled it, which is the race this fault is built from. Where the values originate elsewhere in the application, hand them over through variables and let a single task own every library call on that region.
Why does call order matter if the data still arrives a cycle late?
For a cyclic setpoint one late cycle may be tolerable, but the same order silently breaks everything written once: an initialization value, a recipe load or an edge-triggered command is committed never, because the commit already ran. Putting the transfer call at the end of the sequence removes the delay and the missing writes in one change.
How do you keep a test word from acting on the machine?
Halt the master's program or disable the actuators while you test, change only the one word you intend to change, and write a defined safe value back to that word before the master returns to run. A leftover test word is picked up as live input data on the very next cycle.
Can a command-line tool write the image while the CODESYS application runs?
It can, and that is the hazard: the region then has two writers, and whichever writes last wins each cycle, which looks exactly like values that appear and then change back. During diagnosis stop one side, and in operation give each region a single writer: the application for the words it controls, the command line only for checks made while the application is stopped.


