def setupSerial(portChoice): print("Setting up...") # if HARDCODED_PORT is '', then the user will get a choice #HARDCODED_PORT = '/dev/tty.wchusbserial1410' HARDCODED_PORT = '' # choose port if portChoice == None: portChoiceInt = 0 if HARDCODED_PORT == '': ports = availablePorts.serial_ports() if len(ports) == 1: # just choose the first print("Choosing: " + ports[0]) portChoice = ports[0] else: if portChoiceInt == 0: print("Please choose a port:") for idx, p in enumerate(ports): print("\t" + str(idx + 1) + ") " + p) portChoiceInt = int(input()) portChoice = ports[portChoiceInt - 1] else: portChoice = HARDCODED_PORT # set up serial port ser = serial.Serial(portChoice, 115200, timeout=0.1) # wait a bit time.sleep(2) return ser
# if HARDCODED_PORT is '', then the user will get a choice #HARDCODED_PORT = '/dev/tty.wchusbserial1410' HARDCODED_PORT = '' if len(sys.argv) == 1: print("Usage:\n\ttextToBean filename [port choice]") quit() filePath = sys.argv[1] if len(sys.argv) > 2: portChoiceInt = int(sys.argv[2]) else: portChoiceInt = 0 # choose port if HARDCODED_PORT == '': ports = availablePorts.serial_ports() if len(ports) == 1: # just choose the first print("Choosing: " + ports[0]) portChoice = ports[0] else: if portChoiceInt == 0: print("Please choose a port:") for idx, p in enumerate(ports): print("\t" + str(idx + 1) + ") " + p) portChoiceInt = int(input()) portChoice = ports[portChoiceInt - 1] else: portChoice = HARDCODED_PORT