hacklab-in / webiopi

Automatically exported from code.google.com/p/webiopi
0 stars 1 forks source link

spi.xfer() uses bytes() call w/o encoding parameter which raises an error in Python 3 #75

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
When I import webiopi.devices.spi from WebIOPi 0.6 in a custom macro and try to 
call SPI.xfer using Python 3.2 I get the following stack trace:
Traceback (most recent call last):
  File "/home/pi/Concierge/python/spicomm.py", line 73, in <module>
    print(getStatus())
  File "/home/pi/Concierge/python/spicomm.py", line 66, in getStatus
    return sendCommand("GET_STATUS")
  File "/home/pi/Concierge/python/spicomm.py", line 28, in sendCommand
    c = spi.xfer('\0')
  File "/usr/local/lib/python3.2/dist-packages/WebIOPi-0.6.0-py3.2-linux-armv6l.egg/webiopi/devices/spi.py", line 128, in xfer
    _txbuff = bytes(txbuff)
TypeError: string argument without an encoding

WebIOPi version used?
=> 0.6

Python version used?
=> 3.2.3

Distro used? (WebIOPi has only been tested on Raspbian Wheezy)
=> Raspbian Wheezy

Raspberry Pi board revision? (1 or 2)
=> 2

For Javascript side bugs, Browser?
=> n.n.

Please provide any additional information below.
=> http://docs.python.org/3.0/whatsnew/3.0.html - bullet 4
Although, spi.py has a case statement if (PYTHON_MAJOR >= 3): it calls the 
bytes() function without the encoding parameter.

Original issue reported on code.google.com by markus.d...@googlemail.com on 13 Jan 2014 at 9:08

GoogleCodeExporter commented 9 years ago
when using xfer, you are supposed to use binary and provide a binary array, not 
a string.
try to use spi.xfer([0x00]) instead

Original comment by tro...@trouch.com on 13 Jan 2014 at 9:53

GoogleCodeExporter commented 9 years ago
Hi Eric,

you're right. It was PEBCAK. I'm quite new to Python in general and WebIOPi in 
particular. I can confirm that it's working the suggested way. Denoting all 
strings as byte strings (b'GET_STATUS' as well as b'\n') does the job. If you 
feel like you may consider adding a respective check in spi.py for this 
particular case (just in case I'm not the only newbie stumbling upon this) ;-)

Thanks for the quick support and keep up the good work! :-)

Original comment by markus.d...@googlemail.com on 13 Jan 2014 at 8:41

GoogleCodeExporter commented 9 years ago
Fine, so I close the issue

Original comment by tro...@trouch.com on 13 Jan 2014 at 9:07