Code example for UsbDeviceConnection

Methods: controlTransfer

0
        byte[] buffer = new byte[7];
         
        if (connection == null) throw new IOException("Connection closed");
         
        // Get current settings 
        connection.controlTransfer(GET_LINE_REQUEST_TYPE, GET_LINE_REQUEST, 0, 0, oldSettings, 7, 100);
         
        buffer = oldSettings;
         
        // Setup Baudrate 
        int baud;
        switch (R) {
        case B0: baud = 0; break;
        case B75: baud = 75; break;
        case B150: baud = 150; break;
        case B300: baud = 300; break;
        case B600: baud = 600; break;
        case B1200: baud = 1200; break;
        case B1800: baud = 1800; break;
        case B2400: baud = 2400; break;
        case B4800: baud = 4800; break;
        case B9600: baud = 9600; break;
        case B19200: baud = 19200; break;
        case B38400: baud = 38400; break;
        case B57600: baud = 57600; break;
        case B115200: baud = 115200; break;
        case B230400: baud = 230400; break;
        case B460800: baud = 460800; break;
        case B614400: baud = 614400; break;
        case B921600: baud = 921600; break;
        case B1228800: baud = 1228800; break;
        case B2457600: baud = 2457600; break;
        case B3000000: baud = 3000000; break;
        case B6000000: baud = 6000000; break;
        default: baud = 9600; break;
        } 
         
        if  ((baud > 1228800) && (pl2303type == 0)) baud = 1228800; // Only PL2303HX supports higher baudrates   
         
        buffer[0]=(byte) (baud & 0xff);
        buffer[1]=(byte) ((baud >> 8) & 0xff);
        buffer[2]=(byte) ((baud >> 16) & 0xff);
        buffer[3]=(byte) ((baud >> 24) & 0xff);
         
//        // Setup Stopbits 
//        switch (S) { 
//        case S1: buffer[4] = 0; break; 
//        case S2: buffer[4] = 2; break; 
//        default: buffer[4] = 0; break; 
//        } 
//         
//        // Setup Parity 
//        switch (P) { 
//        case NONE: buffer[5] = 0; break; 
//        case ODD: buffer[5] = 1; break; 
//        case EVEN: buffer[5] = 2; break; 
//        default: buffer[5] = 0; break; 
//        } 
//         
//        // Setup Databits 
//        switch (D) { 
//        case D5: buffer[6] = 5; break; 
//        case D6: buffer[6] = 6; break; 
//        case D7: buffer[6] = 7; break; 
//        case D8: buffer[6] = 8; break; 
//        default: buffer[6] = 8; break; 
//        } 
 
        // Set new configuration on PL2303 only if settings have changed 
        //if (buffer != oldSettings)  
        connection.controlTransfer(SET_LINE_REQUEST_TYPE, SET_LINE_REQUEST, 0, 0, buffer, 7, 100); 
 
//        // Disable BreakControl 
//        connection.controlTransfer(BREAK_REQUEST_TYPE, BREAK_REQUEST, BREAK_OFF, 0, null, 0, 100); 
//         
//        // Disable FlowControl