Check return value of ioctl `TIOCGSERIAL` on Linux

This commit is contained in:
Arthur Gay 2018-12-07 15:51:44 +01:00
parent 4788ef8f4e
commit 9457337495
2 changed files with 14 additions and 10 deletions

View File

@ -510,13 +510,15 @@ int setBaudRateCustom(int portFD, baud_rate baudRate)
int retVal = ioctl(portFD, TCSETS2, &options); int retVal = ioctl(portFD, TCSETS2, &options);
#else #else
struct serial_struct serInfo; struct serial_struct serInfo;
ioctl(portFD, TIOCGSERIAL, &serInfo); int retVal = ioctl(portFD, TIOCGSERIAL, &serInfo);
if (retVal == 0) {
serInfo.flags &= ~ASYNC_SPD_MASK; serInfo.flags &= ~ASYNC_SPD_MASK;
serInfo.flags |= ASYNC_SPD_CUST | ASYNC_LOW_LATENCY; serInfo.flags |= ASYNC_SPD_CUST | ASYNC_LOW_LATENCY;
serInfo.custom_divisor = serInfo.baud_base / baudRate; serInfo.custom_divisor = serInfo.baud_base / baudRate;
if (sersInfo.custom_divisor == 0) if (sersInfo.custom_divisor == 0)
serInfo.custom_divisor = 1; serInfo.custom_divisor = 1;
int retVal = ioctl(portFD, TIOCSSERIAL, &serInfo); retVal = ioctl(portFD, TIOCSSERIAL, &serInfo);
}
#endif #endif
return (retVal == 0); return (retVal == 0);
} }

View File

@ -336,9 +336,11 @@ JNIEXPORT jboolean JNICALL Java_com_fazecast_jSerialComm_SerialPort_configPort(J
// Attempt to set the transmit buffer size and any necessary custom baud rates // Attempt to set the transmit buffer size and any necessary custom baud rates
#if defined(__linux__) #if defined(__linux__)
struct serial_struct serInfo; struct serial_struct serInfo;
ioctl(serialPortFD, TIOCGSERIAL, &serInfo); int tiocgserialRetVal = ioctl(serialPortFD, TIOCGSERIAL, &serInfo);
if (tiocgserialRetVal == 0) {
serInfo.xmit_fifo_size = sendDeviceQueueSize; serInfo.xmit_fifo_size = sendDeviceQueueSize;
ioctl(serialPortFD, TIOCSSERIAL, &serInfo); ioctl(serialPortFD, TIOCSSERIAL, &serInfo);
}
#endif #endif
if (nonStandardBaudRate) if (nonStandardBaudRate)
setBaudRateCustom(serialPortFD, baudRate); setBaudRateCustom(serialPortFD, baudRate);