If this sounds a little strange to you, it's because of the way Python
represents raw binary data (as a string!). Thus, any function that's supposed
to accept binary data actually accepts strings.
This makes sense when you consider that Python natively doesn't differentiate
between, for example, 8 bit and 32 bit integers. So if you have the binary
number "1" that you want to send, how does it know to represent it as 0x01 or
0x0001 or 0x00000001? The "struct" package provides functions for packing and
unpacking python arrays of numbers, strings and other things into binary
structures, including endian-ness conversion (remember PPC is different to
X86). It converts things into strings, where each string character is 8 bits
long. This mostly works well but has some funny side effects. Like Python
cannot pack and unpack less than 8 bits easily which makes working with signed
nibbles, for example, tricky.
Jason
On 06 Jan 2011, at 23:44, Laura Spitler wrote:
> Hi Jon,
>
> To elaborate on Mark's suggestion, I include a python function I've
> written to do just what you're trying to do:
>
> def bramw(fpga, bname, odata, samples=2048):
> b_0=struct.pack('>'+str(samples)+'l',*odata)
> fpga.write(bname,b_0)
> return
>
> Where 'fpga' is your FpgaClient variable, 'bname' is a string that
> contains the name of the BRAM, 'odata' is an array that contains the
> data you want to write, and 'samples' is an optional variable that
> specifies the length of data with 2048 being default.
>
> Usage:
>
>> bramw(fpga, 'Shared_BRAM', test_data, 32)
>
> Best,
> Laura
>
>
> On Thu, Jan 6, 2011 at 4:39 PM, Mark Wagner <[email protected]> wrote:
>> Hi Jon,
>> I think you may want to try using the struct.pack() method to format your
>> data before the fpga.write() call.
>> Best,
>> Mark
>>
>> On Thu, Jan 6, 2011 at 1:22 PM, Jon Losh <[email protected]> wrote:
>>>
>>> Hi,
>>>
>>> I'm using Corr in Python to write test data to BRAMs on a roach, but
>>> whenever I try to write something using the fpga.write() method, it writes
>>> the ASCII codes rather than the numbers themselves. The fpga.write() method
>>> also won't take anything but a string as its input, and I can't find any
>>> detailed documentation for Corr for how to fix this.
>>>
>>> I found some references to an "ioreg" variable that I can set to make the
>>> roach interpret things as binary rather than ASCII, but I can't figure out
>>> what process number my BORPH file is.
>>>
>>> Anyone have any hot ideas?
>>
>>
>