IMDHMIControls LibraryShop main store

Explainer

Why CODESYS variables do not map to Neuron outputs like GPIO

Industrial networks Published 6 min read

Short answer

A declared CODESYS variable drives a Neuron output only after you bind it to that channel in the device's I/O Mapping tab. The outputs are not GPIO: the licensed UniPi Neuron for CODESYS driver exposes them as device channels over Modbus TCP, and channels whose values span more than one register go through the bundled Neuron library.

On this page
  1. Why a declared variable is not a connection
  2. What the UniPi Neuron for CODESYS package adds
  3. How the binding works in the I/O Mapping tab
  4. Worked example: a 32-bit channel across two Modbus registers
  5. After the mapping: rules the device adds per channel
  6. When a mapped output still does not move
  7. Questions asked

A declared variable never reaches a Neuron output on its own — that is the whole problem. The m203's digital and relay outputs are not GPIO: the licensed UniPi Neuron for CODESYS package exposes them as channels of a device that communicates over Modbus TCP, and CODESYS attaches application variables to device channels in exactly one place, the device's I/O Mapping tab. So the answer is: declare the variable with the type the channel shows, double-click the Neuron device in the device tree, open its I/O Mapping tab, and type the variable into that channel's row. Channels whose values are wider than one register go through the Neuron library that ships in the same package. The sections below cover why the GPIO approach cannot work here, what the package adds, where the binding happens, and how to chase an output that stays dead after mapping.

Why a declared variable is not a connection #

On a controller whose outputs sit in its own process image, tying a variable to a physical point can feel like a declaration detail. The Neuron does not work that way. Its I/O lives behind a Modbus TCP interface, and the UniPi Neuron for CODESYS driver is the piece that speaks that protocol; your application only ever sees the channels the driver exposes. CODESYS's driver documentation states the pattern plainly: add the device, configure it, then map its input and output channels to variables in your application.

Until that mapping exists, an output variable is memory and nothing more — writes to it stop at the variable and never reach a coil. No GPIO-style assignment changes this, because there is no GPIO layer for these points to land in. CODESYS treats the Neuron like any other I/O device: the outputs are assigned the way every device channel is, in the mapping, not in the declaration.

What the UniPi Neuron for CODESYS package adds #

The addon is a licensed product distributed through the CODESYS store; once installed and licensed it brings the two things the project cannot do without. First, a device description for the Neuron, which is the tree entry whose channels you map. Second, a library whose function blocks handle the data types that span more than one register. The driver runs the Modbus TCP master side of the conversation, so nothing in your application writes the transport by hand.

Resolve the package before touching variables. If a new project on the Neuron's hardware offers a generic Raspberry Pi controller type but no Neuron device, the wrong package is installed, and the fix is to install the Neuron package rather than the plain Raspberry Pi one. A missing device description or a device configuration error will block every mapping you attempt, so the tree entry has to be present and error-free before the steps below.

How the binding works in the I/O Mapping tab #

The mapping is the link between application data and the driver's process data, and CODESYS gives it one home:

  1. Declare the variable with the type the channel row shows — rRelay01 : BOOL for an on/off relay channel, as an example name; the type is what has to match.
  2. Double-click the Neuron device object in the device tree, which opens the device editor on its I/O Mapping tab.
  3. Find the row of the output channel you want. The row's name and its Type column come from the device configuration — never from the terminal number printed on the housing, and never from a register list for a different product.
  4. Bind the variable in that row's variable cell.
  5. Build the project, clear any type or mapping error, and download.

The tab itself is ordinary CODESYS, and Map physical I/O channels in CODESYS V3.5 walks it channel by channel. For using the mapped variables in your program, Map CODESYS I/O for ladder and structured text use shows them at work from ladder and structured text. Keep one habit: scroll the tab before leaving it and confirm each intended channel shows its intended variable, because the rows you see there are what the download sends.

Worked example: a 32-bit channel across two Modbus registers #

The case: an output channel whose value will not fit one register — exactly the situation the package's library exists for.

  • Inputs: the channel's configured type, read from the Type column of its row in the I/O Mapping tab — for this example DINT, 32 bits (an example reading; your row is the authority); the Modbus register width, 16 bits, which is a protocol constant and not a device setting; and the declared variable, for example rSetpoint : DINT (illustrative name).
  • Rule in words: registers the value occupies = channel width ÷ register width, rounded up to a whole register. If that comes to more than one, no single-register write can carry the value.
  • Arithmetic: 32 bits ÷ 16 bits per register = 2 registers, with no rounding left over.
  • Result: the one value sits in two registers. A BOOL or INT variable cannot hold it, and two separate single-register writes would tear the value apart between the pair.
  • Decision: when the Type column shows a type no wider than the register width — BOOL, INT, UINT, WORD — bind the variable straight into the I/O Mapping tab. When it shows anything wider — DINT, UDINT, REAL — drive the channel through the Neuron library's function blocks from the package, which assemble the register pair for you.

After the mapping: rules the device adds per channel #

Getting the value to the channel is the mapping's whole job; what the channel does next belongs to the device, and a few channel classes add their own rules.

Relay and digital outputs carry none beyond the load circuit: once the variable maps and the driver communicates, the contact follows the variable.

Analog channels bind the same way and then add scaling, so a correct mapping alone still leaves the engineering value wrong until the scaling is configured — the M203 analog scaling and auto-cycle walkthrough covers that setup on its own page.

Front-panel pushbuttons bring one more rule: on the M203 the pushbutton commands need edge qualification before a button press behaves as a clean command, which the M203 edge-qualified pushbutton commands article details.

When a mapped output still does not move #

Let the symptom pick the next check instead of changing types or addresses by guesswork.

What you observe Where to look next
Variable changes, relay does not The driver's device status or communication diagnostics, then the output's supply and load path
Variable never changes Whether the row you bound is the channel your logic actually writes, and whether the downloaded program is in run
No Neuron device in the tree The installed package — put the UniPi Neuron for CODESYS package on instead of the generic Raspberry Pi one
Multi-register value reads garbled The match between the channel's configured type and the variable's type; move the handling into the Neuron library

Command one channel at a time, and only while its load is in a state where switching it cannot injure anyone or damage the machine. When the commanded variable moves and the physical output follows it, the mapping is proven; whatever remains is application logic or wiring, not mapping.

Questions asked

Do I need to write the Modbus TCP registers myself?

No. The Neuron driver runs the Modbus TCP conversation and the mapping is its interface, so application code never touches a register. Adding a second, hand-written client onto the same device puts two writers on one set of outputs, which is the same conflict pattern that produces oscillation through Modbus gateways. Keep every access on the mapped channels.

Does the Neuron library run for plain relay outputs too?

It does not need to. The library exists for values wider than one register; a relay or digital output maps as a boolean-typed variable straight in the I/O Mapping tab with no library call. Reach for the package's library only when a channel's Type column shows a value that cannot fit a single register.

Can two variables drive the same relay?

The mapping model gives each channel one variable slot. Bind a single variable to the relay and let both code paths write that variable. Alternating two variables on one channel leaves whichever binding was downloaded last in charge and makes the logic impossible to trace.

Why does the build complain after I bind the variable?

A binding or build error almost always means the variable's type does not match the type shown on the channel's row. Correct the declaration to match the device configuration. Do not widen the channel or copy an address from an unrelated project: the device description, not the application, defines the channel.

Keep reading

  • How-to

    Map CODESYS I/O for ladder and structured text use

    Map every physical channel once, in the I/O mapping dialog of the device in the project tree, to a named global variable. Ladder and structured text then reference the same variables, because the mapping belongs to the device, not to either language. Prove the link with one input and one output through the full field-device-to-program path before mapping the rest.

    Controllers and I/O

  • Troubleshooting

    Why a Micro850 will not read tags over a DF1 I/O server

    A Micro850 serves variables through a Modbus map you build in Connected Components Workbench, not through DF1 or ABLOGIX I/O servers, because its memory has no data-table files for those drivers to read. Map each variable, poll the mapped range with an independent Modbus client on unit identifier 1, and set the tag address to the offset that actually answers.

    Industrial networks

  • How-to

    Map physical I/O channels in CODESYS V3.5

    Add the device description for the controller and every I/O module, insert each module under the bus interface it physically hangs on, and bind channel to variable in the device's I/O Mapping tab. Match the variable's type to the channel's exposed type, convert raw values in code, and treat a successful login as proof of nothing about the I/O.

    PLC programming