Configuring CoDeSys Symbolic Aliases for Packed I/O Bits

Patricia Callen8 min read
Other ManufacturerPLC HardwareTechnical Reference
Licensed PE Working through this on a live machine? A Maine-licensed engineer can take it from here — included with IMD hardware, by the hour for everything else. Book an engineer

After the fix, each packed input bit has one readable application name, while the received byte remains the single communication value. The correct implementation depends on whether the programming environment supports a true alias to a relocatable bit expression, only an alias to a complete tag, or no alias mechanism at all. Follow the signal from the RS485 receive buffer through the packed byte and into the Boolean logic before changing declarations.

What value arrives from the serial interface?

Start with the online value of MyByte. A serial device that represents eight digital inputs in one byte transports a packed value; the controller receives that byte before the application interprets its individual bits. Confirm that the byte changes as expected when each physical input changes. If the packed byte is wrong or static, symbolic naming cannot repair the fault.

Signal Source Wrong-value symptom
Physical input Expansion I/O channel The expected bit never changes at the source.
RS485 payload byte Proprietary serial peripheral The received value is static, shifted, stale, or assigned to the wrong byte.
MyByte.0 through MyByte.7 Bit selection from MyByte The byte changes, but the application observes the wrong input.
Application Boolean such as Start Alias, mapped Boolean, or explicit assignment The selected bit is correct, but the named signal does not follow it.

Look at the trend first. Exercise one field input at a time and record the received hexadecimal or binary value. That test identifies the protocol bit position without relying on the label shown by a configurator. It also catches reversed channel numbering, an incorrect register offset, and updates being written into a different byte.

Does direct bit selection already solve the access problem?

For an integer variable that supports indexed bit access, notation such as MyByte.3 selects one bit without allocating another protocol byte. The same pattern was described for integer tags as Pippo.0 and Pippo.1. A named constant may also provide the bit index:

VAR_GLOBAL CONSTANT
    enable : INT := 2;
END_VAR

xxx.enable := TRUE;

Here, enable represents the bit index, so xxx.enable addresses the third bit of xxx. This improves the meaning of the index but does not create an independent Boolean alias named enable. Code must still qualify the selector with the packed variable.

Check this branch in the editor and compiler. If MyByte.3 compiles and follows the intended input online, the storage and bit-selection layers work. Continue to the naming check. If it does not compile, inspect the declared scalar type and the platform's supported bit-access syntax; changing the symbol table will not make an unsupported expression valid.

Is the requested name a type, an address, or an alias?

These mechanisms solve different problems. A type declaration defines the form of future variables; it does not rename an expression. That is why an attempted declaration such as TYPE MyBit : Pippo.0; is the wrong mechanism: Pippo.0 is a selected storage location, not a data type.

An located declaration binds a variable to an absolute memory or I/O address. The example MyBit AT %IB1.2 : BOOL; gives a Boolean name to a particular input bit. It is useful when that absolute address is the authoritative storage location. It does not, by itself, bind MyBit to a bit inside any relocatable variable chosen later by the compiler.

A true expression alias would make Start refer directly to MyByte.3. Whether that feature exists, and whether it accepts a bit expression rather than only a whole tag, is an editor and compiler capability. IEC 61131-3 language structure does not make every editor expose the same symbol-management feature.

Does the alias function target the bit or the complete tag?

Inspect the declaration or symbol editor rather than inferring behavior from a column called Alias For. Some environments associate a second name with the same complete integer tag. If an INT tag receives an alias, the alias remains an INT; its bits are still selected as Alias.0, Alias.1, and so on. That is not a Boolean alias to one bit.

Run a compile-time test with a temporary declaration. Select MyByte.3 as the alias target and declare or infer the target as BOOL. Three outcomes have distinct meanings:

  1. If the editor accepts the bit expression and the online Boolean follows only bit 3, use the native alias feature.
  2. If the editor accepts only MyByte and exposes the alias as BYTE, it aliases the complete tag. Continue using a qualified selector or create an explicit Boolean mapping.
  3. If the editor rejects relocatable variables but accepts an absolute expression such as %IB1.2, its located-variable mechanism cannot provide the requested alias for a compiler-placed byte.

Do not evaluate the result only by its displayed label. Check the compiled data type, cross-reference list, online value, and write behavior. A text substitution, a tag alias, and a copied Boolean may look similar in ladder or a watch window while producing different ownership and update semantics.

Where should proprietary RS485 channel names live?

Keep communication ownership separate from application naming. The driver or firmware should update the complete received byte. A mapping layer should then expose the channel meanings used by the PLC program. This mirrors the useful behavior of an integrated I/O configurator without making the protocol handler depend on application names.

The configuration data must identify at least the received byte, the bit index, and the application symbol. Validate the actual bit order from the peripheral definition and the observed receive value. Serial byte order across multiple bytes and bit numbering within one byte are separate questions; a correct byte offset can still select the wrong channel bit.

If an external executable generates importable declarations, treat its output as generated interface code. Regenerate it from one definition file instead of manually editing both the external mapping and the PLC declarations. If the environment provides an integrated device description or symbol import facility, use it to reduce duplicate entry, but verify the resulting target type and expression after import.

How should the Boolean interface be implemented without a bit alias?

Use explicit Boolean assignments when the compiler cannot alias a relocatable bit. This adds named variables, but it creates a clear boundary between the packed transport representation and the application interface:

VAR_GLOBAL
    MyByte : BYTE;
    Start  : BOOL;
END_VAR

Start := MyByte.3;

Execute the mapping after the communication layer updates MyByte and before the consuming control logic runs. The final element then sees Start, while diagnostics retain access to the complete received byte. For multiple inputs, assign each named Boolean from its documented bit position in one mapping section.

This is a one-way unpacking pattern. Do not write both Start and MyByte.3 from different program sections. Multiple writers create scan-order behavior: the value observed by later logic depends on which assignment ran last. For output bytes, reverse the direction deliberately by assembling named commands into the transmitted byte at one defined point.

If retaining separate Boolean variables is unacceptable, use qualified symbolic indices such as MyByte.enable where supported. That approach keeps one storage object, but every reference must include the byte name and the index constants must remain unique and within the width of the packed type.

What procedure proves the mapping from input to logic?

  1. Place MyByte, its binary representation, the selected expression such as MyByte.3, and the application Boolean in one online watch or trend view.
  2. Hold all field inputs inactive, then activate one channel. Record which bit changes in the received byte. Repeat for every channel that will receive a symbolic name.
  3. Compare the observed positions with the proprietary RS485 channel definition. Correct the byte offset or bit index before changing application logic.
  4. Compile the native alias test. Confirm whether its target type is BOOL and whether its cross-reference points to the bit expression or only to the complete byte.
  5. If bit aliases are unsupported, add one-way assignments from the packed byte to named Boolean variables. Place the mapping between the communication update and the control logic.
  6. Run the input exercise again. Confirm that each physical input changes one intended bit, that the selected expression follows it, and that the named Boolean changes in the same scan sequence.
  7. Search the project for writes to the received byte, the selected bit, and the mapped Boolean. Remove unintended writers or define one authoritative writer for each signal.

Tuning does not fix wiring, protocol offsets, or mapping order. If MyByte is already wrong, work backward through the receive buffer, byte selection, device address, and physical input. If the byte is correct but Start is wrong, remain in the bit-selection and mapping layers.

How is the final mapping verified under operating conditions?

Verification must cover initialization and repeated communication updates, not only one forced value. Restart the controller or application and confirm that the packed byte and named Booleans enter defined states. Restore communication, operate each input, and watch for stale values when messages stop or become invalid. The failure-state policy belongs in the communication layer; the application should not silently continue using an old input byte unless that behavior is intentional.

Retest after declaration imports or regenerated files. Confirm that symbolic names still point to the intended byte and bit, because a successful import proves syntax acceptance but not channel correctness. Archive the byte-to-bit map beside the peripheral definition so firmware, PLC declarations, and application logic share one channel assignment.

FAQ

How do I give MyByte.3 a Boolean name in CoDeSys?

First test whether the installed editor and compiler accept a BOOL alias whose target is MyByte.3. If they accept only whole-tag aliases or absolute located variables, declare a Boolean such as Start and assign Start := MyByte.3; in one mapping section.

How do I use a symbolic bit index without declaring another Boolean?

Declare a global constant such as enable : INT := 2 and use xxx.enable where that compiler supports symbolic bit indices. The expression selects the third bit but still requires the packed variable name.

How do I tell whether Alias For aliases one bit?

Check the target accepted by the editor and the resulting data type. If an alias of an INT remains an INT and requires Alias.0, the feature aliases the complete tag rather than one Boolean bit.

How do I know when to stop troubleshooting the PLC mapping?

Stop adjusting the mapping when the received byte is wrong before bit selection, or when the compiler rejects a minimal relocatable-bit alias test and its documentation does not define such a feature. Capture the declaration, compiler message, target type, software version shown by the installed environment, and an online trace of MyByte before escalating. Contact the platform's official support channel to confirm compiler-specific alias capability or diagnose the communication driver.

Back to blog