Serial Communication
# Serial Communication Component
The RuleGo IoT component library provides serial communication support, allowing rule chains to interact with serial devices. It provides four functional components: read, write, request, and control.
Requires extension library: rulego-components-iot (opens new window)
# Component List
| Component Name | Type | Description |
|---|---|---|
| Serial In | x/serialIn | Reads data from a serial port. Supports splitting data by character, timeout, or fixed length. |
| Serial Out | x/serialOut | Writes data to a serial port. Supports automatically appending trailing characters. |
| Serial Request | x/serialRequest | Writes data and waits for a response (blocking). Supports timeout and response splitting logic. |
| Serial Control | x/serialControl | Controls the serial port connection status (open/close). |
# Common Configuration
All serial components share the following connection configuration:
| Field | Description | Example |
|---|---|---|
| port | Serial port name, e.g., COM1 (Windows) or /dev/ttyUSB0 (Linux) | COM3 |
| baudRate | Baud rate | 9600 |
| dataBits | Data bits | 8 |
| stopBits | Stop bits ("1", "1.5", "2") | 1 |
| parity | Parity (N: None, O: Odd, E: Even, M: Mark, S: Space) | N |
| dtr | DTR control (true, false) | true |
| rts | RTS control (true, false) | false |
Note: Multiple nodes with the same
portwill share the same underlying connection instance.
# 1. Serial In (x/serialIn)
Used to read data from a serial port. The read operation is triggered when an input message is received (usually used with a timer).
# Specific Configuration
| Field | Description | Default |
|---|---|---|
| startChar | Start character. If set, discards data until this character is matched. | - |
| splitType | Split type: char (by character), timeout (by timeout), fixed (by length) | timeout |
| splitKey | Split parameter. Delimiter if split by char (e.g., \n); number of bytes if split by length. | - |
| splitTimeout | Read segment timeout (ms). If no data for this duration, segment ends. | 100 |
| dataType | Output data type: text (UTF-8), binary, hex, base64 | text |
# 2. Serial Out (x/serialOut)
Used to write data to a serial port.
# Specific Configuration
| Field | Description | Default |
|---|---|---|
| data | Send content, supports dynamic variable replacement (e.g., ${data}). If empty, msg.Data is used. | - |
| addChar | Append character. Automatically appended to data when sending (supports \n, \r, etc.). | \r\n |
| dataType | Input data type: text (default), hex, base64. If not text, the data will be decoded before sending. | text |
# Input Message
If the data configuration is empty, msg.Data will be used as the content to send.
# 3. Serial Request (x/serialRequest)
Used for "Request-Response" pattern. Sends data first, then blocks waiting for a response.
# Specific Configuration
Includes data, addChar, dataType from Serial Out and all split configurations from Serial In (startChar, splitType, dataType, etc.), plus:
| Field | Description | Default |
|---|---|---|
| requestTimeout | Total request timeout (ms). | 10000 |
# 4. Serial Control (x/serialControl)
Used to manually control the serial connection.
# Specific Configuration
| Field | Description | Default |
|---|---|---|
| action | Control instruction, supports dynamic variable replacement (e.g., ${msg.action}). If empty, msg.Data is used as the instruction. | close |
# Input Message
If the action configuration is empty, msg.Data content is used as the control instruction:
open: Open the serial connection (normally the component opens it automatically, this is for manual reconnection).close: Close the serial connection.dtr=1: Set DTR signal to High.dtr=0: Set DTR signal to Low.rts=1: Set RTS signal to High.rts=0: Set RTS signal to Low.flush: Clear both input and output buffers.flush_in: Clear input buffer.flush_out: Clear output buffer.