Constraint: No External/InOut Ports in PLCnext C++
Defining external (InOut) ports in a C++ program on the PLCnext platform is not currently possible. A C++ input port such as rxBuffer[] therefore cannot be cleared directly from the C++ side by writing back through a port reference. Buffer management that requires modifying the connected port variable must be delegated to code running in PLCnext Engineer, for example a Structured Text (ST) program.
Workaround: Clearing the Buffer from ST Code
The supported workflow uses two additional C++ outputs — a boolean and an integer — to hand the buffer state and index to the ST program, which performs the actual clear on the port variable connected to the C++ input port:
- In the C++ program, copy the buffer element to the
processMsgvariable. - Set
xUsedtofalsein the C++ program. - Transfer the state of
xUsedand the element number to be cleared to the ST code in PLCnext Engineer via the C++ output boolean and output integer. - In the ST code, clear the element in the port variable connected to the C++ input port
rxBuffer[]. This also clears the correspondingrxBufferelement in the C++ code.
Interface Design Between C++ and ST
The C++ program must expose the handshake data as ports so the ST logic can act on it. The minimal interface derived from the workflow is:
| Port | Direction (C++ side) | Purpose |
|---|---|---|
rxBuffer[] |
Input | Receive buffer; elements are cleared by ST on the connected port variable |
| Output boolean | Output | Transfers the xUsed state to the ST code after the message is copied |
| Output integer | Output | Transfers the element number that needs to be cleared |
The ST program reads the boolean and integer, then clears the indexed element in its own port variable wired to rxBuffer[]. Because the clear happens on the connected port variable, the change propagates back to the C++ input buffer without any InOut port.
Verification
After the ST code clears the element, confirm in the C++ program that the corresponding rxBuffer[] element no longer holds the copied message and that xUsed remains false. If the element is not cleared, check that the ST port variable is correctly connected to the C++ input port and that the element number transferred matches the index copied into processMsg.
FAQ
Can a PLCnext C++ program define external or InOut ports?
No. Defining external/InOut ports in C++ is currently not possible; any logic that must write back to a connected port variable has to run in PLCnext Engineer, such as a Structured Text program.
How do I clear an rxBuffer element from a PLCnext C++ program?
Copy the element to your processMsg variable, set xUsed to false, then pass the xUsed state and element number to ST code via a C++ output boolean and output integer. The ST code clears the element in the port variable connected to rxBuffer[], which also clears it in the C++ code.
What C++ ports are needed for the PLCnext buffer-clear handshake?
Two additional outputs are required: a boolean carrying the xUsed state and an integer carrying the element number to be cleared, alongside the existing rxBuffer[] input port.