Skip to content

Commit

Permalink
Merge pull request #174 from Arth-ur/check-tiocgserial-retval
Browse files Browse the repository at this point in the history
Check return value of ioctl `TIOCGSERIAL` on Linux
  • Loading branch information
hedgecrw authored Dec 7, 2018
2 parents 4788ef8 + 9457337 commit c5741a2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
16 changes: 9 additions & 7 deletions src/main/c/Posix/PosixHelperFunctions.c
Original file line number Diff line number Diff line change
Expand Up @@ -510,13 +510,15 @@ int setBaudRateCustom(int portFD, baud_rate baudRate)
int retVal = ioctl(portFD, TCSETS2, &options);
#else
struct serial_struct serInfo;
ioctl(portFD, TIOCGSERIAL, &serInfo);
serInfo.flags &= ~ASYNC_SPD_MASK;
serInfo.flags |= ASYNC_SPD_CUST | ASYNC_LOW_LATENCY;
serInfo.custom_divisor = serInfo.baud_base / baudRate;
if (sersInfo.custom_divisor == 0)
serInfo.custom_divisor = 1;
int retVal = ioctl(portFD, TIOCSSERIAL, &serInfo);
int retVal = ioctl(portFD, TIOCGSERIAL, &serInfo);
if (retVal == 0) {
serInfo.flags &= ~ASYNC_SPD_MASK;
serInfo.flags |= ASYNC_SPD_CUST | ASYNC_LOW_LATENCY;
serInfo.custom_divisor = serInfo.baud_base / baudRate;
if (sersInfo.custom_divisor == 0)
serInfo.custom_divisor = 1;
retVal = ioctl(portFD, TIOCSSERIAL, &serInfo);
}
#endif
return (retVal == 0);
}
Expand Down
8 changes: 5 additions & 3 deletions src/main/c/Posix/SerialPort_Posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
#if defined(__linux__)
struct serial_struct serInfo;
ioctl(serialPortFD, TIOCGSERIAL, &serInfo);
serInfo.xmit_fifo_size = sendDeviceQueueSize;
ioctl(serialPortFD, TIOCSSERIAL, &serInfo);
int tiocgserialRetVal = ioctl(serialPortFD, TIOCGSERIAL, &serInfo);
if (tiocgserialRetVal == 0) {
serInfo.xmit_fifo_size = sendDeviceQueueSize;
ioctl(serialPortFD, TIOCSSERIAL, &serInfo);
}
#endif
if (nonStandardBaudRate)
setBaudRateCustom(serialPortFD, baudRate);
Expand Down

0 comments on commit c5741a2

Please sign in to comment.