view dmx_usb_module/dmx.pyx @ 375:962f46713b63

keyboardcomposer: sort subs by groups first, fix sub cmp The "None" group goes first, then all groups sorted by names. Within groups, subs are sorted by names. Subs sort by their __repr__, which could be a problem in the future.
author David McClosky <dmcc@bigasterisk.com>
date Fri, 15 Jun 2007 20:23:43 +0000
parents 4e60444605f6
children 295e803f6a5e
line wrap: on
line source

cdef extern from "fcntl.h":
    int open(char *pathname, int flags)
    int O_WRONLY

cdef extern from "unistd.h":
    int write(int fd, void *buf, int count)

cdef extern from "string.h":
    char *strncpy(char *dest, char *src, int n)

cdef extern from "Python.h":
    char* PyString_AsString(object string)

cdef class Dmx:
    cdef int fd
    def __new__(self, port="/dev/dmx0"):
        self.fd = open(port, O_WRONLY)
        if self.fd < 0:
            raise OSError("open failed")

    def write(self, buf):
        cdef char *cbuf
        cbuf = PyString_AsString(buf)
        if cbuf == NULL:
            raise
        res = write(self.fd, cbuf, 513)
        if res < 0:
            raise OSError("write failed")