Accessing /dev/* serial via python

Hi.

For a project I need to access /dev/ttyACM0 from python on an APP LAB app.

By accessing the board via SSH I'm able to see correctly the device (a usb serial barcode scanner) but when the code is executed it seems that the "app container" can't interact with /dev*

[main] Activating python virtual environment
[main] Requirements already installed.
[main] Using Python 3.13.9 environment at: .cache/.venv
[main] Audited 1 package in 334ms
[main] Clearing cache at: .cache/uv
[main] Removed 6 files (1.1KiB)
[main] Traceback (most recent call last):
[main]   File "/app/.cache/.venv/lib/python3.13/site-packages/serial/serialposix.py", line 322, in open
[main]     self.fd = os.open(self.portstr, os.O_RDWR | os.O_NOCTTY | os.O_NONBLOCK)
[main]               ~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[main] FileNotFoundError: [Errno 2] No such file or directory: '/dev/ttyACM0'
[main]
[main] During handling of the above exception, another exception occurred:
[main]
[main] Traceback (most recent call last):
[main]   File "/app/python/main.py", line 23, in <module>
[main]     main()
[main]     ~~~~^^
[main]   File "/app/python/main.py", line 7, in main
[main]     ser = serial.Serial(PORT, BAUD, timeout=1)
[main]   File "/app/.cache/.venv/lib/python3.13/site-packages/serial/serialutil.py", line 244, in __init__
[main]     self.open()
[main]     ~~~~~~~~~^^
[main]   File "/app/.cache/.venv/lib/python3.13/site-packages/serial/serialposix.py", line 325, in open
[main]     raise SerialException(msg.errno, "could not open port {}: {}".format(self._port, msg))
[main] serial.serialutil.SerialException: [Errno 2] could not open port /dev/ttyACM0: [Errno 2] No such file or directory: '/dev/ttyACM0'

This is my simple code that I want to run:

import serial

PORT = "/dev/ttyACM0"
BAUD = 115200

def main():
    ser = serial.Serial(PORT, BAUD, timeout=1)
    buffer = b""
    print("Pronto, in attesa di scansioni...")
    while True:
        b = ser.read(1)
        if not b:
            continue
        if b in b"\r\n":
            if buffer:
                code = buffer.decode("ascii", errors="ignore")
                print("Letto:", code, flush=True)
                buffer = b""
        else:
            buffer += b

if __name__ == "__main__":
    main()

Permissions?

What does ls -l /dev/tty*
Show for that device?

Owned by dialout?

Does the groups command show that arduino user have dialout listed.
You might try adduser command to add.

Or add capabilities chmod

@checco_ux

Please see Issues with extra python packages (evdev) - #11 by ptillisch for an explanation on why it is not working.

Cheers.

@manchuino thanks for the response, so is not possible to get access directly on standard linux i/o inside the container?

It seems counter-intuitive to have a fully fledged linux computer and the capability of connecting usb peripherals but can't use them.

Because the alternative is to expose them to the microcontroller and RPC them to python but from what I could discover the microcontroller can't access usb peripherals

Right now I solved this issue in a way somewhat "discutibile":

python script running as a daemon inside linux (not containerized from applab) that reads data from the barcode scanner -> saves the last barcode to a txt inside a app lab project -> app lab app reads it and calls a few REST apis AND at the same time -> the microcontroller is updated with Bridge to give user feedback via LEDS

Hi @checco_ux

Future releases will allow specifying a list of devices from the host to be shared with the container environment.

Cheers.