Serial Port

Communication over a serial port (RS-232, RS-485, or a USB adapter presenting itself as one).

Transport syntax

{name of the serial port}

The name depends on the operating system:

  • Windows: COM1

  • Linux: /dev/ttyS0, /dev/ttyUSB0

  • macOS: /dev/tty.usbserial-XXXX

Example
modbus-rtu://COM1?serial.baud-rate=19200
modbus-rtu:serial:///dev/ttyUSB0?serial.baud-rate=9600&serial.parity=even

Name

Type

Default Value

Required

Description

Name

Serial

Code

serial

Maven Dependency

<dependency>
  <groupId>org.apache.plc4x</groupId>
  <artifactId>plc4j-transports-serial</artifactId>
  <version>1.1.0</version>
</dependency>

Config options:

serial.baud-rate

INT

9600

Baud rate (bits per second)

serial.data-bits

INT

8

Number of data bits (5, 6, 7, or 8)

serial.stop-bits

INT

1

Number of stop bits (1 or 2)

serial.parity

STRING

none

Parity: none, odd, even, mark, space (case-insensitive)

serial.flow-control

STRING

none

Flow control: none, rts-cts, xon-xoff (case-insensitive)

serial.read-timeout-ms

INT

1000

Read timeout in milliseconds. 0 means blocking read.

serial.write-timeout-ms

INT

1000

Write timeout in milliseconds.

serial.dtr

BOOLEAN

false

Enable DTR (Data Terminal Ready) signal

serial.rts

BOOLEAN

false

Enable RTS (Request To Send) signal

serial.reuse-port

BOOLEAN

false

Reuse the underlying serial port across multiple transport instances. When true, instances with the same port will share a connection. This is useful for protocols where multiple logical connections share one serial port. Connections sharing a port must target distinct unit ids; Modbus RTU responses carry no transaction ids, so same-unit traffic from multiple connections cannot be told apart.

serial.interframe-delay

INT

0

Interframe delay in milliseconds for protocols that need spacing between messages. Applies to shared and dedicated ports; the gap is measured from the last write or received data.

On an RS-485 bus several devices share one physical port. serial.reuse-port=true lets several PLC4X connections share a single open port for that case - read the warning on that option before using it.