RS-232/485
The RS-232/485 connector provides a unified interface to communicate with devices connected over a serial port, such as physical RS-232 and RS-485 interfaces, or USB-to-serial adapters. It scans system ports, configures connection parameters, and manages incoming and outgoing data streams.
This connector requires instance creation before you can scan system ports, configure connection parameters, or manage data streams.
Connection management
list
Scans the host system and returns an array of all detected serial ports. Use this to locate valid port paths before creating an instance.
Parameters
None.
Output
Returns an array of objects containing detailed platform hardware information for each detected serial port.
Example
[
{
"path": "COM3",
"manufacturer": "Arduino LLC",
"serialNumber": "12345",
"pnpId": "USB\\VID_2341&PID_0043\\12345",
"locationId": "Port_#0003.Hub_#0001",
"productId": "0043",
"vendorId": "2341"
}
]create
Creates an instance configured for a specific serial port. The connector preserves these properties but delays opening the physical hardware port until you run open.
Parameters
options
path
The file system path of the target serial port (such as /dev/ttyUSB0 on Linux or COM3 on Windows).
string
baudRate
The serial communication speed in bits per second. Supported standard values include 110, 300, 1200, 2400, 4800, 9600, 14400, 19200, 38400, 57600, or 115200. Default 9600.
integer
dataBits
The number of data bits per character frame (5, 6, 7, or 8). Default 8.
integer
stopBits
The number of stop bits to signal the end of a character frame (1, 1.5, or 2). Default 1.
number
parity
The parity error-checking mode (none, even, mark, odd, or space). Default 'none'.
string
lock
Prevents other system processes from gaining control of the port. Windows does not support disabling this. Default true.
boolean
rtscts
Enables Ready to Send / Clear to Send (RTS/CTS) hardware handshaking flow control. Default false.
boolean
xon
Enables XON software flow control. Default false.
boolean
xoff
Enables XOFF software flow control. Default false.
boolean
xany
Enables XANY software flow control, which allows any received character to restart transmission. Default false.
boolean
hupcl
Drops the Data Terminal Ready (DTR) hardware line when closing the connection. Default true.
boolean
Output
Returns the name of the created instance.
Example
open
Opens the communication channel to the serial port defined in the configuration.
Parameters
None.
Output
Returns true when the connection succeeds. Throws an error on failure.
isOpen
Checks whether the communication channel to the serial port is open.
Parameters
None.
Output
Returns true if the channel is open, or false if it is not.
changeBaudRate
Updates the communication speed dynamically for an active, open serial connection.
Parameters
baudRate
The new baud rate (such as 19200 or 115200).
integer
Output
Returns true if the baud rate updates successfully. Throws an error on failure.
Example
close
Closes the active serial connection.
Parameters
None.
Output
Returns true on successful disconnection. Ongoing write operations automatically fail if the connection drops before they finish.
delete
Removes the instance and its configuration.
Irreversible action
Deleting an instance removes its configuration. To communicate with the device again, you must create a new instance.
Parameters
None.
Output
Returns true upon removal.
Data operations
write
Transmits a text string across the active serial interface and pauses execution until the port transmits all data. To insert control characters, use <CR> for carriage return (\r), <LF> for line feed (\n), and <CRLF> for both (\r\n).
Parameters
data
The text string to transmit. Supports control tokens like <CRLF>.
string
suffix
An optional string appended automatically to the end of the text. Default empty string.
string
Output
Returns true when all data transmits completely. Throws an error on failure.
Example
read
Retrieves a specific number of raw bytes from the incoming receive buffer. To monitor incoming traffic asynchronously, use onData instead of polling with this function.
Parameters
size
The number of bytes to retrieve from the receive buffer.
integer
Output
Returns a decoded string containing the retrieved bytes, or null if the buffer does not contain the requested number of bytes.
onData
Registers a named observer that parses the incoming serial data stream and triggers a callback when a complete message arrives. Use only one of the three parsing strategies. If several are set, timeout takes precedence over byteLength over delimiter.
Parameters
name
A unique label to identify this stream parser.
string
handler
The callback evaluated on payload match. Receives the parsed string payload.
callback
parserOptions
delimiter
Emits the accumulated stream immediately when encountering this character sequence. Recognizes control tokens like <LF> or <CRLF>. Default <LF>.
string
timeout
Emits the accumulated data after detecting a communication silence of this duration in milliseconds.
integer
byteLength
Emits the data block when the incoming stream reaches this fixed size in bytes.
integer
Output
Returns true when the observer registers successfully, or nothing if an observer with that name already exists.
Examples
Example 1: Delimiter text parsing
Example 2: Inter-byte timeout burst parsing
Example 3: Fixed byte length parsing
onError
Registers an observer that triggers whenever the serial channel encounters a hardware or connection error.
Parameters
name
A unique identification label for this error observer.
string
handler
The callback triggered when a connector exception occurs. Receives the error object.
callback
Output
Returns true when the observer registers successfully, or nothing if an observer with that name already exists.
Example
Last updated
Was this helpful?