Closed anandology closed 6 years ago
microrepl from the master branch fails with following error.
$ microrepl
Traceback (most recent call last):
File "/Users/anand/anaconda/envs/rx/bin/microrepl", line 11, in <module>
sys.exit(main())
File "/Users/anand/anaconda/envs/rx/bin/microrepl.py", line 87, in main
port = find_microbit()
File "/Users/anand/anaconda/envs/rx/bin/microrepl.py", line 40, in find_microbit
vid, pid = int(vid, 16), int(pid, 16)
ValueError: invalid literal for int() with base 16: '0204 SER=9900023433984e45007210030000004d00000000ce5328bd LOCATION=250-1.4'
Okay, so it looks like we have a 2 part issue. On one hand the VID/PID string is not in the format microrepl expects and parses the PID part as 0204 SER=9900023433984e45007210030000004d00000000ce5328bd LOCATION=250-1.4
instead of just 0204
. For that PR #14 would be able to help.
On the first message however it looks like microrepl did not throw an exception, but still failed to identify the micro:bit. Looking at the code in the master branch, it looks to me like it should work in either case of the PID/VID formatted as VID:PID=d28:204
or VID:PID=0D28:0204
.
https://github.com/ntoll/microrepl/blob/14ad006e08630aa7790e9eff7361d36fb1ca3fd6/microrepl.py#L38-L42
Is the version in PyPi older with a different implementation of find_microbit()
?
Thanks for looking into this.
The following should probably do the trick with the latest PySerial:
from serial.tools.list_ports import comports as list_serial_ports
def find_microbit():
"""
Finds the port to which the device is connected.
"""
ports = list_serial_ports()
for port in ports:
if "VID:PID=0D28:0204" in port[2].upper():
return port[0]
return None
Apparently some work has gone into PySerial to make sure cross platform reporting of ports is more uniform. I don't have access to a Mac at the moment to be able to test this.
@carlosperate the version on PyPI is uploaded on 2016-03-14. So it doesn't have the code from PR #11.
The published version on PyPI is checking for pattern "VID:PID=d28:204"
on mac and that was changed to "VID:PID=0D28:0204"
in the subsequent commit. Wouldn't it be safer to check for both?
def find_microbit():
"""
Finds the port to which the device is connected.
"""
ports = list_serial_ports()
for port in ports:
hwid = port[2].upper()
if "VID:PID=0D28:0204" in hwid or "VID:PID=D28:204" in hwid:
return port[0]
return None
Fixed in 0.6
OS: Mac OS X El Captain (10.11.5)
When I tried to run microrepl after connecting microbit, it failed to identify the micro:bit.
Noticed that the code of microrepl is looking for pattern
VID:PID=d28:204
in the serial port hwid. But it looks like the serial module is returningVID:PID=0D28:0204
instead.Here is the status of serial ports after connecting micro:bit.
Changing the pattern from
'VID:PID=d28:204
toVID:PID=0D28:0204
in the darwin section seems to have fixed the issue.This was using the microrepl 0.5 installed from pypi.