The serial-port interface

serial-port enables access to a specific serial port. This interface is restricted because it provides privileged access to configure serial port hardware.

The slot is intended to be implemented by a gadget snap and is not provided by the core system snap.

Auto-Connect: no
Attributes:

  • 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.

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
slots:
  - 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.

ⓘ This is a snap interface. See Interface management and Supported interfaces for further details on how interfaces are used.

2 Likes

Is there an example on how any application snap connect to the serial port.

Isn’t the description missing usb-interface-number?

1 Like

I think snap interface serial-port lists the snaps that provide slots and the snaps the have plugs for the named interface (in this case serial-port interface). That is, it does not seem list see “serial port devices” as the current text indicates. For example, I have a gadget named ‘my-test-gadg’ that declares the slot, and I have a snap ‘my-sp-app’ that has the plug, and I see this:

knitzsche@localhost:~$ snap interface serial-port
name:    serial-port
summary: allows accessing a specific serial port
plugs:
  - my-sp-app
slots:
  - my-test-gadg

I just found that declaring a usb-vendor or usb-product with a four-digit INT with a leading 0 causes a toolchain failure leading to a snap that cannot be uploaded, that is, these fail:

slots:
  serial-port:
    usb-vendor: 0658
    usb-product: 0200
    ....

Use this instead:

slots:
  serial-port:
    usb-vendor: 0x0658
    usb-product: 0x0200
    ....

I cannot yet build a gadget that declares the serial-port slot and declares BOTH the path and the two usb-* attributes.

This:

slots:
  serial-port:
    path: /dev/ttyACM0
    usb-vendor: 0x0658
    usb-product: 0x0200 

Results in this:
snap "my-gadge" has bad plugs or slots: serial-port (serial-port path attribute specifies invalid symlink location)

This is discussed up above, with usb-vendor and usb-product, ‘path’ specifies the symlink name: https://github.com/snapcore/snapd/blob/master/interfaces/builtin/serial_port.go#L77

Use this:

slots:
  serial-port:
    path: /dev/serial-port-?
    usb-vendor: 0x0658
    usb-product: 0x0200 

Thanks Jamie. The text could be clearer by simply stating that when usb-vendor and usb-product attributes are declared, the path value must start with /dev/serial-port-.

Thanks Kyle - and yes, I think you’re right. I’ll update the text to try and make it clearer.

@degville - oh, I just did! Please adjust as you see fit :slight_smile:

That’s awesome, thank you :slight_smile:

Any chance it will be supported in the classic core snap?

Yes. And I think usb-interface-number may be needed when a (for example) USB device provides two interfaces and you need therefore two paths to them exposed deterministically.

What is the significance of the prefix of “serial-port-” when defining a slot for a USB serial port? Is this a prefix required by udev?