use of org.firstinspires.ftc.robotcore.internal.usb.exception.RobotUsbUnspecifiedException in project robotcode by OutoftheBoxFTC.
the class FtDevice method setBaudRate.
public void setBaudRate(int baudRate) throws RobotUsbException {
if (!this.isOpen()) {
throw new RobotUsbDeviceClosedException("setBaudRate");
} else {
byte rc = 1;
int[] divisors = new int[2];
switch(baudRate) {
case 300:
divisors[0] = 0x2710;
break;
case 600:
divisors[0] = 0x1388;
break;
case 1200:
divisors[0] = 0x09c4;
break;
case 2400:
divisors[0] = 0x04e2;
break;
case 4800:
divisors[0] = 0x0271;
break;
case 9600:
divisors[0] = 0x4138;
break;
case 19200:
divisors[0] = 0x809c;
break;
case 38400:
divisors[0] = 0xc04e;
break;
case 57600:
divisors[0] = 0x0034;
break;
case 115200:
divisors[0] = 0x001a;
break;
case 230400:
divisors[0] = 0x000d;
break;
case 460800:
divisors[0] = 0x4006;
break;
case 921600:
divisors[0] = 0x8003;
break;
default:
if (this.isHiSpeed() && baudRate >= 1200) {
rc = BaudRate.getDivisorHi(baudRate, divisors);
} else {
rc = BaudRate.getDivisor(baudRate, divisors, this.isBitModeDevice());
}
break;
}
if (this.isMultiInterfaceDevice() || this.isFt232h() || this.isFt232ex()) {
divisors[1] <<= 8;
divisors[1] &= '\uff00';
divisors[1] |= this.mInterfaceID;
}
if (rc == 1) {
int status = this.getConnection().controlTransfer(UsbConstants.USB_TYPE_VENDOR | UsbConstants.USB_DIR_OUT, FTDI_SIO_SET_BAUDRATE, divisors[0], divisors[1], (byte[]) null, 0, 0);
if (status != 0) {
throw new RobotUsbUnspecifiedException("setBaudRate: status=%d", status);
}
} else {
throw new RobotUsbUnspecifiedException("setBaudRate: rc=%d", rc);
}
}
}
Aggregations