Take a look at the struct and ctypes modules.
struct is really not the choice. it returns an expanded string of the
data and this means larger latency over bluetooth.
ctypes is basically for the interface with libraries written in C
(this I read from the python docs)
--
On Jan 25, 12:52 am, Martin v. Löwis mar...@v.loewis.de wrote:
packet_type (1 byte unsigned) || packet_length (1 byte unsigned) ||
packet_data(variable)
How to construct these using python data types, as int and float have
no limits and their sizes are not well defined.
In Python 2.x,
Ravi wrote:
Take a look at the struct and ctypes modules.
struct is really not the choice. it returns an expanded string of the
data and this means larger latency over bluetooth.
If you read the module documentation more carefully you will see that it
converts between the various native
On 2009-01-25, Ravi ra.ravi@gmail.com wrote:
Take a look at the struct and ctypes modules.
struct is really not the choice. it returns an expanded string of the
data and this means larger latency over bluetooth.
I don't know what you mean by returns an expanded string of
the data.
I do
On Sun, Jan 25, 2009 at 7:27 AM, Ravi ra.ravi@gmail.com wrote:
Take a look at the struct and ctypes modules.
struct is really not the choice. it returns an expanded string of the
data and this means larger latency over bluetooth.
Noo... struct really IS the choice; that is the
Take a look at the struct and ctypes modules.
struct is really not the choice. it returns an expanded string of the
data and this means larger latency over bluetooth.
I don't know what you mean by returns an expanded string of
the data.
I do know that struct does exactly what you
On 2009-01-25, Martin v. Löwis mar...@v.loewis.de wrote:
Take a look at the struct and ctypes modules.
struct is really not the choice. it returns an expanded string of the
data and this means larger latency over bluetooth.
I don't know what you mean by returns an expanded string of
the
I disagree. He has a format (type, length, value), with the
value being variable-sized. How do you do that in the struct
module?
You construct a format string for the value portion based on
the type/length header.
Can you kindly provide example code on how to do this?
I don't see how
On Jan 26, 2:28 am, Ravi ra.ravi@gmail.com wrote:
On Jan 25, 12:52 am, Martin v. Löwis mar...@v.loewis.de wrote:
packet_type (1 byte unsigned) || packet_length (1 byte unsigned) ||
packet_data(variable)
How to construct these using python data types, as int and float have
no
Looks to me like there was already a reasonable way of getting a bytes
object containing a variable number of zero bytes. Any particular
reason why bytes(n) was given this specialised meaning?
I think it was because bytes() was originally mutable, and you need a
way to create a buffer of n
On 2009-01-25, Martin v. Löwis mar...@v.loewis.de wrote:
You construct a format string for the value portion based on
the type/length header.
Can you kindly provide example code on how to do this?
OK, something like this to handle received data where there is
an initial 8-bit type field that
dtype = ord(rawdata[0])
dcount = struct.unpack(!H,rawdata[1:3])
if dtype == 1:
fmtstr = ! + H*dcount
elif dtype == 2:
fmtstr = ! + f*dcount
rlen = struct.calcsize(fmtstr)
data = struct.unpack(fmtstr,rawdata[3:3+rlen])
leftover = rawdata[3+rlen:]
On 2009-01-25, Martin v. Löwis mar...@v.loewis.de wrote:
dtype = ord(rawdata[0])
dcount = struct.unpack(!H,rawdata[1:3])
if dtype == 1:
fmtstr = ! + H*dcount
elif dtype == 2:
fmtstr = ! + f*dcount
rlen = struct.calcsize(fmtstr)
data =
Unfortunately, that does not work in the example. We have
a message type (an integer), and a variable-length string.
So how do you compute the struct format for that?
I'm confused. Are you asking for an introductory tutorial on
programming in Python?
Perhaps. I honestly do not know how to
On 2009-01-25, Martin v. Löwis mar...@v.loewis.de wrote:
Unfortunately, that does not work in the example. We have
a message type (an integer), and a variable-length string.
So how do you compute the struct format for that?
I'm confused. Are you asking for an introductory tutorial on
It deals with variable sized fields just fine:
dtype = 18
dlength = 32
format = !BB%ds % dlength
rawdata = struct.pack(format, (dtype,dlength,data))
I wouldn't call this just fine, though - it involves
a % operator to even compute the format string. IMO,
it is *much* better not to use
On 2009-01-25, Martin v. Löwis mar...@v.loewis.de wrote:
It deals with variable sized fields just fine:
dtype = 18
dlength = 32
format = !BB%ds % dlength
rawdata = struct.pack(format, (dtype,dlength,data))
I wouldn't call this just fine, though - it involves
a % operator to even
However, as you keep claiming that the struct module is what
should be used, I must be missing something about the struct
module.
You seem to be focusing overly on the C Struct part of the description of
what the struct module does, instead of the part where it says, packed
binary data and
On Jan 26, 10:53 am, Martin v. Löwis mar...@v.loewis.de wrote:
It deals with variable sized fields just fine:
dtype = 18
dlength = 32
format = !BB%ds % dlength
rawdata = struct.pack(format, (dtype,dlength,data))
I wouldn't call this just fine, though - it involves
a % operator to
I have following packet format which I have to send over Bluetooth.
packet_type (1 byte unsigned) || packet_length (1 byte unsigned) ||
packet_data(variable)
How to construct these using python data types, as int and float have
no limits and their sizes are not well defined.
Check out the
packet_type (1 byte unsigned) || packet_length (1 byte unsigned) ||
packet_data(variable)
How to construct these using python data types, as int and float have
no limits and their sizes are not well defined.
In Python 2.x, use the regular string type: chr(n) will create a single
byte, and
Ravi packet_type (1 byte unsigned) || packet_length (1 byte unsigned) ||
Ravi packet_data(variable)
Ravi How to construct these using python data types, as int and float have
Ravi no limits and their sizes are not well defined.
Take a look at the struct and ctypes modules.
--
22 matches
Mail list logo