Just to share python tricks, note that there's no need for a separate
module for this:

'%x' % 1234

--> '42d'

int('42d', base=16)

--> 1234

of course the binascii module may be more convenient.

On Tue, Aug 28, 2012 at 2:05 PM, Patrick Brandt <pbra...@nrao.edu> 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.
>
> 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.
>

Reply via email to