Serial port access for private repository

@radomirpolach what device does this USB-Serial converter show up as on your host system? Also can you confirm that sudo snap get system experimental.hotplug outputs true? When testing this locally with a different USB-Serial converter:

$ lsusb | grep Keyspan
Bus 005 Device 009: ID 06cd:0121 Keyspan USA-19hs serial adapter

It works for me:

$ sudo snap get system experimental.hotplug
true
$ sudo dmesg | grep ttyUSB
[43658.826363] usb 5-2.2: Keyspan 1 port adapter converter now attached to ttyUSB0
$ snap interface serial-port
name:    serial-port
summary: allows accessing a specific serial port
slots:
  - snapd:keyspanusa-19h (allows accessing a specific serial port)
          -                                                              :keyspanusa-19h            -

what do you see in dmesg when plugging in the USB/serial adapter … it should look similar to the stuff below:

$ sudo dmesg -w
[...]
[268760.901758] audit: type=1420 audit(1654174808.483:1290): subj_apparmor=unconfined
[268868.859996] usb 1-1: new full-speed USB device number 4 using xhci_hcd
[268869.013021] usb 1-1: New USB device found, idVendor=067b, idProduct=2303, bcdDevice= 3.00
[268869.013028] usb 1-1: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[268869.013030] usb 1-1: Product: USB-Serial Controller
[268869.013033] usb 1-1: Manufacturer: Prolific Technology Inc.
[268869.126420] usbcore: registered new interface driver usbserial_generic
[268869.126461] usbserial: USB Serial support registered for generic
[268869.128788] usbcore: registered new interface driver pl2303
[268869.128827] usbserial: USB Serial support registered for pl2303
[268869.128866] pl2303 1-1:1.0: pl2303 converter detected
[268869.129541] usb 1-1: pl2303 converter now attached to ttyUSB0
[...]

you should then see a slot:

$ snap interface serial-port
name:    serial-port
summary: allows accessing a specific serial port
plugs:
  - arduino
  - esptool
  - pcsc-daemon
slots:
  - snapd:pl2303serialportmobi (allows accessing a specific serial port)

does the kernel actually detect the device and assign a ttyUSB* port for it in the first step above ?

$  sudo snap get system experimental.hotplug
true
$  sudo dmesg | grep ttyUSB
[  425.300597] usb 1-4: ch341-uart converter now attached to ttyUSB0
[  426.010761] ch341-uart ttyUSB0: ch341-uart converter now disconnected from ttyUSB0
$  snap interface serial-port
name:    serial-port
summary: allows accessing a specific serial port
plugs:
  - internethandel-electron-cme
$  snap connections system | grep serial

Complete dmesg from connecting the device:

[  581.148236] usb 1-1: new full-speed USB device number 5 using xhci_hcd
[  581.301054] usb 1-1: New USB device found, idVendor=1a86, idProduct=7523, bcdDevice= 2.54
[  581.301059] usb 1-1: New USB device strings: Mfr=0, Product=2, SerialNumber=0
[  581.301060] usb 1-1: Product: USB2.0-Serial
[  581.302426] ch341 1-1:1.0: ch341-uart converter detected
[  581.302772] usb 1-1: ch341-uart converter now attached to ttyUSB0
[  581.843558] audit: type=1400 audit(1654176321.477:217): apparmor="DENIED" operation="open" profile="snap.keepassxc.keepassxc" name="/sys/devices/pci0000:00/0000:00:14.0/usb1/1-1/busnum" pid=5556 comm="keepassxc" requested_mask="r" denied_mask="r" fsuid=1000 ouid=0
[  581.881687] audit: type=1400 audit(1654176321.517:218): apparmor="DENIED" operation="open" profile="snap.keepassxc.keepassxc" name="/sys/devices/pci0000:00/0000:00:14.0/usb1/1-1/busnum" pid=5556 comm="keepassxc" requested_mask="r" denied_mask="r" fsuid=1000 ouid=0
[  582.415955] input: BRLTTY 6.4 Linux Screen Driver Keyboard as /devices/virtual/input/input30
[  582.541536] usb 1-1: usbfs: interface 0 claimed by ch341 while 'brltty' sets config #1
[  582.542318] ch341-uart ttyUSB0: ch341-uart converter now disconnected from ttyUSB0
[  582.542380] ch341 1-1:1.0: device disconnected

that looks like:

(not actually snap related at all)

Ah good find @ogra - so it looks like you may be able to resolve this @radomirpolach by removing the brltty package.

@radomirpolach ping can you confirm if removing the brltty package is sufficient to get serial-port with hotplug working? If so, we can then look at granting the required snap declaration to allow this to occur automatically when your snap is installed. Thanks.

@radomirpolach - ping, have you had a chance to test removing the brltty package to get this working?

Sorry for late response, removing brltty package solved the connection of snap issues, but my application stil don’t see serial port:

Interface                 Plug                                         Slot                             Notes
browser-support           internethandel-electron-cme:browser-support  :browser-support                 -
content[gnome-3-28-1804]  internethandel-electron-cme:gnome-3-28-1804  gnome-3-28-1804:gnome-3-28-1804  -
content[gtk-3-themes]     internethandel-electron-cme:gtk-3-themes     gtk-common-themes:gtk-3-themes   -
content[icon-themes]      internethandel-electron-cme:icon-themes      gtk-common-themes:icon-themes    -
content[sound-themes]     internethandel-electron-cme:sound-themes     gtk-common-themes:sound-themes   -
cups-control              internethandel-electron-cme:cups-control     :cups-control                    manual
desktop                   internethandel-electron-cme:desktop          :desktop                         -
desktop-legacy            internethandel-electron-cme:desktop-legacy   :desktop-legacy                  -
gsettings                 internethandel-electron-cme:gsettings        :gsettings                       -
home                      internethandel-electron-cme:home             :home                            -
network                   internethandel-electron-cme:network          :network                         -
opengl                    internethandel-electron-cme:opengl           :opengl                          -
pulseaudio                internethandel-electron-cme:pulseaudio       -                                -
serial-port               internethandel-electron-cme:serial-port      :usb20-serial                    manual
unity7                    internethandel-electron-cme:unity7           :unity7                          -
x11                       internethandel-electron-cme:x11              :x11                             -

Plug is connected to snap.

When I run the application outside snap, it sees the serial device. When I run it inside snap with the device connected, it doesn’t.

I am looking into snap directory and I don’t see any dev directory. How exactly is the device connected to snap?

ls -la /snap/internethandel-electron-cme/62
total 179865
drwxrwxrwx 11 root root       623 čec  7 02:33 .
drwxr-xr-x  4 root root      4096 čec  7 02:35 ..
-rw-r--r--  1 root root    142605 čec  7 02:33 chrome_100_percent.pak
-rw-r--r--  1 root root    209194 čec  7 02:33 chrome_200_percent.pak
-rwxr-xr-x  1 root root   1100720 čec  7 02:33 chrome_crashpad_handler
-rwxr-xr-x  1 root root       157 čec  7 02:33 command.sh
drwxr-xr-x  5 root root        56 čec 10  2019 data-dir
-rwxr-xr-x  1 root root     16513 čec 10  2019 desktop-common.sh
-rwxr-xr-x  1 root root      1401 čec 10  2019 desktop-gnome-specific.sh
-rwxr-xr-x  1 root root      1530 čec 10  2019 desktop-init.sh
drwxr-xr-x  2 root root         3 čec 10  2019 gnome-platform
-rw-r--r--  1 root root  10217376 čec  7 02:33 icudtl.dat
-rwxr-xr-x  1 root root 148213568 čec  7 02:33 internethandel-electron-cme
drwxr-xr-x  3 root root        39 dub 18  2018 lib
-rwxr-xr-x  1 root root    236376 čec  7 02:33 libEGL.so
-rwxr-xr-x  1 root root   2890552 čec  7 02:33 libffmpeg.so
-rwxr-xr-x  1 root root   6985384 čec  7 02:33 libGLESv2.so
-rwxr-xr-x  1 root root   4034648 čec  7 02:33 libvk_swiftshader.so
-rwxr-xr-x  1 root root   4784456 čec  7 02:33 libvulkan.so.1
drwxrwxr-x  2 root root       792 čec  7 02:33 locales
drwxrwxr-x  3 root root        43 čec  7 02:33 meta
drwxrwxr-x  2 root root        31 čec  7 02:33 resources
-rw-r--r--  1 root root   5124401 čec  7 02:33 resources.pak
drwxrwxr-x  2 root root         3 čec  7 02:33 scripts
-rw-r--r--  1 root root     49495 čec  7 02:33 snapshot_blob.bin
drwxrwxr-x  2 root root        52 čec  7 02:33 swiftshader
drwxr-xr-x  3 root root        26 čec 10  2019 usr
-rw-r--r--  1 root root    164753 čec  7 02:33 v8_context_snapshot.bin
-rw-r--r--  1 root root       107 čec  7 02:33 vk_swiftshader_icd.json

Device doesn’t have SN, but otherwise seems pretty normal:

{
  manufacturer: '1a86',
  serialNumber: undefined,
  pnpId: 'usb-1a86_USB2.0-Serial-if00-port0',
  locationId: undefined,
  vendorId: '1a86',
  productId: '7523',
  path: '/dev/ttyUSB0'
}

Along with only supporting USB serial port adapters, hotplug is restricted to devices that provide a specific set of udev attributes; name, vendor identifier and/or serial number.

So this is within limitation?

[45526.422667] ch341-uart ttyUSB0: ch341-uart converter now disconnected from ttyUSB0
[45526.422687] ch341 5-2:1.0: device disconnected
[45528.858788] usb 5-2: new full-speed USB device number 8 using xhci_hcd
[45529.020894] usb 5-2: New USB device found, idVendor=1a86, idProduct=7523, bcdDevice= 2.54
[45529.020903] usb 5-2: New USB device strings: Mfr=0, Product=2, SerialNumber=0
[45529.020907] usb 5-2: Product: USB2.0-Serial
[45529.027938] ch341 5-2:1.0: ch341-uart converter detected
[45529.041994] usb 5-2: ch341-uart converter now attached to ttyUSB0
  looking at device '/devices/pci0000:00/0000:00:08.1/0000:07:00.4/usb5/5-2/5-2:1.0/ttyUSB0/tty/ttyUSB0':
    KERNEL=="ttyUSB0"
    SUBSYSTEM=="tty"
    DRIVER==""
    ATTR{power/async}=="disabled"
    ATTR{power/control}=="auto"
    ATTR{power/runtime_active_kids}=="0"
    ATTR{power/runtime_active_time}=="0"
    ATTR{power/runtime_enabled}=="disabled"
    ATTR{power/runtime_status}=="unsupported"
    ATTR{power/runtime_suspended_time}=="0"
    ATTR{power/runtime_usage}=="0"

  looking at parent device '/devices/pci0000:00/0000:00:08.1/0000:07:00.4/usb5/5-2/5-2:1.0/ttyUSB0':
    KERNELS=="ttyUSB0"
    SUBSYSTEMS=="usb-serial"
    DRIVERS=="ch341-uart"
    ATTRS{port_number}=="0"
    ATTRS{power/async}=="enabled"
    ATTRS{power/control}=="auto"
    ATTRS{power/runtime_active_kids}=="0"
    ATTRS{power/runtime_active_time}=="0"
    ATTRS{power/runtime_enabled}=="disabled"
    ATTRS{power/runtime_status}=="unsupported"
    ATTRS{power/runtime_suspended_time}=="0"
    ATTRS{power/runtime_usage}=="0"

Tried another device with serial number:

{
  manufacturer: 'FTDI',
  serialNumber: 'A50285BI',
  pnpId: 'usb-FTDI_FT232R_USB_UART_A50285BI-if00-port0',
  locationId: undefined,
  vendorId: '0403',
  productId: '6001',
  path: '/dev/ttyUSB0'
}

It is still not visible to my application.

Interface                 Plug                                         Slot                             Notes
browser-support           internethandel-electron-cme:browser-support  :browser-support                 -
content[gnome-3-28-1804]  internethandel-electron-cme:gnome-3-28-1804  gnome-3-28-1804:gnome-3-28-1804  -
content[gtk-3-themes]     internethandel-electron-cme:gtk-3-themes     gtk-common-themes:gtk-3-themes   -
content[icon-themes]      internethandel-electron-cme:icon-themes      gtk-common-themes:icon-themes    -
content[sound-themes]     internethandel-electron-cme:sound-themes     gtk-common-themes:sound-themes   -
cups-control              internethandel-electron-cme:cups-control     :cups-control                    manual
desktop                   internethandel-electron-cme:desktop          :desktop                         -
desktop-legacy            internethandel-electron-cme:desktop-legacy   :desktop-legacy                  -
gsettings                 internethandel-electron-cme:gsettings        :gsettings                       -
home                      internethandel-electron-cme:home             :home                            -
network                   internethandel-electron-cme:network          :network                         -
opengl                    internethandel-electron-cme:opengl           :opengl                          -
pulseaudio                internethandel-electron-cme:pulseaudio       -                                -
serial-port               internethandel-electron-cme:serial-port      :ft232rusbuart                   manual
unity7                    internethandel-electron-cme:unity7           :unity7                          -
x11                       internethandel-electron-cme:x11              :x11                             -

I was under the impression, that my application would work without any change once serial device is connected to my snap. What am I missing here?

I can connect both devices as well:

serial-port               internethandel-electron-cme:serial-port      :ft232rusbuart                   manual
serial-port               internethandel-electron-cme:serial-port      :usb20-serial                    manual

But I don’t see any of them from within application. Is there any way to debug this?

It seems to work actually, the serialport library is just unable to list serial devices. Most likely because usedadm is missing.

assuming that was a typo and you mean udevadm, you can just add udev to your stage-packages: to ship it in your snap …

@radomirpolach ping, what’s the status of this request? were you able to list serial devices?

@radomirpolach - ping, this request cannot proceed without the requested information?

@radomirpolach - since we’ve not heard back from you, we are removing this request from our review queue. When you have more time to respond, simply do so here and we can add the request back to the queue. Thanks