Add additional attempts to open serial port

K4 was failing on 1st open for some unknown reason but succeeds on 2nd try
https://github.com/Hamlib/Hamlib/issues/768
pull/772/head
Mike Black W9MDB 2021-08-20 22:29:12 -05:00
rodzic 1f515458fe
commit df40151d65
1 zmienionych plików z 17 dodań i 8 usunięć

Wyświetl plik

@ -225,20 +225,23 @@ int HAMLIB_API serial_open(hamlib_port_t *rp)
* Open in Non-blocking mode. Watch for EAGAIN errors!
*/
fd = OPEN(rp->pathname, O_RDWR | O_NOCTTY | O_NDELAY);
if (fd == -1)
{
rig_debug(RIG_DEBUG_WARN, "%s: open failed...trying withoud O_NOCTTY\n", __func__);
fd = OPEN(rp->pathname, O_RDWR | O_NDELAY);
if (fd == -1) // some serial ports fail to open 1st time for some unknown reason
{
rig_debug(RIG_DEBUG_WARN, "%s(%d): open failed#1\n", __func__, __LINE__);
hl_usleep(500*1000);
fd = OPEN(rp->pathname, O_RDWR | O_NOCTTY | O_NDELAY);
}
if (fd == -1)
{
rig_debug(RIG_DEBUG_WARN, "%s: open failed...trying withoud O_NDELAY\n", __func__);
fd = OPEN(rp->pathname, O_RDWR | O_NOCTTY );
rig_debug(RIG_DEBUG_WARN, "%s(%d): open failed#2\n", __func__, __LINE__);
hl_usleep(500*1000);
fd = OPEN(rp->pathname, O_RDWR | O_NOCTTY | O_NDELAY);
}
if (fd == -1)
{
rig_debug(RIG_DEBUG_WARN, "%s: open failed...trying withoud O_NDELAY and O_NOCTTY\n", __func__);
fd = OPEN(rp->pathname, O_RDWR);
rig_debug(RIG_DEBUG_WARN, "%s(%d): open failed#3\n", __func__, __LINE__);
hl_usleep(500*1000);
fd = OPEN(rp->pathname, O_RDWR | O_NOCTTY | O_NDELAY);
}
if (fd == -1)
@ -717,6 +720,12 @@ int ser_open(hamlib_port_t *p)
* pathname is not uh_rig or uh_ptt: simply open()
*/
ret = OPEN(p->pathname, O_RDWR | O_NOCTTY | O_NDELAY);
if (ret == 1) // some serial ports fail to open 1st time
{
rig_debug(RIG_DEBUG_WARN, "%s(d): open failed#1\n", __func__, ___LINE__);
hl_usleep(500*1000);
ret = OPEN(p->pathname, O_RDWR | O_NOCTTY | O_NDELAY);
}
}
}