spacepaste

  1.  
  2. #!/usr/bin/env python3
  3. # -*- coding: utf-8 -*-
  4. #
  5. # mon_cffi.py
  6. #
  7. # Copyright 2018 john@jcoppens.com
  8. #
  9. # This program is free software; you can redistribute it and/or modify
  10. # it under the terms of the GNU General Public License as published by
  11. # the Free Software Foundation; either version 2 of the License, or
  12. # (at your option) any later version.
  13. #
  14. # This program is distributed in the hope that it will be useful,
  15. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. # GNU General Public License for more details.
  18. #
  19. # You should have received a copy of the GNU General Public License
  20. # along with this program; if not, write to the Free Software
  21. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  22. # MA 02110-1301, USA.
  23. #
  24. #
  25. from cffi import FFI
  26. ffi = FFI()
  27. ffi.cdef(""" // declarations
  28. typedef unsigned int lsampl_t;
  29. struct comedi_t *comedi_open(
  30. const char *filename);
  31. int comedi_data_read(
  32. struct comedi_t *handler,
  33. unsigned int subdevice,
  34. unsigned int channel,
  35. unsigned int range,
  36. unsigned int aref,
  37. lsampl_t *data);
  38. """)
  39. C = ffi.verify(""" // passed to the real C compiler
  40. #include <comedi.h>
  41. """, libraries=["/usr/lib/libcomedi.so"])
  42. p = C.comedi_open(b"/dev/comedi0")
  43. print(C.comedi_data_read(p, 0, 0, 0, 0, None))
  44.