bkatko / python-xbee

Automatically exported from code.google.com/p/python-xbee
MIT License
0 stars 0 forks source link

Errors in send command with python 3.3 #47

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
When I try sending data to an Xbee using the send() method there is a TypeError 
in the base.py file

the script is:
import serial
from xbee import ZigBee

serial_port = serial.Serial('/dev/cu.usbserial-A800f7SH', 9600)
xbee = ZigBee(serial_port)
xbee.send("at", frame='A', command='MY', parameter=None)
xbee.halt()
serial_port.close()

and the output is:
Traceback (most recent call last):
  File "test.py", line 6, in <module>
    xbee.send("at", frame='A', command='MY', parameter=None)
  File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/xbee/base.py", line 386, in send
    self._write(self._build_command(cmd, **kwargs))
  File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/xbee/base.py", line 201, in _build_command
    packet += data
TypeError: can't concat bytes to str

If I run the same script on python 2.7 it runs fine. I have tried changing the 
command to all of the optional forms in the documentation on page 6 
(xbee.at(command='MY'), etc) but none of the various options have any impact. 

I am using XBee-2.1.0 on Python 3.3 on a mac.

Thanks for your help

Original issue reported on code.google.com by ksted...@gmail.com on 13 Mar 2014 at 3:19

GoogleCodeExporter commented 9 years ago
When you call send(), please prefix all data values with b to indicate it is a 
bytes type:

xbee.send("at", frame=b'A', command=b'MY')

This is important on Python 3.X because byte-string literals (which being with 
b) differ from normal strings.

Let me know if you still have trouble.

Original comment by pmalms...@gmail.com on 13 Mar 2014 at 3:39

GoogleCodeExporter commented 9 years ago
That fixed it. Maybe you could add that to the examples in the documentation at 
some point. Thanks for the great library.

Original comment by ksted...@gmail.com on 13 Mar 2014 at 3:24

GoogleCodeExporter commented 9 years ago
Glad this fixed it for you. Since no library changes were required, closing as 
WontFix.

Original comment by pmalms...@gmail.com on 15 Aug 2014 at 12:52

GoogleCodeExporter commented 9 years ago
worked for me as well. thanks!

Original comment by mko...@gmail.com on 29 Oct 2014 at 10:23