MCPcopy Create free account
hub / github.com/Hamlib/Hamlib / ser_open

Function ser_open

src/serial.c:926–979  ·  view source on GitHub ↗

* \brief Open serial port * \param p * \return fd */

Source from the content-addressed store, hash-verified

924 * \return fd
925 */
926int ser_open(hamlib_port_t *p)
927{
928 int ret;
929
930 rig_debug(RIG_DEBUG_VERBOSE, "%s called port=%s\n", __func__, p->pathname);
931
932 if (!strncmp(p->pathname, "uh-rig", 6))
933 {
934 /*
935 * This should not happen: ser_open is only used for
936 * DTR-only serial ports (ptt_pathname != rig_pathname).
937 */
938 ret = -1;
939 }
940 else
941 {
942 if (!strncmp(p->pathname, "uh-ptt", 6))
943 {
944 /*
945 * Use microHam device for doing PTT. Although a valid file
946 * descriptor is returned, it is not used for anything
947 * but must be remembered in a global variable:
948 * If it is tried later to set/unset DTR on this fd, we know
949 * that we cannot use ioctl and must rather call our
950 * PTT set/unset service routine.
951 */
952 ret = uh_open_ptt();
953 uh_ptt_fd = ret;
954 }
955 else
956 {
957 /*
958 * pathname is not uh_rig or uh_ptt: simply open()
959 */
960 int i = 1;
961
962 do // some serial ports fail to open 1st time
963 {
964 ret = OPEN(p->pathname, O_RDWR | O_NOCTTY | O_NDELAY);
965
966 if (ret == -1) // some serial ports fail to open 1st time
967 {
968 rig_debug(RIG_DEBUG_WARN, "%s(%d): open failed#%d\n", __func__, __LINE__, i);
969 hl_usleep(500 * 1000);
970 ret = OPEN(p->pathname, O_RDWR | O_NOCTTY | O_NDELAY);
971 }
972 }
973 while (++i <= 4 && ret == -1);
974 }
975 }
976
977 p->fd = ret;
978 return (ret);
979}
980
981
982/**

Callers 2

rig_openFunction · 0.85
rig_set_pttFunction · 0.85

Calls 3

rig_debugFunction · 0.85
uh_open_pttFunction · 0.85
hl_usleepFunction · 0.85

Tested by

no test coverage detected