How to access USB with Torizon Visual Code Extension (python)

Simply put, I would like to access the USB in a manner similar to UARTS.

How can the USB be accessed through /dev?
In the VSCode application what would be entered for “Configurations-Devices”?
What would be entered under “build-commands” property, “requirements.txt”, and any other?

Thanks

Greetings @CEK,

Generally adding a bind-mount that shares the respective /dev/* entry will suffice. To do this in our extension is demonstrated here: Torizon Best Practices Guide | Toradex Developer Center

Though you may need additional settings/permissions depending on specifically what kind of USB device this is and how it enumerates itself in Linux.

Best Regards,
Jeremias

I reviewed the torizon best practices guide and unfortunately I’m still uncertain about mounting the /dev folder as a volume.

in my situation, on my Colibri, I have a USB-to-Serial device (/dev/ttyUSB0) and a flash drive (/dev/sda) that can be plugged into 2 separate USB connectors at any time.

In regards to “Configurations-Volumes” in VScode:
What would i enter for for “key” and what would i enter for “value”?
Do i only need to enter something for the /dev folder and that handles both ttyUSB0 and sda?
Is there something else i need to do?

Sorry for my confusion

in my situation, on my Colibri, I have a USB-to-Serial device (/dev/ttyUSB0) and a flash drive (/dev/sda) that can be plugged into 2 separate USB connectors at any time.

If these USB devices can be plugged in and removed at any time then you need to use something called bind-mount propagation: Bind mounts | Docker Docs

This should allow changes in bind-mounts to be propagated to the container. For example when you plug your flash drive in it creates in /dev/sda entry. With Bind mount propagation this change in /dev should transfer into the container.

This post has an example of how you would configure this in the extension: Configuring docker dynamic USB memory access with --mount option in VS Code Torizon Extension

I reviewed the torizon best practices guide and unfortunately I’m still uncertain about mounting the /dev folder as a volume.

Could you clarify why you are uncertain? If you need /dev/ttyUSB0 inside the container then you need to bind mount this from the host. But since you just stated these USB devices can be plugged at any time and therefore may not be available at container start time you need to then bind-mount all of /dev and propagate the changes with bind mount propagation.

Maybe it’s simpler to just experiment with docker run on the command-line and figure out what arguments and flags you need for the bind-mounts to fit your use-case. Then when you figure out the correct flags you can transfer this into the extension.

Best Regards,
Jeremias

The information provided is helpful.

In VSCode, when i go to Configurations-extraparams, i’m propmted for a ‘key’ then a ‘Value’. Same with Configurations-Volumes, i’m propmted for a ‘key’ then a ‘value’. Entering what’s required for ‘key’ and ‘value’ is the uncertainty

In VSCode, when i go to Configurations-extraparams, i’m propmted for a ‘key’ then a ‘Value’.

In general for extraparms the syntax it uses is stated in the best practices article that I referenced:

The extraparms takes a key-value pair, which syntax shall match the Python API as specified in the Docker SDK for Python.

For specifically bind-propagation bind mount, there’s an example of the key-value pair in the other community post I referenced.

Same with Configurations-Volumes, i’m propmted for a ‘key’ then a ‘value’.

The key value pair syntax for volumes is stated also in the best practices article along with a video showing how it works in the extension. The key is the file/directory you want to bind-mount from outside of the container. The value is a file path where you want this bind-mounted to inside the container.

Best Regards,
Jeremias