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
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
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
# 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
print "Contacting Xbees : ", network_ids # Open serial port ser = serial.Serial(xbee_port, 57600, timeout=0.01) ser.flush() ser.flushInput() ser.flushOutput() time.sleep(1) # Create API object xbee = XBee(ser, escaped=True) for xid in network_ids: client_ports[xid] = FakeSerial(xid, xbee) time.sleep(.2) clients[xid] = SerialClient(client_ports[xid]) threads = [threading.Thread(target=c.run) for c in clients.values()] for t in threads: t.deamon = True t.start() while not rospy.is_shutdown(): try: msg = xbee.wait_read_frame() if (debug): print "Received ", msg if msg['id'] == 'rx': src = msg['source_addr']
pass def flushOutput(self): pass if __name__=="__main__": rospy.init_node("serial_node") port = rospy.get_param('~port','/dev/ttyRPMSG30') sys.argv = rospy.myargv(argv=sys.argv) if len(sys.argv) >= 2 : port = sys.argv[1] if port == "/dev/m4char": port = M4charStream() while not rospy.is_shutdown(): try: rospy.loginfo("Opening {}".format(port)) client = SerialClient(port) client.run() except KeyboardInterrupt: break except SerialException: sleep(1.0) continue except OSError: sleep(1.0) continue
def __init__(self, *args, **kwargs): kwargs.pop('fix_pyserial_for_test', None) _SerialClient.__init__(self, *args, **kwargs) rospy.Service('~hard_reset', Empty, self.hard_reset)
def main_loop(): while not rospy.is_shutdown(): try: serial_client.run() except KeyboardInterrupt: rospy.loginfo("Keyboard interrupt") return except SerialException: sleep(1.0) continue except OSError: sleep(1.0) continue if __name__ == '__main__': rospy.init_node("serial_node") baud = None port = None if not port: port = rospy.get_param('~port','/dev/ttyUSB0') if not baud: baud = int(rospy.get_param('~baud','57600')) #57600 serial_client = SerialClient(port, baud) main_loop()