The serial-port interface

The serial-port interface enables input and output access to a specific serial port on a device typically running Ubuntu Core. As a result, and because it provides such privileged access to configure serial port hardware, serial-port is considered a restricted interface.

Use snap interface serial-port to see which serial-port devices are available on the system:

$ snap interface serial-port 
name:    serial-port
summary: allows accessing a specific serial port
  - core:model01 (allows accessing a specific serial port)
  - core:monome (allows accessing a specific serial port)

Once connected, the consuming snap can use the device via the path specified by the connected slot.

Interface documentation:

See Interface management and Supported interfaces for further details on how interfaces are used.

Developer details

Auto-Connect: no

  • Should specify a single path attribute:
    • path (slot): path to serial device node e.g. /dev/ttyS1
  • Or three attributes:
    • usb-vendor (slot): integer representing the USB Vendor ID, must be in range 0 < vid <= 65535
    • usb-product (slot): integer representing the USB Product ID, must be in range 0 <= vid <= 65535
    • path (slot): path of the form /dev/serial-port-... where a symlink will be created to the device e.g. /dev/serial-port-mydevice

To use a serial-port device, the snap developer must add plugs: [ serial-port ] to a snap’s snapcraft.yaml. The snap user can then access a specific serial-port device with an interface connection.

Device considerations

From a Brand Store context, the intention for IO interfaces like these, including gpio and i2c, is that they’re driven from a device’s gadget snap instead from the core system snap or other connecting snap. This should mean that no change is required in a connecting snap other the appropriately-configured plug.

This approach is more robust because it allows the gadget snap providing the slot to centralise and arbitrate the connection conditions. These conditions would include which other snaps, identified by their snap ID, can connect to the slots the gadget offers and, consequently, gain privileged access to the hardware.

See Auto-connections for more details on when an automatic connection is triggered or processed.

Code examples

The following example shows the slot configuration, such as from the gadget snap, and includes which snaps are permitted to connect automatically:

          - (whatever)
          - serial-foo
          - foooVbn5YriRw2sRVw7Cuj5PbjJjwnFb
          path: /dev/whatever
          - serial-foo

All attributes must match for an auto-connection attempt to be successful. The above example requires a connecting snap to have a matching snap-id and plug name. For example, the following snapcraft.yaml stanza for the connecting snap would not connect:


While the following snapcraft.yaml stanza for the connecting snap would automatically connect:

      interface: serial-port

The test code can be found in the snapd repository: serial_port_test.go.

The source code for the interface is in the snapd repository: serial_port.go

Last updated a month ago.