Skip to main content
Version: 1.0

Serial

The Serial component configures a hardware serial port and its operating mode. It is available on devices with serial hardware, such as The Pill.

The Serial component uses Serial as RPC namespace and implements the following methods:

Modes of Operation

The mode parameter in the configuration determines how the serial port is used. The set of supported modes depends on the device and is listed in the modes attribute.

modeDescription
disabledSerial port is inactive. If the Serial instance shares hardware with a port used for debug output, that function is also suspended.
jsuartExposes the port to scripts via the UART API. Only one script can use the port at a time.
mb_serverOperates as a Modbus RTU Server. Only available on devices with Modbus support.
mb_clientOperates as a Modbus RTU Client. Creates an MbRtuClient component instance with the same id as the Serial instance, exposing raw register and coil read/write RPC methods.

Methods

Serial.GetConfig

Retrieves the currently-applied configuration.

Parameters:

PropertyTypeDescription

id

number

Id of the Serial component instance

Serial.SetConfig

Updates the configuration of the Serial component. Configuration changes are applied at runtime without requiring a device restart.

Parameters:

PropertyTypeDescription

id

number

Id of the Serial component instance

config

object

Configuration to apply

Return:

PropertyTypeDescription

restart_required

bool

Whether a reboot is required for the new config to apply

Attributes

The Serial component exports the following attribute:

PropertyTypeDescription

modes

array of strings

Set of modes that this Serial instance supports.

Configuration

PropertyTypeDescription

id

number

Id of the Serial component instance

mode

string

Operating mode for the serial port. Supported modes are listed in the modes attribute.

serial

object

Serial port parameters, used as applicable for the selected mode.

PropertyTypeDescription

baud

integer

Baud rate

format

string

A 3-character string indicating the serial frame format to use, e.g. 8N1

hd

boolean

Optional. Half-duplex mode. Only present on devices where the underlying hardware supports it. true = enabled, false = disabled.

de_al

boolean

Optional. Driver Enable (DE) active level. Only present on devices where the underlying hardware supports it. true = active high, false = active low.

mb_server

object

Modbus RTU Server configuration

PropertyTypeDescription

addr

integer

RTU Server Address, between 1 and 247

mb_client

object

Modbus RTU Client configuration. Reserved for future use.

The serial.format config parameter accepts a 3-char string, where each of the chars configures some aspect of the serial framing:

  • Number of data bits, 7 or 8
  • Parity, N, E or O for None, Even and Odd respectively
  • Number of stop bits, 1, 2 or the letter x for 1.5

Examples

Serial.GetConfig example

http://192.168.33.1/rpc/Serial.GetConfig?id=0

Response

{
"mode": "disabled",
"serial": {
"baud": 115200,
"format": "8N1",
"hd": false,
"de_al": false
},
"mb_server": {
"addr": 42
}
}

Serial.SetConfig example

http://192.168.33.1/rpc/Serial.SetConfig?id=0&config={"mode":"jsuart","serial":{"baud":9600,"format":"8E1"}}

Response

{
"restart_required": false
}