def main(): '''Main code to illustrate the usage of TextSerial. ''' args = parse_args() if args.serialport != "0": print("Opening serial port: %s" % args.serialport) baudrate = 9600 # [bit/seconds] 115200 also works # The with statment ensures that if things go bad, then ser # will still be closed properly. with textserial.TextSerial(args.serialport, baudrate, newline=None) as ser: data_transfer(ser, ser) # with serial.Serial(args.serialport, baudrate) as serial_out: # with serial.Serial(args.serialport, baudrate) as serial_in: # data_transfer(serial_out,serial_out) else: print("No serial port. Using stdin and stdout.") data_transfer(sys.stdin, sys.stdout) print("Demo finished.")
def main(): import argparse parser = argparse.ArgumentParser( description='Client-server message test.', formatter_class=argparse.RawTextHelpFormatter, ) parser.add_argument("-d0", help="Debug off", action="store_false", dest="debug") parser.add_argument("-s", help="Set serial port for protocol", nargs="?", type=str, dest="serial_port_name", default="/dev/ttyACM0") args = parser.parse_args() debug = args.debug set_logging(debug) # this imports serial, and provides a useful wrapper around it import textserial serial_port_name = args.serial_port_name log_msg("Opening serial port: {}".format(serial_port_name)) # Open up the connection baudrate = 9600 # [bit/seconds] 115200 also works # Run the server protocol forever # The with statment ensures that if things go bad, then ser # will still be closed properly. # errors='ignore' allows any 1 byte character, not just the usual # ascii range [0,127] with textserial.TextSerial(serial_port_name, baudrate, errors='ignore', newline=None) as ser: protocol(ser, ser)
def main(): '''Main code to illustrate the usage of TextSerial. ''' args = parse_args() if args.serialport != "0": print("Opening serial port: %s" % args.serialport) baudrate = 9600 # [bit/seconds] 115200 also works with textserial.TextSerial(args.serialport, baudrate, newline=None) as ser: data_transfer(ser, ser) else: print("No serial port. Using stdin/stdout.") data_transfer(sys.stdin, sys.stdout) print("Demo finished.")
def main(): serial_port_name = '/dev/ttyACM0' log_msg("Opening serial port: {}".format(serial_port_name)) # Open up the connection baudrate = 9600 # [bit/seconds] 115200 also works # Run the server protocol forever # The with statment ensures that if things go bad, then ser # will still be closed properly. # errors='ignore' allows any 1 byte character, not just the usual # ascii range [0,127] with textserial.TextSerial(serial_port_name, baudrate, errors='ignore', newline=None) as ser: protocol(ser, ser)
d0 = args.debugOff set_logging(d0) import textserial serial_port_name = args.serial_port_name if serial_port_name != "0": log_msg("Opening serial port: {}".format(serial_port_name)) # Open up the connection baudrate = 9600 # [bit/seconds] 115200 also works # Run the server protocol forever # The with statment ensures that if things go bad, then ser # will still be closed properly. # errors='ignore' allows any 1 byte character, not just the usual # ascii range [0,127] # creates graph and dictionaries with ancilliary data with textserial.TextSerial(serial_port_name, baudrate, errors='ignore', newline=None) as ser: server(ser, ser) # runs the server else: # if no serial port use stdin and stdout print("No serial port. Using stdin and stdout.") server(sys.stdin, sys.stdout)
if __name__ == "__main__": # Init dict to store ancillary graph data. # cost_distance() and find_nearest_waypoint() are dependents. ancillary_data = {} filename = 'edmonton-roads-2.0.1.txt' # Read graph file into graph object, store ancillary_data le_graph = read_undirected_city_graph(filename) # Process Requests while True: # Get client input, parse with textserial.TextSerial( ser=serial.serial_for_url('loop://', timeout=0)) as f: client_in = f.readline().rstrip('\r\n') # If client is making request if client_in[0] == 'R': start = (int(client_in[1]), int(client_in[2])) dest = (int(client_in[3]), int(client_in[4])) # Find nearest vertices start, dest = find_nearest_waypoint(start, dest, euclid_dist) # Find shortest path shortest_path = \ least_cost_path(le_graph, start, dest, cost_distance) # Begin path transmission if len(shortest_path) < 1: print('N ' + str(len(shortest_path)) + "\n", file=f) else: