fposbapi_client
fposbapi_client
Thread-safe ASCII TCP socket client for the Festo FPosBAPI server.
The FPosBAPI server runs on the Festo CECC-X PLC (CoDeSys) and listens on TCP port 1234. It speaks a line-oriented ASCII protocol::
1 2 | |
On success the last three comma-delimited fields are 0, NULL, SUCCESS.
On error the last three fields carry a non-zero error id, type string, and
message string.
A single FPosBAPIClient instance should be shared across all
FPosBAxis objects belonging
to the same gantry, and is owned by Gantry.
All send/receive operations are serialised through an internal
threading.Lock.
FPosBAPIClientError
Bases: Exception
Raised when the FPosBAPI server returns an error response or the connection is lost.
FPosBAPICommunicationError
Bases: FPosBAPIClientError
Raised when a transport or protocol-level failure occurs (socket, framing, ID mismatch).
FPosBAPICommandError
Bases: FPosBAPIClientError
Raised when the PLC returns a structurally valid but non-SUCCESS response.
FPosBAPIClient
Thread-safe TCP socket client for the Festo FPosBAPI ASCII protocol.
Connects to the CECC-X PLC on ip:port and wraps the request/response
cycle in send_command. A threading.Lock serialises all
socket I/O so multiple FPosBAxis
objects sharing the same client do not interleave their frames.
Attributes:
| Name | Type | Description |
|---|---|---|
ip |
IPv4 address of the CECC-X TCP server. |
|
port |
TCP port of the FPosBAPI server (default |
Connect to the FPosBAPI server.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ip
|
str
|
IPv4 address of the CECC-X PLC. |
required |
port
|
int
|
TCP port the FPosBAPI server is listening on. Defaults to
|
1234
|
timeout
|
float | None
|
Socket timeout in seconds. Applied to both |
None
|
Raises:
| Type | Description |
|---|---|
OSError
|
If the TCP connection cannot be established within timeout seconds. |
Source code in src/applied_motion/backends/fposbapi_client.py
send_command
Send a command to the FPosBAPI server and return all response lines.
Acquires the internal lock, increments the message ID, formats the
ASCII request frame, sends it, then reads lines via
_collect_response until the terminal (non-ACK) line
arrives. The terminal (last) line is validated for correct MSG_ID
echo, CMD echo, and SUCCESS status before returning.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
command
|
str
|
FPosBAPI command string, e.g. |
required |
*params
|
Zero or more positional parameters appended to the frame. |
()
|
|
timeout
|
float | None | _Unset
|
Per-call socket timeout in seconds. Pass |
_UNSET
|
Returns:
| Type | Description |
|---|---|
list[str]
|
All response lines received before the empty terminator, in arrival |
list[str]
|
order. The last element is always the terminal status line echoing |
list[str]
|
the command and carrying |
Raises:
| Type | Description |
|---|---|
FPosBAPIClientError
|
If the server returns an error status, the echoed MSG_ID or command name does not match what was sent, the response is empty, or the connection is closed. |
Source code in src/applied_motion/backends/fposbapi_client.py
try_command
Send a command; raise on communication failure, return bool for PLC result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
command
|
str
|
FPosBAPI command string, e.g. |
required |
*params
|
Zero or more positional parameters. |
()
|
|
timeout
|
float | None | _Unset
|
Per-call socket timeout forwarded to |
_UNSET
|
Returns:
| Type | Description |
|---|---|
bool
|
|
bool
|
returns a valid but non-SUCCESS response. |
Raises:
| Type | Description |
|---|---|
FPosBAPICommunicationError
|
If a transport or protocol-level failure occurs. |
Source code in src/applied_motion/backends/fposbapi_client.py
get_veab
Get the pressure set value of the VEAB.
Source code in src/applied_motion/backends/fposbapi_client.py
set_veab
list_commands
Query the server for its supported command set via CMD_LIST.
Sends CMD_LIST and parses the response to extract the command
names the connected FPosBAPI server advertises. The set varies
between firmware versions, so callers can use this to feature-detect
before issuing optional commands (e.g. IS_HOME, SYS_STATUS).
Response layout assumed::
1 | |
The first two fields (MSG_ID and CMD_LIST) and the last
three (error fields ending with SUCCESS) are stripped; the
remaining fields are returned as a list of command name strings.
Returns:
| Type | Description |
|---|---|
list[str]
|
List of command name strings advertised by the server, |
list[str]
|
e.g. |
Raises:
| Type | Description |
|---|---|
FPosBAPIClientError
|
If the server returns an error response or the connection is lost. |
Source code in src/applied_motion/backends/fposbapi_client.py
enable
Enable the gantry drives via ENABLE.
Raises:
| Type | Description |
|---|---|
FPosBAPIClientError
|
If the server returns an error response or the connection is lost. |
Source code in src/applied_motion/backends/fposbapi_client.py
disable
Disable the gantry drives via DISABLE.
Raises:
| Type | Description |
|---|---|
FPosBAPIClientError
|
If the server returns an error response or the connection is lost. |
Source code in src/applied_motion/backends/fposbapi_client.py
home
Home all axes via HOME.
Raises:
| Type | Description |
|---|---|
FPosBAPIClientError
|
If the server returns an error response or the connection is lost. |
Source code in src/applied_motion/backends/fposbapi_client.py
move_pos
Execute a motion sequence to a stored position via MOVE_POS.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pos_id
|
int
|
Position record ID (1-100). |
required |
tool_id
|
int
|
Tool index to apply. |
0
|
retract_z
|
int
|
|
0
|
slow_app
|
int
|
|
0
|
Raises:
| Type | Description |
|---|---|
FPosBAPIClientError
|
If the server returns an error response or the connection is lost. |
Source code in src/applied_motion/backends/fposbapi_client.py
move_loc
move_loc(
a1: float,
a2: float,
a3: float,
tool_id: int = 0,
move_typ: int = 0,
retract_z: int = 0,
slow_app: int = 0,
) -> None
Execute a coordinated 3-axis move to explicit coordinates via MOVE_LOC.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
a1
|
float
|
Target X-axis position in mm. |
required |
a2
|
float
|
Target Y-axis position in mm. |
required |
a3
|
float
|
Target Z-axis position in mm. |
required |
tool_id
|
int
|
Tool offset to apply. |
0
|
move_typ
|
int
|
|
0
|
retract_z
|
int
|
|
0
|
slow_app
|
int
|
|
0
|
Raises:
| Type | Description |
|---|---|
FPosBAPIClientError
|
If the server returns an error response or the connection is lost. |
Source code in src/applied_motion/backends/fposbapi_client.py
move_path
Execute the programmed motion path via MOVE_PATH.
Raises:
| Type | Description |
|---|---|
FPosBAPIClientError
|
If the server returns an error response or the connection is lost. |
Source code in src/applied_motion/backends/fposbapi_client.py
halt
Halt the current motion via HALT.
Raises:
| Type | Description |
|---|---|
FPosBAPIClientError
|
If the server returns an error response or the connection is lost. |
Source code in src/applied_motion/backends/fposbapi_client.py
resume
Resume a halted motion via RESUME.
Raises:
| Type | Description |
|---|---|
FPosBAPIClientError
|
If the server returns an error response or the connection is lost. |
Source code in src/applied_motion/backends/fposbapi_client.py
abort
Abort the current motion via ABORT.
Raises:
| Type | Description |
|---|---|
FPosBAPIClientError
|
If the server returns an error response or the connection is lost. |
Source code in src/applied_motion/backends/fposbapi_client.py
reset_err
Reset the active error via RESET_ERR.
Raises:
| Type | Description |
|---|---|
FPosBAPIClientError
|
If the server returns an error response or the connection is lost. |
Source code in src/applied_motion/backends/fposbapi_client.py
open_valve
open_valve(
v1_time: int = 0,
v2_time: int = 0,
v3_time: int = 0,
v4_time: int = 0,
v5_time: int = 0,
v6_time: int = 0,
v7_time: int = 0,
v8_time: int = 0,
) -> None
Open one or more valves for the specified durations via OPEN_VALVE.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
v1_time
|
int
|
Valve 1 open duration in ms. |
0
|
v2_time
|
int
|
Valve 2 open duration in ms. |
0
|
v3_time
|
int
|
Valve 3 open duration in ms. |
0
|
v4_time
|
int
|
Valve 4 open duration in ms. |
0
|
v5_time
|
int
|
Valve 5 open duration in ms. |
0
|
v6_time
|
int
|
Valve 6 open duration in ms. |
0
|
v7_time
|
int
|
Valve 7 open duration in ms. |
0
|
v8_time
|
int
|
Valve 8 open duration in ms. |
0
|
Raises:
| Type | Description |
|---|---|
FPosBAPIClientError
|
If the server returns an error response or the connection is lost. |
Source code in src/applied_motion/backends/fposbapi_client.py
read_pos
Read the stored absolute position for pos_id via READ_POS.
Response layout::
1 | |
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pos_id
|
int
|
Position record ID (1-100). |
required |
Returns:
| Type | Description |
|---|---|
tuple[float, float, float]
|
Tuple of |
Raises:
| Type | Description |
|---|---|
FPosBAPIClientError
|
If the server returns an error response or the connection is lost. |
RuntimeError
|
If the response cannot be parsed. |
Source code in src/applied_motion/backends/fposbapi_client.py
teach_pos
Save the current axis positions to pos_id via TEACH_POS.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pos_id
|
int
|
Position record ID to write (1-100). |
required |
tool_id
|
int
|
Tool offset to associate with this position. |
1
|
Raises:
| Type | Description |
|---|---|
FPosBAPIClientError
|
If the server returns an error response or the connection is lost. |
Source code in src/applied_motion/backends/fposbapi_client.py
write_pos
Write absolute axis coordinates to pos_id via WRITE_POS.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pos_id
|
int
|
Position record ID to write (1-100). |
required |
abs_a1
|
float
|
Absolute X-axis position in mm. |
required |
abs_a2
|
float
|
Absolute Y-axis position in mm. |
required |
abs_a3
|
float
|
Absolute Z-axis position in mm. |
required |
Raises:
| Type | Description |
|---|---|
FPosBAPIClientError
|
If the server returns an error response or the connection is lost. |
Source code in src/applied_motion/backends/fposbapi_client.py
mod_pos
Modify a stored position by relative offsets via MOD_POS.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pos_id
|
int
|
Position record ID to modify (1-100). |
required |
rel_a1
|
float
|
Relative X-axis offset in mm. |
required |
rel_a2
|
float
|
Relative Y-axis offset in mm. |
required |
rel_a3
|
float
|
Relative Z-axis offset in mm. |
required |
Raises:
| Type | Description |
|---|---|
FPosBAPIClientError
|
If the server returns an error response or the connection is lost. |
Source code in src/applied_motion/backends/fposbapi_client.py
write_path
Write one waypoint along the motion path via WRITE_PATH.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pa_pos_id
|
int
|
Path position index (1-10). |
required |
abs_a1
|
float
|
Absolute X-axis position in mm. |
required |
abs_a2
|
float
|
Absolute Y-axis position in mm. |
required |
abs_a3
|
float
|
Absolute Z-axis position in mm. |
required |
Raises:
| Type | Description |
|---|---|
FPosBAPIClientError
|
If the server returns an error response or the connection is lost. |
Source code in src/applied_motion/backends/fposbapi_client.py
read_path
Read one waypoint from the motion path via READ_PATH.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pa_pos_id
|
int
|
Path position index (1-10). |
required |
Returns:
| Type | Description |
|---|---|
tuple[float, float, float]
|
Tuple of |
Raises:
| Type | Description |
|---|---|
FPosBAPIClientError
|
If the server returns an error response or the connection is lost. |
RuntimeError
|
If the response cannot be parsed. |
Source code in src/applied_motion/backends/fposbapi_client.py
sys_status
Return the system status string via SYS_STATUS.
Response layout::
1 | |
Returns:
| Type | Description |
|---|---|
str
|
Status string reported by the PLC (e.g. |
Raises:
| Type | Description |
|---|---|
FPosBAPIClientError
|
If the server returns an error response or the connection is lost. |
RuntimeError
|
If the response cannot be parsed. |
Source code in src/applied_motion/backends/fposbapi_client.py
is_error
Return whether the gantry is in an error state via IS_ERROR.
Response layout::
1 | |
Returns:
| Type | Description |
|---|---|
bool
|
|
Raises:
| Type | Description |
|---|---|
FPosBAPIClientError
|
If the server returns an error response or the connection is lost. |
RuntimeError
|
If the response cannot be parsed. |
Source code in src/applied_motion/backends/fposbapi_client.py
fpb_error
Return the fieldbus error state via FPB_ERROR.
Response layout::
1 | |
Returns:
| Type | Description |
|---|---|
str
|
Raw status string from the terminal response field. |
Raises:
| Type | Description |
|---|---|
FPosBAPIClientError
|
If the server returns an error response or the connection is lost. |
Source code in src/applied_motion/backends/fposbapi_client.py
read_err
Return the current error description via READ_ERR.
Returns:
| Type | Description |
|---|---|
str
|
The raw terminal response line from the server. |
Raises:
| Type | Description |
|---|---|
FPosBAPIClientError
|
If the server returns an error response or the connection is lost. |
Source code in src/applied_motion/backends/fposbapi_client.py
err_log
Return the error log entries via ERR_LOG.
The server may return multiple intermediate lines before the terminal SUCCESS line. All non-terminal lines are returned as the log.
Returns:
| Type | Description |
|---|---|
list[str]
|
List of error log strings (all lines except the terminal status). |
Raises:
| Type | Description |
|---|---|
FPosBAPIClientError
|
If the server returns an error response or the connection is lost. |
Source code in src/applied_motion/backends/fposbapi_client.py
com_log
Return the communication log entries via COM_LOG.
The server may return multiple intermediate lines before the terminal SUCCESS line. All non-terminal lines are returned as the log.
Returns:
| Type | Description |
|---|---|
list[str]
|
List of communication log strings (all lines except the terminal status). |
Raises:
| Type | Description |
|---|---|
FPosBAPIClientError
|
If the server returns an error response or the connection is lost. |
Source code in src/applied_motion/backends/fposbapi_client.py
err_desc
Return the error description via ERR_DESC.
Returns:
| Type | Description |
|---|---|
str
|
Raw terminal response line from the server. |
Raises:
| Type | Description |
|---|---|
FPosBAPIClientError
|
If the server returns an error response or the connection is lost. |
Source code in src/applied_motion/backends/fposbapi_client.py
get_io
Return the value of an I/O channel via GET_IO.
Response layout::
1 | |
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
io_id
|
int
|
I/O channel ID. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Current value of the I/O channel. |
Raises:
| Type | Description |
|---|---|
FPosBAPIClientError
|
If the server returns an error response or the connection is lost. |
RuntimeError
|
If the response cannot be parsed. |
Source code in src/applied_motion/backends/fposbapi_client.py
set_io
Set the value of an I/O channel via SET_IO.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
io_id
|
int
|
I/O channel ID. |
required |
value
|
float
|
Value to write to the I/O channel. |
required |
Raises:
| Type | Description |
|---|---|
FPosBAPIClientError
|
If the server returns an error response or the connection is lost. |
Source code in src/applied_motion/backends/fposbapi_client.py
get_par
Return parameter values for par_id via GET_PAR.
The FPosBAPI server returns up to four value fields per parameter (e.g. tray parameters include column count, column offset, row count, and row offset). Fields that are absent or non-numeric are omitted from the returned list.
Response layout::
1 | |
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
par_id
|
int
|
Parameter ID (see API Rev 5 Parameter ID sheet). |
required |
Returns:
| Type | Description |
|---|---|
list[float]
|
List of up to four float values for the requested parameter. |
Raises:
| Type | Description |
|---|---|
FPosBAPIClientError
|
If the server returns an error response or the connection is lost. |
Source code in src/applied_motion/backends/fposbapi_client.py
set_par
Write one or more values to parameter par_id via SET_PAR.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
par_id
|
int
|
Parameter ID (see API Rev 5 Parameter ID sheet). |
required |
*values
|
float
|
Up to four values to write to the parameter. |
()
|
Raises:
| Type | Description |
|---|---|
FPosBAPIClientError
|
If the server returns an error response or the connection is lost. |
Source code in src/applied_motion/backends/fposbapi_client.py
teach_tray
Save the current axis positions as a tray position via TEACH_TRAY.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tray_id
|
int
|
Tray ID (1-20). |
required |
tray_pos
|
int
|
Position within the tray to teach. |
required |
tool_id
|
int
|
Tool offset to associate with this position. |
0
|
Raises:
| Type | Description |
|---|---|
FPosBAPIClientError
|
If the server returns an error response or the connection is lost. |
Source code in src/applied_motion/backends/fposbapi_client.py
write_tray
Write absolute coordinates to a tray position via WRITE_TRAY.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tray_id
|
int
|
Tray ID (1-20). |
required |
tray_pos
|
int
|
Position index within the tray. |
required |
abs_a1
|
float
|
Absolute X-axis position in mm. |
required |
abs_a2
|
float
|
Absolute Y-axis position in mm. |
required |
abs_a3
|
float
|
Absolute Z-axis position in mm. |
required |
Raises:
| Type | Description |
|---|---|
FPosBAPIClientError
|
If the server returns an error response or the connection is lost. |
Source code in src/applied_motion/backends/fposbapi_client.py
read_tray
Read the stored coordinates of a tray position via READ_TRAY.
Response layout::
1 | |
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tray_id
|
int
|
Tray ID (1-20). |
required |
tray_pos
|
int
|
Position index within the tray. |
required |
Returns:
| Type | Description |
|---|---|
tuple[float, float, float]
|
Tuple of |
Raises:
| Type | Description |
|---|---|
FPosBAPIClientError
|
If the server returns an error response or the connection is lost. |
RuntimeError
|
If the response cannot be parsed. |
Source code in src/applied_motion/backends/fposbapi_client.py
mod_tray
Modify a stored tray position by relative offsets via MOD_TRAY.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tray_id
|
int
|
Tray ID (1-20). |
required |
tray_pos
|
int
|
Position index within the tray. |
required |
rel_a1
|
float
|
Relative X-axis offset in mm. |
required |
rel_a2
|
float
|
Relative Y-axis offset in mm. |
required |
rel_a3
|
float
|
Relative Z-axis offset in mm. |
required |
Raises:
| Type | Description |
|---|---|
FPosBAPIClientError
|
If the server returns an error response or the connection is lost. |
Source code in src/applied_motion/backends/fposbapi_client.py
move_tray
move_tray(
tray_id: int,
tray_col: int,
tray_row: int,
tool_id: int = 0,
retract_z: int = 0,
slow_app: int = 0,
) -> None
Move the gantry to a tray location via MOVE_TRAY.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tray_id
|
int
|
Tray ID (1-20). |
required |
tray_col
|
int
|
Target column within the tray. |
required |
tray_row
|
int
|
Target row within the tray. |
required |
tool_id
|
int
|
Tool offset to apply. |
0
|
retract_z
|
int
|
|
0
|
slow_app
|
int
|
|
0
|
Raises:
| Type | Description |
|---|---|
FPosBAPIClientError
|
If the server returns an error response or the connection is lost. |
Source code in src/applied_motion/backends/fposbapi_client.py
init_sys
Initialize system parameters via INIT_SYS.
Raises:
| Type | Description |
|---|---|
FPosBAPIClientError
|
If the server returns an error response or the connection is lost. |
Source code in src/applied_motion/backends/fposbapi_client.py
close
Close the underlying TCP socket.
Safe to call more than once; subsequent calls are no-ops because the OS will already have released the socket descriptor.