mirror of
https://github.com/YikeStone/ros_arduino_bridge.git
synced 2025-08-03 11:14:08 +05:30
Close the serial port when exiting arduino_node.py
This commit is contained in:
parent
174878c7ab
commit
ef83edc1dc
@ -27,6 +27,7 @@ from ros_arduino_python.base_controller import BaseController
|
||||
from geometry_msgs.msg import Twist
|
||||
import os, time
|
||||
import thread
|
||||
from serial.serialutil import SerialException
|
||||
|
||||
class ArduinoROS():
|
||||
def __init__(self):
|
||||
@ -201,6 +202,8 @@ class ArduinoROS():
|
||||
return AnalogReadResponse(value)
|
||||
|
||||
def shutdown(self):
|
||||
rospy.loginfo("Shutting down Arduino Node...")
|
||||
|
||||
# Stop the robot
|
||||
try:
|
||||
rospy.loginfo("Stopping the robot...")
|
||||
@ -208,7 +211,19 @@ class ArduinoROS():
|
||||
rospy.sleep(2)
|
||||
except:
|
||||
pass
|
||||
rospy.loginfo("Shutting down Arduino Node...")
|
||||
|
||||
# Close the serial port
|
||||
try:
|
||||
self.controller.close()
|
||||
except:
|
||||
pass
|
||||
finally:
|
||||
rospy.loginfo("Serial port closed.")
|
||||
os._exit(0)
|
||||
|
||||
if __name__ == '__main__':
|
||||
try:
|
||||
myArduino = ArduinoROS()
|
||||
except SerialException:
|
||||
rospy.logerr("Serial exception trying to open port.")
|
||||
os._exit(0)
|
||||
|
Loading…
x
Reference in New Issue
Block a user