Pluggable monitor specification








































Monitor tools are a special kind of tool used to let the user communicate with the supported boards. A platform developer can create their own tools following the specification below. These tools must be in the form of command line executables that can be launched as a subprocess.

They will communicate to the parent process via stdin/stdout, in particular a monitor tool will accept commands as plain text strings from stdin and will send answers back in JSON format on stdout. Each tool will implement the commands to open and control communication ports for a specific protocol as specified in this document. The actual I/O data stream from the communication port will be transferred to the parent process through a separate channel via TCP/IP.

Pluggable monitor API via stdin/stdout

All the commands listed in this specification must be implemented in the monitor tool.

After startup, the tool will just stay idle waiting for commands. The available commands are:

HELLO
,
DESCRIBE
,
CONFIGURE
,
OPEN
,
CLOSE
and
QUIT
.

After each command the client always expects a response from the monitor. The monitor must not introduce any delay and must respond to all commands as fast as possible.

HELLO command

HELLO
must be the first command sent to the monitor to tell the name of the client/IDE and the version of the pluggable monitor protocol that the client/IDE supports. The syntax of the command is:

HELLO <PROTOCOL_VERSION> "<USER_AGENT>"

  • <PROTOCOL_VERSION>
    is the maximum protocol version supported by the client/IDE (currently
    1
    )
  • <USER_AGENT>
    is the name and version of the client. It must not contain double-quotes (
    "
    ).

some examples:

  • HELLO 1 "Arduino IDE 1.8.13"

  • HELLO 1 "arduino-cli 1.2.3"

the response to the command is:

1{
2 "eventType": "hello",
3 "protocolVersion": 1,
4 "message": "OK"
5}

The

protocolVersion
field represents the protocol version that will be used in the rest of the communication. There are three possible cases:

  • if the client/IDE supports the same or a more recent version of the protocol than the monitor tool, then the client/IDE should go into a compatibility mode and use the protocol level supported by the monitor tool.
  • if the monitor tool supports a more recent version of the protocol than the client/IDE, then the monitor tool should downgrade itself into compatibility mode and report a
    protocolVersion
    that is less than or equal to the one supported by the client/IDE.
  • if the monitor tool cannot go into compatibility mode, it must report the protocol version supported (even if greater than the version supported by the client/IDE) and the client/IDE may decide to terminate the monitor tool or produce an error/warning.

DESCRIBE command

The

DESCRIBE
command returns a description of the communication port. The description will have metadata about the port configuration, and which parameters are available to the user.

1{
2 "eventType": "describe",
3 "message": "ok",
4 "port_description": {
5 "protocol": "serial",
6 "configuration_parameters": {
7 "baudrate": {
8 "label": "Baudrate",
9 "type": "enum",
10 "value": [
11 "300", "600", "750", "1200", "2400", "4800", "9600",
12 "19200", "38400", "57600", "115200", "230400", "460800",
13 "500000", "921600", "1000000", "2000000"
14 ],
15 "selected": "9600"
16 },
17 "parity": {
18 "label": "Parity",
19 "type": "enum",
20 "value": [ "N", "E", "O", "M", "S" ],
21 "selected": "N"
22 },
23 "bits": {
24 "label": "Data bits",
25 "type": "enum",
26 "value": [ "5", "6", "7", "8", "9" ],
27 "selected": "8"
28 },
29 "stop_bits": {
30 "label": "Stop bits",
31 "type": "enum",
32 "value": [ "1", "1.5", "2" ],
33 "selected": "1"
34 }
35 }
36 }
37}

The field

protocol
is the board port protocol identifier, it must match with the corresponding protocol identifier for a pluggable discovery tool.

configuration_parameters
is a key/value map that enumerates the available port parameters.

Each parameter has a unique name (

baudrate
,
parity
, etc...), a
type
(in this case only
enum
is allowed but more types may be added in the future if needed), and the
selected
value for each parameter.

The parameter name can not contain spaces, the allowed characters are alphanumerics, underscore

_
, dot
.
, and dash
-
.

The

enum
types must have a list of possible values in the
value
list field.

The client/IDE may expose these configuration values to the user via a config file or a GUI, in this case the

label
field may be used for a user readable description of the parameter.

CONFIGURE command

The

CONFIGURE
command sets configuration parameters for the communication port. The parameters can be changed one at a time and the syntax is:

CONFIGURE <PARAMETER_NAME> <VALUE>

The response to the command is:

1{
2 "eventType": "configure",
3 "message": "ok"
4}

or if there is an error:

1{
2 "eventType": "configure",
3 "error": true,
4 "message": "invalid value for parameter baudrate: 123456"
5}

The currently selected parameters or their default value may be obtained using the

DESCRIBE
command.

OPEN command

The

OPEN
command opens a communication port with the board, the data exchanged with the board will be transferred to the Client/IDE via TCP/IP.

The Client/IDE must first TCP-Listen to a randomly selected TCP port and send the address to connect it to the monitor tool as part of the

OPEN
command. The syntax of the
OPEN
command is:

OPEN <CLIENT_TCPIP_ADDRESS> <BOARD_PORT>

For example, let's suppose that the Client/IDE wants to communicate with the serial port

/dev/ttyACM0
using an hypothetical
serial-monitor
tool, then the sequence of actions to perform will be the following:

  1. the Client/IDE must first listen to a random TCP port (let's suppose it chose
    32123
    )
  2. the Client/IDE runs the
    serial-monitor
    tool and initializes it with the
    HELLO
    command
  3. the Client/IDE sends the command
    OPEN 127.0.0.1:32123 /dev/ttyACM0
    to the monitor tool
  4. the monitor tool opens
    /dev/ttyACM0
  5. the monitor tool connects via TCP/IP to
    127.0.0.1:32123
    and starts streaming data back and forth

The answer to the

OPEN
command is:

1{
2 "eventType": "open",
3 "message": "ok"
4}

If the monitor tool cannot communicate with the board, or if the tool can not connect back to the TCP port, or if any other error condition happens:

1{
2 "eventType": "open",
3 "error": true,
4 "message": "unknown port /dev/ttyACM23"
5}

The board port will be opened using the parameters previously set through the

CONFIGURE
command.

Once the port is opened, it may be unexpectedly closed at any time due to hardware failure, or because the Client/IDE closes the TCP/IP connection, etc. In this case an asynchronous

port_closed
message must be generated by the monitor tool:

1{
2 "eventType": "port_closed",
3 "message": "serial port disappeared!"
4}

or

1{
2 "eventType": "port_closed",
3 "message": "lost TCP/IP connection with the client!"
4}

CLOSE command

The

CLOSE
command will close the currently opened port and close the TCP/IP connection used to communicate with the Client/IDE. The answer to the command is:

1{
2 "eventType": "close",
3 "message": "ok"
4}

or in case of error

1{
2 "eventType": "close",
3 "error": true,
4 "message": "port already closed"
5}

QUIT command

The

QUIT
command terminates the monitor. The response to
QUIT
is:

1{
2 "eventType": "quit",
3 "message": "OK"
4}

after this output the monitor exits. This command must always succeed.

Invalid commands

If the client sends an invalid or malformed command, the monitor should answer with:

1{
2 "eventType": "command_error",
3 "error": true,
4 "message": "Unknown command XXXX"
5}
In this page you can check the latest version of the Arduino CLI. You can find previous versions here.

ON THIS PAGE