From ef28e435d8cfbe1a14c9b4f8cfd388639153958f Mon Sep 17 00:00:00 2001 From: Bill Somerville Date: Fri, 6 Sep 2013 01:18:35 +0100 Subject: [PATCH] Patch to allow same serial port for PTT and CAT. Hi, patch attached to enable the above which was partially coded but not quite working. 73 Bill G4WJS. >From 9dab3a250dfad7203772df91aadf79d38c108f04 Mon Sep 17 00:00:00 2001 From: Bill Somerville Date: Fri, 6 Sep 2013 01:13:34 +0100 Subject: [PATCH] Fix using same serail port for PTT and CAT src/rig.c was coded to allow the same serial port for PTT and CAT but them tried to open the port twice. I have added code to share the file descriptor in this situation. Signed-off-by: Nate Bargmann --- src/rig.c | 47 ++++++++++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 17 deletions(-) diff --git a/src/rig.c b/src/rig.c index 4fa5ff36a..55f8dc32e 100644 --- a/src/rig.c +++ b/src/rig.c @@ -503,21 +503,28 @@ int HAMLIB_API rig_open(RIG *rig) break; case RIG_PTT_SERIAL_RTS: case RIG_PTT_SERIAL_DTR: - if (rs->pttport.pathname[0] == '\0' && - rs->rigport.type.rig == RIG_PORT_SERIAL) - strcpy(rs->pttport.pathname, rs->rigport.pathname); - rs->pttport.fd = ser_open(&rs->pttport); - if (rs->pttport.fd < 0) - rig_debug(RIG_DEBUG_ERR, "Cannot open PTT device \"%s\"\n", - rs->pttport.pathname); - else { - /* Needed on Linux because the kernel forces RTS/DTR at open */ - if (rs->pttport.type.ptt == RIG_PTT_SERIAL_DTR) - ser_set_dtr(&rs->pttport, RIG_PTT_OFF); - else if (rs->pttport.type.ptt == RIG_PTT_SERIAL_RTS) - ser_set_rts(&rs->pttport, RIG_PTT_OFF); - } - break; + if (rs->pttport.pathname[0] == '\0' && + rs->rigport.type.rig == RIG_PORT_SERIAL) + strcpy(rs->pttport.pathname, rs->rigport.pathname); + if (!strcmp(rs->pttport.pathname, rs->rigport.pathname)) + { + rs->pttport.fd = rs->rigport.fd; + } + else + { + rs->pttport.fd = ser_open(&rs->pttport); + if (rs->pttport.fd < 0) + rig_debug(RIG_DEBUG_ERR, "Cannot open PTT device \"%s\"\n", + rs->pttport.pathname); + else { + /* Needed on Linux because the kernel forces RTS/DTR at open */ + if (rs->pttport.type.ptt == RIG_PTT_SERIAL_DTR) + ser_set_dtr(&rs->pttport, RIG_PTT_OFF); + else if (rs->pttport.type.ptt == RIG_PTT_SERIAL_RTS) + ser_set_rts(&rs->pttport, RIG_PTT_OFF); + } + } + break; case RIG_PTT_PARALLEL: rs->pttport.fd = par_open(&rs->pttport); if (rs->pttport.fd < 0) @@ -652,11 +659,17 @@ int HAMLIB_API rig_close(RIG *rig) break; case RIG_PTT_SERIAL_RTS: ser_set_rts(&rs->pttport, RIG_PTT_OFF); - port_close(&rs->pttport, RIG_PORT_SERIAL); + if (rs->pttport.fd != rs->rigport.fd) + { + port_close(&rs->pttport, RIG_PORT_SERIAL); + } break; case RIG_PTT_SERIAL_DTR: ser_set_dtr(&rs->pttport, RIG_PTT_OFF); - port_close(&rs->pttport, RIG_PORT_SERIAL); + if (rs->pttport.fd != rs->rigport.fd) + { + port_close(&rs->pttport, RIG_PORT_SERIAL); + } break; case RIG_PTT_PARALLEL: par_ptt_set(&rs->pttport, RIG_PTT_OFF);