FPosBAPI Backend
The FPosBAPI backend connects Python directly to a CECC-X PLC running the FPosBAPI CoDeSys server application. A single persistent TCP socket carries all motion commands for every axis of the gantry, serialised by an internal threading lock so concurrent Python threads cannot interleave frames.
Architecture
Three classes work together:
| Class | Responsibility |
|---|---|
FPosBAPIClient |
Opens and maintains the TCP socket; formats/parses ASCII frames; thread-safe via threading.Lock. |
FPosBAxis |
Represents one logical axis; translates move(), home(), and get_current_axis_position() into FPosBAPI commands. |
FPosBAPIGantryBackend |
Owns the shared FPosBAPIClient and backend-specific behavior (home, diagnostics, teach operations). |
Gantry |
Owns axis mapping and delegates backend behavior to FPosBAPIGantryBackend; dispatches movement queues. |
Wire Protocol
The server speaks a line-oriented ASCII protocol over TCP.
Request format
Response format
On success the last three comma-delimited fields are always 0, NULL, SUCCESS.
On error they carry a non-zero error id, an error type string, and a message string.
Example exchange for a move command:
FPosBAPIClient
FPosBAPIClient is instantiated once per gantry and shared across all axes.
You normally let Gantry.from_config create it; but for special use cases you can build it directly:
| Parameter | Type | Default | Description |
|---|---|---|---|
ip |
str |
— | IPv4 address of the CECC-X PLC. |
port |
int |
1234 |
TCP port the FPosBAPI server is listening on. |
timeout |
float \| None |
None |
Socket timeout in seconds; None = blocking, no timeout. |
Sending raw commands
send_command returns a list of all response lines received before the empty frame terminator.
It raises FPosBAPIClientError if the server reports an error or the connection is lost.
Reconnection behaviour
If the TCP connection drops mid-session, FPosBAPIClient performs exactly one automatic reconnect attempt before raising FPosBAPIClientError.
TCP keepalive is enabled on the socket (15 s idle time, 5 s interval) to detect silent link failures early.
Command wrappers available today
FPosBAPIClient provides typed wrappers around many PLC commands in addition to send_command, including:
- Motion:
enable,disable,home,move_pos,move_loc,halt,resume,abort - Teaching:
teach_pos,teach_tray,read_pos,write_pos,read_tray,write_tray - Diagnostics:
sys_status,is_error,fpb_error,read_err,err_log,com_log - Parameters / I/O:
get_par,set_par,get_io,set_io
FPosBAxis
FPosBAxis represents a single logical axis of the gantry.
It stores a 1-based axis index that must match the axis numbering in the CoDeSys program:
| Index | Axis |
|---|---|
1 |
X |
2 |
Y |
3 |
Z |
Construction (manual)
Moving an axis
Note on velocity:
move()writes the velocity to PLC parameter 103 (global speed) immediately before theMOVE_AXIScommand. When axes move concurrently the two commands are not atomic — use sequential moves when per-move velocity accuracy matters.
Reading the current position
Homing
Homing via a single axis proxy sends the HOME command to the PLC, which always
homes all axes simultaneously. Prefer Gantry.home() to avoid issuing the
command more than once.
Drive-ready state and homed state
FPosBAxis.ready_for_motion() queries IS_ENBL, and FPosBAxis.is_homed() queries IS_HOME.
Gantry (FPosBAPI mode)
From a configuration file
from_config reads the backend key, creates one FPosBAPIClient, sends
an initial ENABLE command to verify the connection, then wraps each axis entry
in an FPosBAxis proxy.
Supported config keys
| Key | Required | Description |
|---|---|---|
backend |
Yes | Must be "fposbapi" to select this backend. |
interface.ip |
Yes | IPv4 address of the CECC-X PLC. |
interface.port |
No | TCP port (default 1234). |
axes |
Yes | Dict of axis name → {name, index}. |
axis_order |
No | Ordered list of axis names; defaults to dict insertion order. |
concurrent_axes |
No | List of axis names allowed to move simultaneously, or null. |
Full config file layout (spec version 3.0)
from_config also accepts the full Festo component config schema used in production:
When the top-level component_config key is present, from_config scopes
automatically to component_config.components.<name> (default "gantry_1").
Gantry API Reference
Gantry.home()
Sends a single HOME command via the shared FPosBAPIClient. All axes home
simultaneously on the PLC side.
Gantry.move_to(movements, timeout=None, concurrent=False)
Dispatches a queue of movement dicts to the gantry axes.
Each dict maps one axis name to its kinematic parameters.
move_to parameter |
Description |
|---|---|
movements |
deque of {axis_name: {position, velocity}} dicts. |
timeout |
Per-move time limit in seconds, or None. |
concurrent |
True to dispatch all valid movements in one parallel batch. |
When concurrent=False, the gantry still uses concurrent_axes grouping from config:
- axes listed in
concurrent_axesmay run in the same batch, - axes not in that set are dispatched as individual batches.
Gantry.get_location()
Returns a dict of axis name → current position (mm) by querying each axis.
Gantry.get_status()
Returns backend metadata, per-axis states, and controller diagnostics.
Teaching helpers and command discovery
For FPosBAPI backends:
Error Handling
All FPosBAPI errors surface as FPosBAPIClientError.
Motion failures at the Gantry level raise MovementError, which wraps the underlying exception.