IIRC serial port slots are only allowed to be owned by the gadget which actually owns the hardware, applications need to use plugs to connect to said slot.
how did hotplug fail for you exactly ? i think it should work for that use-case …
$ sudo snap set system experimental.hotplug=true
$ sudo systemctl restart snapd
$ snap interface serial-port
name: serial-port
summary: allows accessing a specific serial port
plugs:
- test
slots:
- pi:bt-serial
- snapd:pl2303serialport (allows accessing a specific serial port) <- it appears
where exactly does that come from ? you should not tinker with devices underneath snapd if snapd owns them already (especially with hotplug where snapd itself dynamically creates udev rules) …
yes, add vim-common to you stage packages … probably it is also needed to use the full path $SNAP/usr/bin/xxd instead of just xxd
note that it is often helpful to have a second terminal open on the device and run snappy-debug (from the snappy-debug snap) in there while your app starts up … that should give you some insight what failed and why …
I’m recrafting the snap now, it will take some time.
About the udev rule. I need somehow to run that script to init my device (handshake).
I cannot know the state of the device, which means i cannot know if the handshake has been made, therefore, i need to send those commands once, at start up.
How can i set the udev correctly? If i can’t use a udev, are there alternatives?
I tried to write commands in /etc/rc.local, but it fails with:
touch: cannot touch '/etc/rc.local': Read-only file system
you should be able to have a little daemon script that uses udevadm and watches for add/remove events and runs code according to that … (needs the hardware-observe interface connected)
i do something similar (for block devices though, you’ll need to craft your own udevadm filter for serial devices) here:
here is an example script that i quickly threw together, that should work for ttyUSB0:
#! /bin/sh
stdbuf -oL -- udevadm monitor --udev -s usb-serial | while read -r -- _ _ event devpath _; do
if [ "$event" = add ]; then
if echo "$devpath" | grep -q ttyUSB0; then
echo "ttyUSB0 added" # add your init code here
fi
fi
done
then it will probably end up in the toplevel i.e. $SNAP …
using a separate part (so you dont need to re-build the world when making a small change to the script) and putting it into $SNAP/bin (with the dump plugin or similar) would be a bit cleaner …