fail( "I can't find pyserial on your system. That's odd, it should be included in this project" ) #----- PORTSCAN --------------------------------------------------------------- # reuse or scan for a new port trace("will reuse cache or scan for new port") name = portscan.getName(DEVICE_NAME) if name != None: if DEBUG: trace("Using port:" + name) PORT = name else: name = portscan.find() if name == None: fail("No port selected, giving in") PORT = name #----- CONNECT TO SERIAL ------------------------------------------------------ # get the serial port def get_serial(): s = serial.Serial(PORT) s.baudrate = BAUD s.parity = serial.PARITY_NONE s.databits = serial.EIGHTBITS s.stopbits = serial.STOPBITS_ONE s.timeout = 0 # non blocking mode
sys.path.append(thisdir) import serial #----- PORTSCAN ---------------------------------------------------------------- import portscan name = portscan.getName() if name != None: if DEBUG: print("Using port:" + name) PORT = name else: name = portscan.find() if name == None: raise ValueError("No port selected, giving in") PORT = name print("Your micro:bit has been detected") print("Now running your program...") #----- CONFIGURE SERIAL PORT --------------------------------------------------- s = serial.Serial(PORT) s.baudrate = BAUD s.parity = serial.PARITY_NONE s.databits = serial.EIGHTBITS s.stopbits = serial.STOPBITS_ONE
# identifier. If that exists, it will just use the serial port identified # in that file. If the file does not exist, it performs a workflow that # prompts the user. Note that if you plug your micro:bit into a different # USB port or use a different USB hub configuration, this may renumber # the port and require a re-scan. Just delete the portscan.cache file # and re-run your app code, if that happens. import portscan name = portscan.getName() if name != None: if DEBUG: print("Using port:" + name) PORT = name else: name = portscan.find() if name == None: raise ValueError("No port selected, giving in") PORT = name print("Your micro:bit has been detected") print("Now running your program...") #----- CONFIGURE SERIAL PORT --------------------------------------------------- s = serial.Serial(PORT) s.baudrate = BAUD s.parity = serial.PARITY_NONE s.databits = serial.EIGHTBITS s.stopbits = serial.STOPBITS_ONE s.timeout = 0 # non blocking mode