Getting Started with C++#
The Synergy C++ library drives the SLM backplane with no interpreter and no
dependencies beyond the C++ standard library. Where timing matters, it is the
appropriate choice.
Where the library is#
The C++ library, its examples and a preconfigured build directory are supplied
on the desktop of the slm-rp4 user:
~/Desktop/synergy_cpp/
├── main.cpp your program
├── CMakeLists.txt build definition
├── build/ run make here; the executable appears here
├── examples/ worked examples for each module type
└── lib/
├── synergy/ the backplane library
└── rpi_ws281x/ drives the RGB indicator
You edit main.cpp, build in build/, and run the resulting executable. See
C++: Building.
Prerequisites#
The toolchain and CMake are preinstalled. The library communicates with
/dev/spidev6.0 and /dev/gpiochip0 through the standard Linux kernel
interfaces, so there are no third-party packages to install and nothing
additional to link. The exception is the RGB LED, which needs libws2811.a;
see C++: Building.
Confirm the interfaces are present:
ls -l /dev/spidev6.0 /dev/gpiochip0
If /dev/spidev6.0 is missing, the backplane interface has been lost. See
Troubleshooting.
Build on the device#
Build on the SLM-RP4 itself. It compiles this project comfortably, and the supplied build directory is already configured. Cross-compiling from a workstation is possible but offers little benefit.
If you prefer to work from your own machine, use Visual Studio Code with the Remote - SSH extension, which edits and builds on the device while presenting the project locally. See Accessing the Device.
Before you run anything#
Stop the PLC first
The OpenPLC Runtime holds the backplane while the PLC is running. Press Stop in OpenPLC Editor before running your program. See Sharing the Hardware.
Permissions#
The program needs read and write access to /dev/spidev6.0 and
/dev/gpiochip0. The slm-rp4 user belongs to the spi and gpio groups, so
backplane access requires no sudo.
Driving the RGB indicator is the exception and requires root. Because the
supplied main.cpp includes the indicator library, the example program is run
with sudo. See Onboard Peripherals.
Next#
C++: Building, covering how to compile and run a program.