Hi all,

First, a word of warning: I don't actually know anything about the
CASPER tools.

But from what I've read, I think you can take a shortcut using a trick
provided by Numpy. (So, assumption 1: that Numpy is being used.) If 'x'
is a Numpy array, 'x.data' is a special "buffer" object that refers to
its raw binary contents, and 'str(x.data)' returns those contents as a
binary string. Many Python functions accept either a buffer or a string
and implicitly stringify the argument if it's the former.

So I'm pretty sure that if your data are stored as a Numpy array, you
should just be able to write

fpga.write (bname, x.data)

or possibly (bname, str (x.data)), and get what you want. You can do
type conversions with something like

fpga.write (bname, x.astype ('>d').data)

If this isn't a dumb suggestion for some reason, it should be both
clearer and faster than going through struct.pack.

Cheers,

Peter

On Thu, 2011-01-06 at 16:44 -0500, 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?
> >
> >
> 
> 
> 

-- 
Peter Williams / [email protected]
Department of Astronomy, UC Berkeley


Reply via email to