Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Python parsing Bluetooth RFCOMM for 9 bytes

Reply
Thread Tools

Python parsing Bluetooth RFCOMM for 9 bytes

 
 
Barry Dick
Guest
Posts: n/a
 
      12-14-2012
My data looks like this when it comes from the device (biofeedback device). There are 9 bytes in total, and I need to buffer so much, and then poll it for new/recent packets. The start packet unfortunately starts with 0x00

So far the only thing I've found that looks like what I want to do is this, but I don't know how to implement it. http://code.activestate.com/recipes/408859/


Data: [0000002d0270025e00]
Data: [0001004a0006026547]
Data: [0002004b000a026343]
Data: [00]
Data: [03004f0006025b4a00]
Data: [046698000802569d00]
Data: [00003002830257f100]
Data: [01004a000602585400]
Data: [020048000a025b4e00]
Data: [03004b0006025b4e00]
Data: [046698000702579d00]
Data: [00002f027602480e00]
Data: [01004a0006024b61]
Data: [0002004a000a025552]
Data: [0003004b0006025752]
Data: [00046698000702569e]
Data: [0000002c025b025321]
Data: [00010048000602505e]

My code so far looks like this...

import bluetooth, sys, time, os, binascii, struct;

# Create the client socket
client_socket=BluetoothSocket( RFCOMM )

client_socket.connect(("10:00:E8:AC:4D0", 1))

data = ""
try:
while True:
try:
data = client_socket.recv(9)
except bluetooth.BluetoothError, b:
print "Bluetooth Error: ", b

if len(data) > 0:
print "Data: [%s]" % binascii.hexlify(data)

except KeyboardInterrupt:
#print "Closing socket...",
client_socket.close()
#print "done."
 
Reply With Quote
 
 
 
 
MRAB
Guest
Posts: n/a
 
      12-14-2012
On 2012-12-14 00:00, Barry Dick wrote:
> My data looks like this when it comes from the device (biofeedback device). There are 9 bytes in total, and I need to buffer so much, and then poll it for new/recent packets. The start packet unfortunately starts with 0x00
>
> So far the only thing I've found that looks like what I want to do is this, but I don't know how to implement it. http://code.activestate.com/recipes/408859/
>
>
> Data: [0000002d0270025e00]
> Data: [0001004a0006026547]
> Data: [0002004b000a026343]
> Data: [00]
> Data: [03004f0006025b4a00]
> Data: [046698000802569d00]
> Data: [00003002830257f100]
> Data: [01004a000602585400]
> Data: [020048000a025b4e00]
> Data: [03004b0006025b4e00]
> Data: [046698000702579d00]
> Data: [00002f027602480e00]
> Data: [01004a0006024b61]
> Data: [0002004a000a025552]
> Data: [0003004b0006025752]
> Data: [00046698000702569e]
> Data: [0000002c025b025321]
> Data: [00010048000602505e]
>
> My code so far looks like this...
>
> import bluetooth, sys, time, os, binascii, struct;
>
> # Create the client socket
> client_socket=BluetoothSocket( RFCOMM )
>
> client_socket.connect(("10:00:E8:AC:4D0", 1))
>
> data = ""
> try:
> while True:
> try:
> data = client_socket.recv(9)
> except bluetooth.BluetoothError, b:
> print "Bluetooth Error: ", b
>
> if len(data) > 0:
> print "Data: [%s]" % binascii.hexlify(data)
>
> except KeyboardInterrupt:
> #print "Closing socket...",
> client_socket.close()
> #print "done."
>

Is the following more like how you want it?

data = ""
try:
while True:
try:
more = client_socket.recv(9)
except bluetooth.BluetoothError, b:
print "Bluetooth Error: ", b
else:
data += more

while len(data) >= 9:
print "Data: [%s]" % binascii.hexlify(data[ : 9])
data = data[9 : ]
except KeyboardInterrupt:
#print "Closing socket...",
client_socket.close()
#print "done."

You could, of course, decide to recv more than 9 bytes at a time. It
could return less than you asked for (but it should block until at
least 1 byte is available), but it will never return more than you
asked for.
 
Reply With Quote
 
 
 
 
Barry Dick
Guest
Posts: n/a
 
      12-14-2012

> Is the following more like how you want it?
>
>
>
> data = ""
>
> try:
>
> while True:
>
> try:
>
> more = client_socket.recv(9)
>
> except bluetooth.BluetoothError, b:
>
> print "Bluetooth Error: ", b
>
> else:
>
> data += more
>
>
>
> while len(data) >= 9:
>
> print "Data: [%s]" % binascii.hexlify(data[ : 9])
>
> data = data[9 : ]
>
> except KeyboardInterrupt:
>
> #print "Closing socket...",
>
> client_socket.close()
>
> #print "done."
>
>
>
> You could, of course, decide to recv more than 9 bytes at a time. It
>
> could return less than you asked for (but it should block until at
>
> least 1 byte is available), but it will never return more than you
>
> asked for.


Thank you for your interest and quick reply.

Its a great start, seeing as I'm a beginner with python, I was actually hoping to see an example of http://code.activestate.com/recipes/408859/ as it appears to be exactly what I need, but I haven't got a clue how to implement it. Basically as each byte perhaps gets read or 9 bytes at a time, that way I can seek out as much real data as possible

Data: [0000002c025b025321]
Data: [00010048000602505e]
Data: [0002004a000a025552]
Data: [0003004b0006025752]
Data: [00046698000702569e]

(notice the header data[9:1] will always flow in this pattern 0 -> 4 and then back again, so I figure that might as well be my start)


And skip the errors...

Data: [0002004b000a026343]
Data: [00]
Data: [03004f0006025b4a00]
Data: [046698000802569d00]
Data: [00003002830257f100]
 
Reply With Quote
 
Barry Dick
Guest
Posts: n/a
 
      12-14-2012

> Is the following more like how you want it?
>
>
>
> data = ""
>
> try:
>
> while True:
>
> try:
>
> more = client_socket.recv(9)
>
> except bluetooth.BluetoothError, b:
>
> print "Bluetooth Error: ", b
>
> else:
>
> data += more
>
>
>
> while len(data) >= 9:
>
> print "Data: [%s]" % binascii.hexlify(data[ : 9])
>
> data = data[9 : ]
>
> except KeyboardInterrupt:
>
> #print "Closing socket...",
>
> client_socket.close()
>
> #print "done."
>
>
>
> You could, of course, decide to recv more than 9 bytes at a time. It
>
> could return less than you asked for (but it should block until at
>
> least 1 byte is available), but it will never return more than you
>
> asked for.


Thank you for your interest and quick reply.

Its a great start, seeing as I'm a beginner with python, I was actually hoping to see an example of http://code.activestate.com/recipes/408859/ as it appears to be exactly what I need, but I haven't got a clue how to implement it. Basically as each byte perhaps gets read or 9 bytes at a time, that way I can seek out as much real data as possible

Data: [0000002c025b025321]
Data: [00010048000602505e]
Data: [0002004a000a025552]
Data: [0003004b0006025752]
Data: [00046698000702569e]

(notice the header data[9:1] will always flow in this pattern 0 -> 4 and then back again, so I figure that might as well be my start)


And skip the errors...

Data: [0002004b000a026343]
Data: [00]
Data: [03004f0006025b4a00]
Data: [046698000802569d00]
Data: [00003002830257f100]
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Strange problem with Bluetooth and RFCOMM logiclips@yahoo.com Java 0 09-20-2006 10:57 PM
Ratio of Bytes Delayed to Bytes Sent netproj Cisco 0 12-21-2005 08:08 PM
Private Bytes vs. # Bytes in all Heaps in Perfmon Jason Collins ASP .Net 3 02-18-2004 03:59 PM
Re: receiving Bytes and sending Bytes Ieuan Adams Computer Support 0 07-24-2003 07:46 PM
Re: receiving Bytes and sending Bytes The Old Sourdough Computer Support 0 07-23-2003 01:23 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57