The serial port is used under Linux. The serial port number will change with the insertion order of multiple serial ports. This problem can be solved by setting the serial port alias.
Create a new ydlidar_ports.rules
file and write the corresponding serial port rules to the file.
sudo gedit /etc/udev/rules.d/ydlidar_ports.rules
or
sudo vim /etc/udev/rules.d/ydlidar_ports.rules
udevadm info -a -n /dev/ttyUSB0 | grep KERNELS
udevadm info -a -n /dev/ttyUSB1 | grep KERNELS
Write the first KERNELS queried above into the new ydlidar_ports.rules
file. Add these two following rules in it.
SUBSYSTEM=="tty", KERNELS=="1-1:1.0", SYMLINK+="ydlidar", MODE="0666", GROUP:="dialout"
SUBSYSTEM=="tty", KERNELS=="1-2:1.0", SYMLINK+="ydlidar1", MODE="0666", GROUP:="dialout"
Save the file and close it. Then as root, tell systemd-udevd to reload the rules files (this also reloads other databases such as the kernel module index), by running.
sudo udevadm control --reload
and
sudo service udev reload
sudo service udev restart
Note: If it doesn't work, plug and unplug the USB or restart the computer
ls -l /dev/ydlidar*
lrwxrwxrwx 1 root dialout 7 Feb 17 13:27 /dev/ydlidar -> ttyUSB0
lrwxrwxrwx 1 root dialout 7 Feb 17 13:27 /dev/ydlidar1 -> ttyUSB1