whaleygeek / bitio

A micro:bit I/O device library for Python
Other
93 stars 32 forks source link

can't set serial port #20

Open titimoby opened 7 years ago

titimoby commented 7 years ago

(Ubuntu 17.04, user added to dialout group) After flashing bitio.hex I launched counter.py but it loops through a cycle:

No micro:bit has previously been detected Scanning for serial ports remove device, then press ENTER scanning... found 98 device(s) plug in device, then press ENTER scanning... found 99 device(s) found 1 new device selected:/dev/ttyACM0 Do you want this device to be remembered? (Y/N)Y connecting... warning:Could not open the serial port that was remembered from last time Scanning for serial ports remove micro:bit, then press ENTER scanning... found 98 micro:bit(s) plug in micro:bit, then press ENTER scanning... found 99 micro:bit(s) found 1 new micro:bit selected:/dev/ttyACM0 Do you want this micro:bit to be remembered? (Y/N)Y warning:Could not open the serial port that was remembered from last time Scanning for serial ports remove micro:bit, then press ENTER scanning... found 98 micro:bit(s) plug in micro:bit, then press ENTER scanning... found 99 micro:bit(s) found 1 new micro:bit selected:/dev/ttyACM0 Do you want this micro:bit to be remembered? (Y/N)Y warning:Could not open the serial port that was remembered from last time Scanning for serial ports remove micro:bit, then press ENTER

whaleygeek commented 7 years ago

Can you see if you can open the serial port with a terminal program logged in as the same user? e.g. miniterm, using /dev/ttyACM0

Also can you paste the contents here of your portscan.cache file that is in the same directory as counter.py

Finally, can you run it in debug mode like this:

python3 counter.py debug

and paste the output here

Thanks

whaleygeek commented 7 years ago

P.S. debug is triggered from this line, so just put the word 'debug' on the command line and it will output more verbose debug info to the console.

https://github.com/whaleygeek/bitio/blob/master/src/microbit/__init__.py#L28

# Allow user to set debug flag on command line
if 'debug' in sys.argv:
    DEBUG = True
titimoby commented 7 years ago

I could connect using "screen" but I didn't see anything outgoing (but I imagine I need to push commands before)

thierry-laptop% python3 counter.py debug
Using path:/home/thierry/Dropbox/MixTeen/SoftShake2017/code/additional/microbit
Yay, I loaded the BITIO packaged pyserial
will reuse cache or scan for new port
No micro:bit has previously been detected
Scanning for serial ports
remove device, then press ENTER
scanning...
found 98 device(s)
plug in device, then press ENTER
scanning...
found 99 device(s)
found 1 new device
selected:/dev/ttyACM0
Do you want this device to be remembered? (Y/N)Y
connecting...
getting active serial port connection to micro:bit
warning:Could not open the serial port that was remembered from last time
Scanning for serial ports
remove micro:bit, then press ENTER
titimoby commented 7 years ago

I have no portscan.cache file, nowhere...

I tried to add one with a simple touch portscan.cache but after running counter.py, the file has been deleted

titimoby commented 7 years ago

I wanted to understand what was wrong and I tried to launch counter.py from PyCharm and put a breakpoint in getSerial in init ... and it worked...

guess I need to learn pdb or other command line debugger to see what's different when I launch from my shell

Edit: arglll, you're hard with my novice skills : step into or put breakpoint in init of a module that is triggered at import... It's a bit too high for me :) Edit2: ok, I found usage of pdb.set_trace() inserted in init.py let's see

titimoby commented 7 years ago

Woooooow, that is weird. I successfully used a breakpoint inside init.py and the program went smooth then. The problem is only when I run it in a normal way...

whaleygeek commented 7 years ago

Perhaps you don't have create access to the folder where it is trying to store portscan.cache?

That file would normally be created in the same folder as the script (counter.py), although that does assume that the current working directory is there too.

I usually open a terminal and cd to the folder where counter.py is, and run it from there, to be sure that cwd is where you expect it to be.

What was the output from adding debug to the command line, in the failing case? Can you paste that here?

zeth commented 6 years ago

I managed to get it to work on Ubuntu 18.04 by adding a print statement telling me what the exceptions were.

First I had error 13 (PermissionError), which was fixed with:

sudo adduser zethg dialout

Then I had 16 (device or resource busy). This was because the built in dial up modem support was claiming the device. This was fixed with:

sudo apt-get purge modemmanager

(Note, don't do this if you need to use a real dial up modem.)

Hope that helps anyone that gets to this issue on Google as I did.

xx

DavidWhaleMEF commented 6 years ago

Super, thanks @zeth this is great detective work!

thebotmakes commented 5 years ago

Thanks Zeth, had the same issue and this sorted it right out. Cheers!