cthuun / python-xbee

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

Does not work using the example code with XB Pro with DigiMesh firmware #28

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Hi, 

From the documentation for python-xbee 2.0, I used the attached code.

Since I'm on a Windows machine, I had to tweak the code by inputting the port 
number associated with COM4. This code works when using print(ser.readline()) 
but for some reason print(xbee.wait_read_frame()) just doesn't return anything. 
I'm using XBee Pro w/ DigiMesh firmware, the latest version of pySerial, 
python-xbee, and I have the latest version of Python (3.x.x).

I also get the following error:

>>> 
Traceback (most recent call last):
  File "C:\Projects\RonakWaspmote\program\python\readCOM.py", line 14, in <module>
    print(xbee.wait_read_frame())
  File "C:\Python32\lib\site-packages\xbee\base.py", line 390, in wait_read_frame
    return self._split_response(frame.data)
  File "C:\Python32\lib\site-packages\xbee\base.py", line 222, in _split_response
    "Unrecognized response packet with id byte {0}".format(data[0]))
KeyError: 'Unrecognized response packet with id byte 144'

What could be the problem? Is it the firmware?

Original issue reported on code.google.com by ronthecon on 3 Feb 2012 at 7:32

Attachments:

GoogleCodeExporter commented 9 years ago
This issue's type should be changed to enhancement.

The DigiMesh python script is written by Matteo Lucchesi and it's location is 
here:
http://matteo.luccalug.it/2011/11/python-xbee/

However, I am still unable to get it to work... :(

It keeps failing:

Traceback (most recent call last):
  File "C:\Projects\RonakWaspmote\program\python\readCOM.py", line 20, in <module>
    print(xbee.wait_read_frame())
  File "C:\Python32\lib\site-packages\xbee\base.py", line 389, in wait_read_frame
    frame = self._wait_for_frame()
  File "C:\Python32\lib\site-packages\xbee\base.py", line 119, in _wait_for_frame
    if self.serial.inWaiting() == 0:
  File "C:\Python32\lib\site-packages\serial\serialwin32.py", line 205, in inWaiting
    raise SerialException('call to ClearCommError failed')
serial.serialutil.SerialException: call to ClearCommError failed

Original comment by ronthecon on 3 Feb 2012 at 8:14

GoogleCodeExporter commented 9 years ago
Matteo wrote to me about the implementation posted above, but I haven't gotten 
around to including it in the library yet.

Ronthecon, that error is being generated by the pyserial serial port code, not 
anything within python-xbee. You may want to check the serial connection 
between your computer and the xbee module?

Original comment by pmalms...@gmail.com on 4 Feb 2012 at 11:33

GoogleCodeExporter commented 9 years ago
The serial connection has been working fine. Because the following code works.

import serial
from xbee import DigiMesh

ser = serial.Serial()
ser.baudrate = 38400
# read COM4, base station
ser.port = 3

ser.open()

print("end")
for x in range(0,1):
   print(ser.readline())

but when I try the DigiMesh code, it fails returning the same exception. 

KeyError: 'Unrecognized response packet with id byte 144'

144 is \x90 and the zigbee.py has a spot in its array for that value. So I'm 
not sure why it's giving me that error... Is there a bug with the 
zigbee/digimesh package? How do I go about fixing it?

Original comment by ronthecon on 30 Mar 2012 at 6:39

GoogleCodeExporter commented 9 years ago
Can you post the code you are using with the DigiMesh module?

Original comment by pmalms...@gmail.com on 30 Mar 2012 at 7:03

GoogleCodeExporter commented 9 years ago
Sure. Sorry I took so long to upload this. This is a side project while I'm 
studying at school.

Code is attached as readCOM.py to this comment.

Original comment by ronthecon on 20 Apr 2012 at 5:23

Attachments:

GoogleCodeExporter commented 9 years ago
It works if I use ser.readline() but fails if I use xbee.wait_read_frame(). Why 
is that?

Original comment by ronthecon on 20 Apr 2012 at 5:24

GoogleCodeExporter commented 9 years ago
Here's the problem. You are using Python 3.X, and the Digimesh file does not 
properly prefix entries in the api_responses dictionary with b for the bytes 
type.

This is okay in Python 2.X because the bytes type simply aliased to str. 
However, in Python 3.X, the bytes type is a brand new type, and therefore 
b"\x90" and "\x90" are not equivalent.

Try adding "b" in front of all byte strings in the DigiMesh file (take a look 
at zigbee.py or ieee.py for an example of this). That will tell Python 3.X to 
use the right type.

python-xbee is one of my side projects in school as well. I don't play with 
XBees that much now, but I like keeping the project going when I have time.

Original comment by pmalms...@gmail.com on 20 Apr 2012 at 8:25

GoogleCodeExporter commented 9 years ago
Perfect, works fine now!

Original comment by ronthecon on 14 Jun 2012 at 8:12

GoogleCodeExporter commented 9 years ago
Great, I'm glad to hear it. 

I will get around to including the DigiMesh module in the source code at some 
point, I hope.

Original comment by pmalms...@gmail.com on 14 Jun 2012 at 8:26

GoogleCodeExporter commented 9 years ago
Wonderful. I look forward to it.

Original comment by ronthecon on 19 Jun 2012 at 6:43

GoogleCodeExporter commented 9 years ago
Attaching the digimesh.py file from Matteo's blog here until I include it in 
the library.

Original comment by pmalms...@gmail.com on 20 Sep 2013 at 11:00

Attachments:

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Hi Guys, i'm facing a similar issue

i'm using Cubietruck (ARM based) with the Ubuntu server image and Python 2.7.6

i've set up an arduino to send a TXRequest with msg "hi" to the coordinator 
which is plugged via FTDI into the Cubietruck running python.

so basically i would like to see this arduino TXRequest coming in

Traceback (most recent call last):
  File "./script_20141026.py", line 18, in <module>
    response = xbee.wait_read_frame()
  File "/usr/local/lib/python2.7/dist-packages/xbee/base.py", line 400, in wait_read_frame
    return self._split_response(frame.data)
  File "/usr/local/lib/python2.7/dist-packages/xbee/base.py", line 231, in _split_response
    "Unrecognized response packet with id byte {0}".format(data[0]))
KeyError: 'Unrecognized response packet with id byte \x91'

in /usr/local/lib/python2.7/dist-packages/xbee/zigbee.py i notice that the 'b' 
is prefixed ... b"\x91"

any ideas on this one?

i will try later-on on a X86 machine to see if we have the same issue. but the 
purpose would be to run it on the embedded machine.

thx a Bunch!

Herman

Original comment by herman.v...@gmail.com on 26 Oct 2014 at 1:04

GoogleCodeExporter commented 9 years ago
Hey Guys, 

it doesnt seem to be better on a  x86 machine (ubuntu 14.04lts - python 2.7*)
-- python crashes as soon as a TXRequest data frame is recieved

what i forgot to mention was that i'm using a set of Xbee pro Serie 2 (both in 
api mode)

i'm not really a python expert, so i dont know which library is being used, i 
assume the Zigbee library from the xbee module.

thx in advance!

Herman

Original comment by herman.v...@gmail.com on 27 Oct 2014 at 11:09

GoogleCodeExporter commented 9 years ago
Hi!
We are using Digimesh.py with python 2.7 and in serial configured a timeout.
What happen is that serial port do not timeout and we are not receiving any 
data...
This is my configuration:
ser = serial.Serial('/dev/ttyUSB0', 115200, timeout=1)
xbee = DigiMesh(ser,escaped = True)

And this is my code for receiving frames:
while time.time() < t_recibir:
        try:
              while True:
                print("Receiving frames")
                packet = xbee.wait_read_frame()
                print("Frame received")
                print packet

But on terminal what I see is:
Receiving frames

And nothing happen. Can anyone advice me what I am doing wrong? 
Best regards!

Original comment by rov...@gmail.com on 6 Mar 2015 at 9:34