def main(argv):
    if len(argv) == 2:
        port_name = rospy.get_param("~port", argv[1])
    else:
        print("Usage: python serial_node.py <port_name>")
        return 1

    rospy.init_node("Pi_Node", log_level=rospy.DEBUG)
    rospy.loginfo("ROS serial python node initialised")
    baud = int(rospy.get_param("~baud", "57600"))
    tcp_portnum = int(
        rospy.get_param("/rosserial_embeddedlinux/tcp_port", "11411"))
    fork_server = rospy.get_param('/rosserial_embeddedlinux/fork_server',
                                  False)

    if port_name == "tcp":
        server = RossSerialServer(tcp_portnm, fork_Server)
        rospy.loginfo("Waiting for socket connections on port %d" %
                      tcp_portnum)
        try:
            server.losten()
        except KeyboardInterupt:
            rospy.loginfo()
        finally:
            rospy.loginfo("Shutting down")
            for process in multiprocessing.active_children():
                rospy.lofinfo("Shutting down process %r", process)
                process.terminate()
                process.join()
            rospy.loginfo("End")
    else:
        while not rospy.is_shutdown():
            rospy.loginfo("Connecting to %s at %d baud" % (port_name, baud))
            try:
                client = SerialClient(port_name, baud)
                client.run()
            except SerialException:
                sleep(1)
                continue
            except OSError:
                sleep(1)
                continue
Exemple #2
0
def main():
    rospy.init_node("Arduino_serial_node", anonymous=False)

    #rospy.init_node("Arduino_serial_node")
    rospy.loginfo("ROS Serial Python Node")

    port_name = rospy.get_param('~port', '/dev/ttyUSB0')
    baud = int(rospy.get_param('~baud', '115200'))

    # for systems where pyserial yields errors in the fcntl.ioctl(self.fd, TIOCMBIS, \
    # TIOCM_DTR_str) line, which causes an IOError, when using simulated port
    fix_pyserial_for_test = rospy.get_param('~fix_pyserial_for_test', False)

    # TODO: do we really want command line params in addition to parameter server params?
    sys.argv = rospy.myargv(argv=sys.argv)
    if len(sys.argv) >= 2:
        port_name = sys.argv[1]
    if len(sys.argv) == 3:
        tcp_portnum = int(sys.argv[2])

    # Use serial port
    while not rospy.is_shutdown():
        rospy.loginfo("Connecting to %s at %d baud" % (port_name, baud))
        try:
            client = SerialClient(port_name,
                                  baud,
                                  fix_pyserial_for_test=fix_pyserial_for_test)
            client.run()
        except KeyboardInterrupt:
            finshed = 1
            exit(1)
            break
        except SerialException:
            sleep(1.0)
            continue
        except OSError:
            sleep(1.0)
            continue
Exemple #3
0
            server.listen()
        except KeyboardInterrupt:
            rospy.loginfo("got keyboard interrupt")
        finally:
            rospy.loginfo("Shutting down")
            for process in multiprocessing.active_children():
                rospy.loginfo("Shutting down process %r", process)
                process.terminate()
                process.join()
            rospy.loginfo("All done")

    else :          # Use serial port
        while not rospy.is_shutdown():
            rospy.loginfo("Connecting to %s at %d baud" % (port_name,baud) )
            try:
                client = SerialClient(port_name, baud, fix_pyserial_for_test=fix_pyserial_for_test)
                client.run()
            except KeyboardInterrupt:
                break
            except SerialException:
                sleep(1.0)
                continue
            except OSError:
                sleep(1.0)
                continue
            except:
                rospy.logwarn("Unexpected Error: %s", sys.exc_info()[0])
                client.port.close()
                sleep(1.0)
                continue
    # TODO: do we really want command line params in addition to parameter server params?
    sys.argv = rospy.myargv(argv=sys.argv)
    if len(sys.argv) == 2 :
        port_name  = sys.argv[1]
    if len(sys.argv) == 3 :
        tcp_portnum = int(sys.argv[2])
    
    if port_name == "tcp" :
        server = RosSerialServer(tcp_portnum, fork_server)
        rospy.loginfo("Waiting for socket connections on port %d" % tcp_portnum)
        try:
            server.listen()
        except KeyboardInterrupt:
            rospy.loginfo("got keyboard interrupt")
        finally:
            rospy.loginfo("Shutting down")
            for process in multiprocessing.active_children():
                rospy.loginfo("Shutting down process %r", process)
                process.terminate()
                process.join()
            rospy.loginfo("All done")

    else :          # Use serial port 
        rospy.loginfo("Connecting to %s at %d baud" % (port_name,baud) )
        client = SerialClient(port_name, baud)
        try:
            client.run()
        except KeyboardInterrupt:
            pass