#133 UnicodeEncodeError

v2.6
closed-fixed
None
5
2013-10-17
2012-12-02
No

From https://bugs.archlinux.org/task/29530:

When receiving invalid characters from serial, miniterm.py(the useful demo tool for python-pyserial) crashes. I think this is because miniterm.py is not meant to run in python3(the default python for arch).

Steps to reproduce:
* Open a serial port
* Receive invalid data(I managed to do it by playing with the RX wire, but i think wrong baud rates will also work)
* UnicodeEncodeError: 'ascii' codec can't encode character '\x97' in position 0: ordinal not in range(128)

Logs:
alex@alex-laptop:~% head -n 1 `which miniterm.py`
#!/usr/bin/python
alex@alex-laptop:~% file /usr/bin/python
/usr/bin/python: symbolic link to `python3'
alex@alex-laptop:~% miniterm.py --port /dev/ttyUSB0 --baud 19200 --rts=0 --dtr=0
--- Miniterm on /dev/ttyUSB0: 19200,8,N,1 ---
--- Quit: Ctrl+] | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---
--- forcing DTR inactive
--- forcing RTS inactive
Initialization Done.Mosfet 14 192uA on:1
Mosfet 14 193uA on:1
Mosfet 14 193uA on:1
Mosfet 14 193uA on:1
Mosfet 14 193uA on:1
Mosfet 14 193uA on:1
Mosfet 14 192uA on:1
Mosfet 14 193uA on:1
Mosfet 14 193uA on:1
Mosfet 14 193uA on:1
Mosfet 14 193uA on:1
Mosfet 14 193uA on:1
Mosfet 31 13uA on:1
Initialization Done.SkException in thread Thread-1:
Traceback (most recent call last):
File "/usr/lib/python3.2/threading.py", line 740, in _bootstrap_inner
self.run()
File "/usr/lib/python3.2/threading.py", line 693, in run
self._target(*self._args, **self._kwargs)
File "/usr/bin/miniterm.py", line 227, in reader
sys.stdout.write(data)
UnicodeEncodeError: 'ascii' codec can't encode character '\x97' in position 0: ordinal not in range(128)

The way I go around this is to use miniterm2(which i think is the same thing with the #! line changed), but it's really annoying having different stuff in makefiles for other OSs. What i suggest is to make python-pyserial(the python3 one) not come with a miniterm.py, and just let the python2-pyserial package take care of it(rename miniterm2.py to miniterm.py).

Discussion

  • Chris Liechti

    Chris Liechti - 2013-05-31
    • Group: --> v1.0 (example)
     
  • Chris Liechti

    Chris Liechti - 2013-05-31

    pySerial 2.6 includes miniterm in the package instead of example. This means that serial.tools.miniterm runs through the 2to3 conversion and should work better. it can then also be started with python -m serial.tools.miniterm

     
  • Chris Liechti

    Chris Liechti - 2013-10-17
    • status: open --> closed-fixed
    • assigned_to: Chris Liechti
    • Group: v1.0 (example) --> v2.6
     
  • Chris Liechti

    Chris Liechti - 2013-10-17

    2.7 released

    the latest version may work better.
    also a workaroudn is to use the "debug mode" (-D) where it does not print non-ascii characters

     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks