On 08/28/2012 11:05 AM, Patrick Brandt wrote:
Tom Kuiper wrote:
It appears that there is something I don't understand about memory
mapped IO.
I'm trying to write directly to a firmware register. I have tried in
Python in binary mode with various options regarding buffering. I
have also tried the command line 'echo 1 > register'. Whatever I
try, the length of the register 'file' changes from 4 to 0.
In python, you'll want to use the 'binascii' module functions
'b2a_hex' and 'a2b_hex' (or the colorfully aliased equivalents,
'hexlify' and 'unhexlify', respectively) to encode the data before
writing it to the firmware register.
I'm using struct pack and unpack. Isn't that more flexible?
Tom
ex:
>>> unhexlify('04') # data going into the file
'\x04'
>>> hexlify('\x04') # data coming out of the file
'04'
Obviously this is using hexadecimal representation. There are
probably ways to handle plain integers, but I didn't stumble upon it
when I was writing my control code.
--
I or me? http://www.oxforddictionaries.com/page/145