diff --git a/src/rig.c b/src/rig.c index e12a35a9b..ceb7586c4 100644 --- a/src/rig.c +++ b/src/rig.c @@ -570,13 +570,6 @@ int HAMLIB_API rig_open(RIG *rig) caps = rig->caps; rs = &rig->state; - if (rs->comm_state) - { - return -RIG_EINVAL; - } - - rs->rigport.fd = -1; - // determine if we have a network address // is_network |= sscanf(rs->rigport.pathname, "%u.%u.%u.%u:%u", &net1, &net2, @@ -608,6 +601,14 @@ int HAMLIB_API rig_open(RIG *rig) rs->rigport.type.rig = RIG_PORT_NETWORK; } + if (rs->comm_state) + { + port_close(&rs->rigport, rs->rigport.type.rig); + return -RIG_EINVAL; + } + + rs->rigport.fd = -1; + if (rs->rigport.type.rig == RIG_PORT_SERIAL) { if (rs->rigport.parm.serial.rts_state != RIG_SIGNAL_UNSET