Device connection via USB to Ubuntu-core

Hello.
To the device with Ubuntu-core connected on the USB device.
When I start the application, it detects the device that is connected and starts to work with it.
If the snap package is installed on Ubuntu desktop is connected without problems.
But I see such a message on Ubuntu-core

[  0:249 ] extern;port setup failed: "/dev/ttyUSB0"
[ 10:133 ] log;GenersControllerCommon;library name: libCommProtV200.so, devices detection timeout
[ 10:136 ] log;GenersControllerCommon;class name: CommProtV200, target medium: /dev/ttyUSB0, no devices were detected                                                                                                                              
[ 10:137 ] log;GenersControllerCommon;class name: CommProtV200, target medium: /dev/ttyUSB0, detection was finished
[ 10:139 ] log;GenersControllerCommon;global, detection was finished

Could someone say what could be the problem?
Thx.

Aug 21 08:13:02 localhost kernel: [74416.741997] usb 2-3: new full-speed USB device number 5 using xhci_hcd
Aug 21 08:13:02 localhost kernel: [74416.878368] usb 2-3: New USB device found, idVendor=0403, idProduct=6001
Aug 21 08:13:02 localhost kernel: [74416.878381] usb 2-3: New USB device strings: Mfr=1, Product=2, SerialNumber=3
Aug 21 08:13:02 localhost kernel: [74416.878389] usb 2-3: Product: FT232R USB UART
Aug 21 08:13:02 localhost kernel: [74416.878396] usb 2-3: Manufacturer: FTDI
Aug 21 08:13:02 localhost kernel: [74416.878403] usb 2-3: SerialNumber: A51IKSXA
Aug 21 08:13:02 localhost kernel: [74416.882263] ftdi_sio 2-3:1.0: FTDI USB Serial Device converter detected
Aug 21 08:13:02 localhost kernel: [74416.882364] usb 2-3: Detected FT232RL
Aug 21 08:13:02 localhost kernel: [74416.883041] usb 2-3: FTDI USB Serial Device converter now attached to ttyUSB0
Aug 21 08:13:27 localhost kernel: [74441.581772] audit_printk_skb: 1195 callbacks suppressed
Aug 21 08:13:27 localhost kernel: [74441.581778] audit: type=1400 audit(1503303207.204:7645): apparmor="ALLOWED" operation="open" profile="snap.bsp095project.BSP095launcherCore" name="/usr/share/applications/" pid=5024 comm="CORE" requested_mask="r" denied_mask="r" fsuid=1000 ouid=0
Aug 21 08:13:27 localhost kernel: [74441.583503] audit: type=1400 audit(1503303207.204:7646): apparmor="ALLOWED" operation="file_receive" profile="snap.bsp095project.BSP095launcherCore" name="/dev/dri/card0" pid=5025 comm=52504320546872656164 requested_mask="wr" denied_mask="wr" fsuid=1000 ouid=0
Aug 21 08:13:27 localhost kernel: [74441.586775] audit: type=1400 audit(1503303207.208:7647): apparmor="ALLOWED" operation="open" profile="snap.bsp095project.BSP095launcherCore" name="/run/udev/data/+pci:0000:00:02.0" pid=5024 comm="CORE" requested_mask="r" denied_mask="r" fsuid=1000 ouid=0

I see in the logs that Ubuntu-core has find a device to work, but if I understand the application has no right to write to it?

denied_mask="r"

Can someone tell something about it?

Hey

You need to grant permissions to a particular snap to talk to a particular device. This is done using the snapd interfaces system. Since it looks like you are dealing with a USB serial port I would recommend to look at some gadget snaps that do exactly that. Once your gadget declares the device then you can simply connect an application to it (the application needs to hold a serial-port plug so that it has something to connect).

I’m CCing my colleagues that deal with this very often as they can point to to examples/real gadgets that use this: @ogra and @morphis

i think @kyrofa has that documented in his “build a robot” series linked here in the forum …

Edit: found it …

https://kyrofa.com/posts/ros-production-obtaining-confined-access-to-the-turtlebot-4-5

Note that these are not actually denials (notice “ALLOWED” in the output), the are violations against policy. Right now, your snap is in devmode, so policy violations are logged, but not denied. If your snap is put in ‘strict’ mode, then these would turn into denials and you would see DENIED instead of ALLOWED.

Some comments on the violations:

  • /usr/share/applications/ are usually harmless. If you ‘plugs: [ unity7 ]’ (and connect the interface), this will go away
  • the /dev/dri/card0 denial will likely break your snap in strict mode. You need to ‘plugs: opengl ]’ (and connect the interface)
  • the /run/udev/data denial is likely harmless, but is solved when you ‘plugs: [ opengl ]’ (and connect the interface)

All that said, the above has nothing to do with /dev/ttyUSB0-- that is a different issue entirely. Looking at the violations it seems like you are running the snap as non-root. I suspect your user does not have the traditional permissions to access /dev/ttyUSB0. You can check this with ‘ls -l /dev/ttyUSB0’ and verifying the permissions on the device. If this is the case, you may want to keep an eye on Multiple users and groups in snaps.

I might also not that on Ubuntu Core, the unity7 and opengl interfaces are not available-- they are implicit classic interfaces. Your snap likely will need to use the framebuffer interface or mir if you need a graphical environment.

In my snap package there are 3 graphics applications and 1 console app. Just the console application should be connected on the port /dev/ttyUSB0 to the device. The first 3 graphics applications are still unable to start due to the reason:

Failed to open settings file for writing.
QIODevice::write (QFile, "/var/snap/bsp095project/x1/BTL095/settings.json"): device not open
/snap/bsp095project/x1/bin/start_GUI.sh: line 11:  7688 Segmentation fault      $SNAP/bin/./BTL095 $(cat "$HOME/PrimaryKey") $(cat "$HOME/SecondaryKey")

The reason is still unknown.

does your “start_GUI.sh” (or anything else) create that dir ? there should be a “mkdir -p $SNAP_DATA/BTL095”, if you did not create the dir you can indeed to write a file to it …

Thank you for reminding me about the creation of this directory. I now noticed one interesting thing, as it turned out the graphics can be launched and that at the start it created a directory, only through sudo. It’s strange, why the graphics should be run with the rights of the root?

And now it’s clear to me the reason why I did not connect to the device through /dev/ttyUSB0. I again used sudo bsp095project.BSP095launcherCore, and it’s running.

@ogra
Can you tell me please, how to configure the launch of the application so that the connection in the device

sudo bsp095project.BSP095launcherCore

[  0:255 ] log;GenersControllerCommon;Starting detection on /dev/ttyUSB0
[  0:255 ] main;initialization finished at 10:35:26.323

does not require the right sudo?

Without “sudo” I see error
bsp095project.BSP095launcherCore

[  0:264 ] log;GenersControllerCommon;Starting detection on /dev/ttyUSB0
[  0:265 ] main;initialization finished at 10:36:34.063
[  0:265 ] extern;port setup failed: "/dev/ttyUSB0" 

Thx.

This is a well-iterated topic. Simply speaking the user doesn’t have rights to access /dev/ttyUSB0, not because of any confinement but simply because the file is owned by user/group with the permissions preventing your user from accessing it.

Have a look at Multiple users and groups in snaps (at the bottom) https://bugs.launchpad.net/snappy/+bug/1646144

Like on Ubuntu desktop I use command “sudo adduser “user” dialout” and the user was granted the right to work with the /dev/ttyUSB0