linuxcnc-ethercat

Beckhoff EL6001 / EL6021 serial terminals

The lcec_el6021 driver supports the Beckhoff EL6001 (RS232) and EL6021 (RS422/RS485) single-channel serial interface terminals. Instead of exporting HAL pins for the serial data itself, the driver exposes the terminal’s serial port as a userspace character device via CUSE (Character Device in Userspace):

/dev/lcec-<master>-<slave>     (default, or <ttyName> modParam)

Any application that can talk to a serial port (mb2hal, pymodbus, minimalmodbus, minicom, or plain shell redirection) can use the device directly. This makes the EL6021 a practical way to attach Modbus RTU devices (VFDs, spindles, scales, …) to an EtherCAT bus without a USB-serial adapter.

<slave idx="1" type="EL6021" name="vfd">
  <modParam name="ttyName" value="lcec-vfd0"/>
</slave>

How it works

Requirements

If libfuse3 is not available (or too old) at build time, the driver compiles without CUSE support and only the HAL status pins are available.

Throughput

The EL6001/EL6021 transfers at most 22 bytes per process data window. At a 1 kHz servo thread this gives roughly 11 kB/s in each direction; plenty for Modbus RTU at 38400 baud (3.8 kB/s wire rate), but large register polls will take multiple servo cycles. The 22-byte window moves roughly every second cycle due to the toggle handshake.

modParams

All modParams are optional; the defaults are the sane choice for most setups (9600 8N1, no handshake). baud, dataFrame and rtsCts are startup values only: they configure the terminal before any application connects, and are overridden as soon as an application opens the character device and sets its own termios attributes (mb2hal does this from its INI on startup). Leave them out of the XML unless the port must be usable before any app configures it.

HAL pins

All pins are prefixed with lcec.<master>.<slave>.:

Supported termios settings

tcsetattr() accepts any combination of: baud rates from the baud table above, 7/8 data bits, no/even/odd parity, 1/2 stop bits, and CRTSCTS. Anything else (5/6 data bits, arbitrary BOTHER baud rates) fails with EINVAL.

TIOCINQ/FIONREAD reports bytes available. TIOCMGET reports a fixed RTS|CTS|DSR|CD set; modem control and break ioctls are accepted but are no-ops (the terminal has no physical modem lines for them).

Example: Huanyang VFD via mb2hal

mb2hal.ini fragment:

[MB2HAL_INIT]
INIT_DEBUG=3
HAL_MODULE_NAME=mb2hal.vfd
SLOWDOWN=0.0
TOTAL_TRANSACTIONS=1

[TRANSACTION_0]
LINK_TYPE=serial
SERIAL_PORT=/dev/lcec-vfd0
SERIAL_BAUD=38400
SERIAL_BITS=8
SERIAL_PARITY=none
SERIAL_STOP=1
MB_SLAVE_ID=1
MB_TX_FN=6
MB_TX_ADDR=8193
NELEMENTS=1
HAL_TX_NAME=rpm-cmd
MAX_UPDATE_RATE=0.0
DEBUG=1

Test the port before configuring mb2hal; the VFD’s maximum reliable baud rate varies by model.