I followed the user guide, but can't detect device either by autodetecting or specifying serial port.
After modifying serial port detecting part in s2m.py, I can detect device either by autodetecting or specifying serial port now.
# if no com port was specified, try doing auto discover.
if com_port is None:
print('Autodetecting serial port. Please wait...')
if sys.platform.startswith('darwin'):
locations = glob.glob('/dev/tty.[usb*]*')
locations = glob.glob('/dev/tty.[wchusb*]*') + locations
locations.append('end')
# for everyone else, here is a list of possible ports
else:
locations = ['dev/ttyACM0', '/dev/ttyACM0', '/dev/ttyACM1',
'/dev/ttyACM2', '/dev/ttyACM3', '/dev/ttyACM4',
'/dev/ttyACM5', '/dev/ttyUSB0', '/dev/ttyUSB1',
'/dev/ttyUSB2', '/dev/ttyUSB3', '/dev/ttyUSB4',
'/dev/ttyUSB5', '/dev/ttyUSB6', '/dev/ttyUSB7',
'/dev/ttyUSB8', '/dev/ttyUSB9',
'/dev/ttyUSB10',
'/dev/ttyS0', '/dev/ttyS1', '/dev/ttyS2',
'/dev/tty.usbserial', '/dev/tty.usbmodem', 'com2',
'com3', 'com4', 'com5', 'com6', 'com7', 'com8',
'com9', 'com10', 'com11', 'com12', 'com13',
'com14', 'com15', 'com16', 'com17', 'com18',
'com19', 'com20', 'com21', 'com22', 'com23', 'com24',
'com25', 'com26', 'com27', 'com28', 'com29', 'com30',
'com31', 'com32', 'com33', 'com34', 'com35', 'com36',
'com1', 'end'
]
detected = None
for device in locations:
try:
self.micro_bit_serial = serial.Serial(port=device, baudrate=115200,
timeout=.1)
detected = device
break
except serial.SerialException:
if device == 'end':
print('Unable to find Serial Port, Please plug in '
'cable or check cable connections.')
detected = None
exit()
except OSError:
pass
self.com_port = detected
# if no com port was specified, try doing auto discover.
if com_port is None:
print('Autodetecting serial port. Please wait...')
# listing all serial ports and checking if there is a micro:bit board
import re
from serial.tools.list_ports import comports
for port, desc, opts in comports():
if 'VID:PID=' in opts:
vid, pid = re.search('VID:PID=(\w+):(\w+)', opts).groups()
vid, pid = int(vid, 16), int(pid, 16)
if vid == 0x0D28 and pid == 0x0204:
self.com_port = port
break
if self.com_port is None:
print('Unable to detect Serial Port, Please plug in '
'cable or check cable connections.')
sys.exit(0)