comparison dmx_usb_module/dmx.pyx @ 355:4e60444605f6

add dmx_usb_module
author drewp@bigasterisk.com
date Wed, 13 Jun 2007 06:01:22 +0000
parents
children 295e803f6a5e
comparison
equal deleted inserted replaced
354:f3909c2df943 355:4e60444605f6
1 cdef extern from "fcntl.h":
2 int open(char *pathname, int flags)
3 int O_WRONLY
4
5 cdef extern from "unistd.h":
6 int write(int fd, void *buf, int count)
7
8 cdef extern from "string.h":
9 char *strncpy(char *dest, char *src, int n)
10
11 cdef extern from "Python.h":
12 char* PyString_AsString(object string)
13
14 cdef class Dmx:
15 cdef int fd
16 def __new__(self, port="/dev/dmx0"):
17 self.fd = open(port, O_WRONLY)
18 if self.fd < 0:
19 raise OSError("open failed")
20
21 def write(self, buf):
22 cdef char *cbuf
23 cbuf = PyString_AsString(buf)
24 if cbuf == NULL:
25 raise
26 res = write(self.fd, cbuf, 513)
27 if res < 0:
28 raise OSError("write failed")