Forum > Linux

[SOLVED] How to read from a serial device without sudo-rights?

(1/2) > >>

My program uses unit SynaSer from Synapse to read data from a serial device. Everything is fine, but my program needs sudo rights. I want to avoid this.

In is written:

--- Quote ---Before starting, make sure to authorize your device on Linux. An option is to create a persistent UDEV rule for each device. For example, the following approach apply mode "0064" for the device specified by 'serial', 'idVendor' and 'idProduct' attributes:

--- Code: Text  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---# create a new dev rule based on some constantsecho 'SUBSYSTEM=="tty", ATTRS{serial}=="A1004chl", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6001", MODE="0664"' | sudo tee /etc/udev/rules.d/50-usb-serial.rules > /dev/null # reload rulessudo udevadm control --reload-rules # re-add all devicessudo udevadm trigger # testls -al /dev/ttyUSB0 # you may want to reboot your systemsudo reboot
--- End quote ---

I don't understand this, but it sounds to me like this could be a way to avoid sudo-rights. Is this correct?

If yes, please help me to find the correct commands for my case. My program uses '/dev/ttyS0'. I don't know Vendor-ID or Product-ID etc. I'm a bloody beginner to this kind of Linux stuff, so some explainations what your command does would be very welcome.

I'm on Linux Ubuntu 18.04. Thanks in advance.

The first hit I got when searching for the topic was this

You would have to figure out how things are setup on your linux distro but it should be similar.

For vendor/product id see this

The udev rules are needed.

They set up the device with the correct ownership.

You can't rely on simply changing the owner/group/permissions as the device nodes are created in a temporary directory and the names are not always the same.

In the udev rules can also make provide a consistent device name that you can use.

The udev rule setup is the same for most mainstream Linux distros (Debian/Ubuntu and based on them, arch and based on it, Fedora and based on it, and many others, and has not changed in over 10 years).



[0] Message Index

[#] Next page

Go to full version