![错误,使用 systemd 启动时无法绑定到指定的串口 /dev/ttyUSB0](https://linux22.com/image/131525/%E9%94%99%E8%AF%AF%EF%BC%8C%E4%BD%BF%E7%94%A8%20systemd%20%E5%90%AF%E5%8A%A8%E6%97%B6%E6%97%A0%E6%B3%95%E7%BB%91%E5%AE%9A%E5%88%B0%E6%8C%87%E5%AE%9A%E7%9A%84%E4%B8%B2%E5%8F%A3%20%2Fdev%2FttyUSB0.png)
我正在尝试使用 systemd 在启动过程中运行启动文件。启动文件启动 rplidar。当我直接运行该.sh
文件时,它会启动激光雷达。
$ systemctl status rosCore.service
● rosCore.service - start roscore
Loaded: loaded (/etc/systemd/system/rosCore.service; enabled; vendor preset: enabled)
Active: active (running) since Sun 2018-04-15 09:31:13 CEST; 1min 5s ago
Main PID: 710 (rosCoreService.)
CGroup: /system.slice/rosCore.service
├─ 710 /bin/bash /usr/local/bin/rosCoreService.sh
├─ 940 /usr/bin/python /opt/ros/kinetic/bin/roslaunch rplidar_ros rplidar.launch
├─1029 /usr/bin/python /opt/ros/kinetic/bin/rosmaster --core -p 11311 -w 3 __log:=/root/.ros/log/fa4e9410-407e-11e8-acf8-f5f547bf4eb3/master.log
└─1069 /opt/ros/kinetic/lib/rosout/rosout __name:=rosout __log:=/root/.ros/log/fa4e9410-407e-11e8-acf8-f5f547bf4eb3/rosout-1.log
Apr 15 09:31:13 PLRV1WB1 systemd[1]: Started start roscore.
Apr 15 09:31:14 PLRV1WB1 rosCoreService.sh[710]: Error, cannot bind to the specified serial port /dev/ttyUSB0.
Apr 15 09:31:15 PLRV1WB1 rosCoreService.sh[710]: RPLIDAR running on ROS package rplidar_ros
Apr 15 09:31:15 PLRV1WB1 rosCoreService.sh[710]: SDK Version: 1.5.7
Apr 15 09:31:15 PLRV1WB1 rosCoreService.sh[710]: [rplidarNode-2] process has died [pid 1072, exit code 255, cmd /home/plrv1wb1/catkin_ws/devel/lib/rplidar_ros/rpli
Apr 15 09:31:15 PLRV1WB1 rosCoreService.sh[710]: log file: /root/.ros/log/fa4e9410-407e-11e8-acf8-f5f547bf4eb3/rplidarNode-2*.log
错误是
Apr 15 09:31:14 PLRV1WB1 rosCoreService.sh[710]: Error, cannot bind to the specified serial port /dev/ttyUSB0.
我的服务和 .sh 文件如下所示。
/etc/systemd/system/
******* rosCore.service *************
Unit]
Description=start roscore
Restart=on-abort
[Service]
ExecStart=/usr/local/bin/rosCoreService.sh
[Install]
WantedBy=default.target
**********************************************
/usr/local/bin/
*******************rosCoreService.sh **********
#!/bin/bash
source /home/bc/.bashrc
source /opt/ros/kinetic/setup.bash
source /home/bc/catkin_ws/devel/setup.bash
roslaunch rplidar_ros rplidar.launch
***************************************************
答案1
添加
After=dev-ttyUSB0.device
到[Unit]
街区。
如果这还不够,那么您必须在 中标记设备udev
。看man systemd.device
:
要标记 udev 设备,请在 udev 规则中使用“TAG+="systemd"”