Sorry, but I'm just too proud of this.

Given that you have:

  class RegisterLayout(ctypes.Structure):
    ...yadayadayada...

You can then:

  fh = os.open('/dev/devicethingy', os.O_RDWR)
  mm = mmap.mmap(fh, ctypes.sizeof(RegisterLayout))
  registers = RegisterLayout.from_buffer(mm)

And it just works. Behaves exactly the same way memory-mapping that struct in C would. Sure the accesses take dict lookups, and that definitely slows you down a bit. If you REALLY really needed that speed you'd be writing C. But it works.

--
Rob Gaddi, Highland Technology -- www.highlandtechnology.com
Email address domain is currently out of order.  See above to fix.
--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to