public void writeControl (byte type, byte request,
                              short value, short index, byte buf [])
    throws IOException
    {
        if (fd < 0) {
            throw new USBException("Dev.writeControl aborted",-USBException.IO_NotOpen);
        }
        if (buf == null) {
            //assume we're doing a No-Data-Control, and somebody has to make a 0-length buf
            buf = new byte[0];
        }
        if (buf.length >= MAX_CONTROL_LENGTH
            || (type & ControlMessage.DIR_TO_HOST) != 0)
            throw new IllegalArgumentException ();

        if (MacOSX.trace)
            System.out.println (
                               "Dev.writeControl, rqt 0x" + Integer.toHexString (0xff & type)
                               + ", req 0x" + Integer.toHexString (0xff & request)
                               + ", value 0x" + Integer.toHexString (0xffff & value)
                               + ", index 0x" + Integer.toHexString (0xffff & index)
                               + ", len " + Integer.toString (buf.length)
                               );

        long status = controlMsg (fd, type, request, value, index,
                                 buf, 0, (short) buf.length);

        if (status < 0) {
            throw new USBException ("control write error", (int)(-status));
    }
    }