This commit is contained in:
@@ -100,9 +100,9 @@ public class CP210XSerialPort extends AbstractSerialPort {
|
||||
initConnection();
|
||||
try {
|
||||
throwIfNegative(sendControlTransfer(IFC_ENABLE, UART_ENABLE, null), "Failed to enable uart (error: %d).");
|
||||
throwIfNegative(initBaudRate(), "Failed to set baud rate (error: %d).");
|
||||
throwIfNegative(initParameters(), "Failed to set parameters (error: %d).");
|
||||
throwIfNegative(initFlowControl(), "Failed to set flow control (error: %d).");
|
||||
throwIfNegative(initBaudRate(), "Failed to set baud rate (error: %d).");
|
||||
} catch (IOException e) {
|
||||
close();
|
||||
throw e;
|
||||
@@ -116,8 +116,10 @@ public class CP210XSerialPort extends AbstractSerialPort {
|
||||
* @throws IOException Thrown if something fails.
|
||||
*/
|
||||
protected int initParameters() throws IOException {
|
||||
int config = getStopBits() | getDataBits() | getParity();
|
||||
return sendControlTransfer(SET_LINE_CTL, config, null);
|
||||
int value = getLineCtl();
|
||||
value &= ~0x05F3;
|
||||
value &= getStopBits() | getDataBits() | getParity();
|
||||
return sendControlTransfer(SET_LINE_CTL, value, null);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -195,7 +197,11 @@ public class CP210XSerialPort extends AbstractSerialPort {
|
||||
(byte) 0x00, (byte) 0x80, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x20, (byte) 0x00, (byte) 0x00
|
||||
};
|
||||
return sendControlTransfer(SET_FLOW, 0, dataOff);
|
||||
// work-around for RPLidar, don't set the flow control if it is off
|
||||
// TODO: check Linux driver to figure out how this should be done properly
|
||||
// see https://github.com/torvalds/linux/blob/master/drivers/usb/serial/cp210x.c
|
||||
//return sendControlTransfer(SET_FLOW, 0, dataOff);
|
||||
return 0;
|
||||
case DSR_DTR:
|
||||
byte[] dataDSRDTR = new byte[]{
|
||||
(byte) 0x11, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
@@ -228,8 +234,6 @@ public class CP210XSerialPort extends AbstractSerialPort {
|
||||
return Math.min(res, sendControlTransfer(SET_FLOW, 0, dataXONXOFF));
|
||||
}
|
||||
throw new IOException("Unsupported flow control configuration.");
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user