1. Solution to USB device permission problem under Ubuntu
In Ubuntu, if you give full permissions to a USB device, you can do this
sudo chmod 777 /dev/ttyUSB0
But this is only a one-time operation. You need to re-assign permissions when unplugging and plugging in again. Here is a once-and-for-all method.
cd /etc/udev/rules.d
After entering /etc/udev/rules.d, ls checks the existing files, and then you can create a new rule file yourself
sudo touch my_ttyusb.rules
or directly
sudo gedit my_ttyusb.rules
Open and edit, the edit content is as follows, so that as long as it is a ttyUSB device in the future, it will automatically give 777 full permissions
KERNEL=="ttyUSB*", MODE:="0777", GROUP:="dialout
Then ctrl+c to save, ctrl+q to exit,
the next step is to add the user to the dialout user group
sudo usermod -a -G dialout $USER
then make it take effect immediately
sudo udevadm trigger
--------------
运行下面两条命令也可以,重新加载udev,然后再重新运行
sudo service udev reload
sudo service udev restart
Done! ! ! !
PS: Of course, the udev rules can also be deleted, just use the rm command, and then reload and start after deleting.
Second, the method of aliasing the USB device
Take the pixhawk6c flight control connected to my current onboard computer as an example,
write in the newly created my_ttyusb.rules file above
KERNEL=="ttyACM*", MODE:="0777", GROUP:="dialout"
KERNELS=="1-1:1.0", SYMLINK+="Pixhawk6c"
Explanation:
KERNEL=="ttyACM*", MODE:="0777", GROUP:="dialout"This line is to give 777 permissions to all ttyACM devices
KERNELS==“1-1:1.0”, SYMLINK+=“Pixhawk6c” This is to rename the "1-1:1.0" device
Where did 1-1:1.0 come from?
First plug in your device, then type
ls /dev/tty*
Get which one is your device, for example, mine is ttyACM7, then enter
udevadm info --attribute-walk --name=/dev/ttyACM7
Output the following information, go back to the top, pay attention to "KERNEL=="xxx" in the line below the second or third "looking at"
Find "KERNELS==1-1:1.0" (I found it in the second looking at, usually in the second and third, copy it when you see this form ab:cd)
OK, come here and go back to your my_ttyUSB.rules rule file just now
KERNEL=="ttyACM*", MODE:="0777", GROUP:="dialout"
KERNELS=="1-1:1.0", SYMLINK+="Pixhawk6c"
In addition to the above writing method, you can also write it like this. If you write it like this, you only give permission to the device "1-1:1.0" and give it an alias. Both are fine.
KERNEL=="1-1:1.0", MODE:="0777", GROUP:="dialout", SYMLINK+="Pixhawk6c"
Don't forget to let the modification take effect immediately! ! !
sudo udevadm trigger
Finally, enter the following command to view the alias results
ls -l /dev |grep ttyACM
Done! ! !