serial_node.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 #####################################################################
4 # Software License Agreement (BSD License)
5 #
6 # Copyright (c) 2011, Willow Garage, Inc.
7 # All rights reserved.
8 #
9 # Redistribution and use in source and binary forms, with or without
10 # modification, are permitted provided that the following conditions
11 # are met:
12 #
13 # * Redistributions of source code must retain the above copyright
14 # notice, this list of conditions and the following disclaimer.
15 # * Redistributions in binary form must reproduce the above
16 # copyright notice, this list of conditions and the following
17 # disclaimer in the documentation and/or other materials provided
18 # with the distribution.
19 # * Neither the name of Willow Garage, Inc. nor the names of its
20 # contributors may be used to endorse or promote products derived
21 # from this software without specific prior written permission.
22 #
23 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 # POSSIBILITY OF SUCH DAMAGE.
35 
36 import rospy
37 from rosserial_arduino import SerialClient
38 from serial import SerialException
39 from time import sleep
40 
41 import sys
42 
43 if __name__=="__main__":
44 
45  rospy.init_node("serial_node")
46  rospy.loginfo("ROS Serial Python Node")
47 
48  port_name = rospy.get_param('~port','/dev/ttyUSB0')
49  baud = int(rospy.get_param('~baud','57600'))
50 
51  # Number of seconds of sync failure after which Arduino is auto-reset.
52  # 0 = no timeout, auto-reset disabled
53  auto_reset_timeout = int(rospy.get_param('~auto_reset_timeout','0'))
54 
55  # for systems where pyserial yields errors in the fcntl.ioctl(self.fd, TIOCMBIS, \
56  # TIOCM_DTR_str) line, which causes an IOError, when using simulated port
57  fix_pyserial_for_test = rospy.get_param('~fix_pyserial_for_test', False)
58 
59  # TODO: do we really want command line params in addition to parameter server params?
60  sys.argv = rospy.myargv(argv=sys.argv)
61  if len(sys.argv) >= 2 :
62  port_name = sys.argv[1]
63 
64  while not rospy.is_shutdown():
65  rospy.loginfo("Connecting to %s at %d baud" % (port_name, baud))
66  try:
67  client = SerialClient(port_name, baud, fix_pyserial_for_test=fix_pyserial_for_test, auto_reset_timeout=auto_reset_timeout)
68  client.run()
69  except KeyboardInterrupt:
70  break
71  except SerialException:
72  sleep(1.0)
73  continue
74  except OSError:
75  sleep(1.0)
76  continue


rosserial_arduino
Author(s): Michael Ferguson, Adam Stambler
autogenerated on Fri Jun 7 2019 22:02:56