Files
Codesys-Library-Atom-Modbus/codesys/BUILD_ON_PI.md
T
2026-09-30 21:17:41 -06:00

3.4 KiB

Ready-to-build component, generated interface validated

The supplied CmpAtomModbus.c and CmpAtomModbusItf.m4 were inspected and the C stub implemented. The M4 file is unchanged. External registration metadata: signature 0x709EE65B, version 0x00020000 (0.2.0.0).

This source bundle is revision 0.3; the IEC library/component version remains 0.2.0.0 to match your generated interface. Do not change it independently.

Build

Copy/extract this source folder and your ExtensionSDK onto the Pi:

~/modbus-build/atom-modbus/
~/modbus-build/ExtensionSDK/

Then:

sudo apt-get install build-essential m4 sed dos2unix make
cd ~/modbus-build/atom-modbus
make -C component SDKDIR="$(realpath sdk/ExtensionSDK)" all
file component/out/libCmpAtomModbus.so
nm -D component/out/libCmpAtomModbus.so | sed -n '/ComponentEntry/p; /atmbcall_cext/p'

Expected: AArch64 shared object; ComponentEntry and atmbcall_cext exported. You do NOT need to run the preparation script: component/ is already prepared. The original generated files are retained in generated/ for reference.

Install during a bench-test maintenance window

Stop your PLC application safely first. Keep a backup of the configuration.

sudo cp /etc/CODESYSControl_User.cfg /etc/CODESYSControl_User.cfg.before-atom-modbus
sudo /etc/init.d/codesyscontrol stop
sudo cp component/out/libCmpAtomModbus.so /usr/lib/libCmpAtomModbus.so
sudo nano /etc/CODESYSControl_User.cfg

Under the existing [ComponentManager] section add:

Component.N=CmpAtomModbus

Replace N with an unused numeric component index. Do not add a duplicate section or overwrite another component. Development component ID is 0xffff2001; ensure it does not collide with another custom component.

sudo /etc/init.d/codesyscontrol start
sudo tail -n 80 /var/log/codesyscontrol.log

Verify the component loads with no interface/signature/version errors. Save and install your CmpAtomModbus IEC library in CODESYS' Library Repository, then add it to a separate Raspberry Pi test project's Library Manager.

Read-only PLC test

Create an ST PROGRAM PLC_PRG. Add the SysTime library. Paste PLC_PRG_declaration.st in its declaration pane and PLC_PRG_implementation.st in its implementation pane. Ensure PLC_PRG is called by one cyclic task, e.g. 10 ms. Namespace-qualify atMbCall_cext if required.

Set the IP, unit ID and zero-based start address for a device with at least ten readable holding registers. Download, start and set run=TRUE in the watch window. Inspect status[1] (state), callResult, registers, readDone, successfulReadCount, dataStale and requestErrorCount. Unplug and restore Ethernet or restart the device to exercise recovery. status[11] counts additional connection attempts.

Set run=FALSE and let the program scan until handle=0 before stopping, downloading or making online changes. Automatic application lifecycle cleanup and the original atMb scheduler migration are still pending; this is a bench program, not yet a production replacement. RTU is not implemented.

Verification scope

Native engine/bridge tests passed locally. The real generated parameter struct and function implementation were compiled against the supplied SDK headers on the x86-64 development host. Full SDK/M4 registration build and execution on the ARM64 Pi remain to be verified. No precompiled Pi binary is included. The ST example has not been compiled in the CODESYS IDE here.