Need help debugging with REPL
Need help debugging with REPL
This is my first post. By way of introduction, I'm a longtime programmer currently using E-Lab Pascal (from Germany) for embedded projects with Atmel AVR chips, and Labview for data acquisition and analysis. I also used Ada for about 8 years. I've never used Python and am just beginning to work with Micropython. I work at a university and have a prototyping shop where I develop software and hardware for research projects.
I want to set up a wireless connection with Peter Hinch's radio_fast. I haven't gotten that to work yet; it won't communicate with the Sparkfun nRF24l01+ module. But that's kind of beside the point. Where I really need help is getting the traceback from REPL when a program dies. I'm using PuTTY on a Windows machine. I connect my Pyboard ver. 1.1 via USB. I'm almost never able to see the traceback.
Let's say I press the RESET button on the Pyboard. At that point the COM port connection to putty is broken and then restarted as the Pyboard boots and the program runs. If it's a broken program, it will immediately break out to REPL and print a traceback. Even if I had putty running before the reset, I can't get the traceback to show up. Pressing Ctrl-C doesn't help. So, how do people keep a COM port open in order to see the traceback when it occurs?
I've also tried using pyb.repl_uart() to get output sent to someplace other than the USB COM port, but that doesn't work either. Maybe I'm not using it correctly - an example would be welcome.
Thanks for any help.
I want to set up a wireless connection with Peter Hinch's radio_fast. I haven't gotten that to work yet; it won't communicate with the Sparkfun nRF24l01+ module. But that's kind of beside the point. Where I really need help is getting the traceback from REPL when a program dies. I'm using PuTTY on a Windows machine. I connect my Pyboard ver. 1.1 via USB. I'm almost never able to see the traceback.
Let's say I press the RESET button on the Pyboard. At that point the COM port connection to putty is broken and then restarted as the Pyboard boots and the program runs. If it's a broken program, it will immediately break out to REPL and print a traceback. Even if I had putty running before the reset, I can't get the traceback to show up. Pressing Ctrl-C doesn't help. So, how do people keep a COM port open in order to see the traceback when it occurs?
I've also tried using pyb.repl_uart() to get output sent to someplace other than the USB COM port, but that doesn't work either. Maybe I'm not using it correctly - an example would be welcome.
Thanks for any help.
Re: Need help debugging with REPL
When I'm debugging stuff, I tend to not call my program main.py but call it something else.
Then when I get to the REPL, I'll import whatever I called my main program.
Under linux, I often use a little python program I wrote called usb-ser-mon.py which detects USB disconnects and reconnects, and it will automatically open and close the tty. Since its a program it can do it fast enough that it will catch that startup stuff.
https://github.com/dhylands/usb-ser-mon
Then when I get to the REPL, I'll import whatever I called my main program.
Under linux, I often use a little python program I wrote called usb-ser-mon.py which detects USB disconnects and reconnects, and it will automatically open and close the tty. Since its a program it can do it fast enough that it will catch that startup stuff.
https://github.com/dhylands/usb-ser-mon
Re: Need help debugging with REPL
Any idea if this will work under Windows?
Re: Need help debugging with REPL
I don't see why not. I do it using the linux version all the time.
Re: Need help debugging with REPL
Hello Dave,
usb-ser-mon seems to me a useful tool. I tried it and ran into a bug. Here is the screen content:
I'm using debian Jessie, Python 3.4
Regards, Robert
usb-ser-mon seems to me a useful tool. I tried it and ran into a bug. Here is the screen content:
Code: Select all
robert@DELL-HH:~/Downloads/MicroPython/usb-ser-mon$ ./usb-ser-mon.py -n Micro
USB Serial device with vendor 'MicroPython' serial '347A35663333' connected @/dev/ttyACM0
Use Control-X to exit.
Traceback (most recent call last):
File "./usb-ser-mon.py", line 310, in main
debug=args.debug, echo=args.echo)
File "./usb-ser-mon.py", line 192, in usb_serial_mon
serial_port.write(data)
File "/usr/local/lib/python3.4/dist-packages/serial/serialposix.py", line 491, in write
d = to_bytes(data)
File "/usr/local/lib/python3.4/dist-packages/serial/serialutil.py", line 76, in to_bytes
b.append(item) # this one handles int and str for our emulation and ints for Python 3.x
TypeError: an integer is required
robert@DELL-HH:~/Downloads/MicroPython/usb-ser-mon$
Regards, Robert
Re: Need help debugging with REPL
That's actually an error in pyserial (Edit: Hmm. maybe not).
A new version of pyserial was released a while ago. So the first thing I'd try is to run: You may need to use sudo to install globally.
If that doesn't fix it, then I think that there is a way to work around in my code.
A new version of pyserial was released a while ago. So the first thing I'd try is to run:
Code: Select all
pip3 install --upgrade pyserial
If that doesn't fix it, then I think that there is a way to work around in my code.
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: Need help debugging with REPL
@BillG Regarding my radio_fast driver, I'm assuming you have a Pyboard with Sparkfun radio at each end. After copying the driver I'd start out by copying tests.py to both Pyboards. Ensure you've edited config.py to provide master_config and slave_config values to match your wiring and copy that to both Pyboards. At the REPL you should be able to issue
at one end, and
at the other. Note that, as suggested by @dhylands, this assumes a main.py which does nothing - the Pyboards take you to a REPL and you run your tests from there.
Code: Select all
import tests
tests.test_master()
Code: Select all
import tests
tests.test_slave()
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
Re: Need help debugging with REPL
@Roberthh - I just pushed a change to usb-ser-mon.py that should address the particular crash you saw above.
Re: Need help debugging with REPL
Hi Dave,
thanks for the swift reply. That change did change the error message.
But it may also be that my system is a little bit messy. I have also change the first line of the script to call python3, otherwise python2 is chosen.
Robert
thanks for the swift reply. That change did change the error message.
Code: Select all
robert@DELL-HH:~/Downloads/MicroPython/usb-ser-mon$ ./usb-ser-mon.py -n Micro
USB Serial device with vendor 'MicroPython' serial '347A35663333' connected @/dev/ttyACM0
Use Control-X to exit.
Traceback (most recent call last):
File "./usb-ser-mon.py", line 312, in main
debug=args.debug, echo=args.echo)
File "./usb-ser-mon.py", line 194, in usb_serial_mon
serial_port.write(data)
File "/usr/local/lib/python3.4/dist-packages/serial/serialposix.py", line 518, in write
d = to_bytes(data)
File "/usr/local/lib/python3.4/dist-packages/serial/serialutil.py", line 58, in to_bytes
raise TypeError('unicode strings are not supported, please encode to bytes: %r' % (seq,))
TypeError: unicode strings are not supported, please encode to bytes: '\r'
robert@DELL-HH:~/Downloads/MicroPython/usb-ser-mon$
Robert
Re: Need help debugging with REPL
That particular script was written for python 2, and never tested with 3.