Logo Search packages:      
Sourcecode: hamlib version File versions

int HAMLIB_API rig_close ( RIG rig  ) 

close the communication to the rig

Parameters:
rig The RIG handle of the radio to be closed
Closes communication to a radio which RIG handle has been passed by argument that was previously open with rig_open().

Returns:
RIG_OK if the operation has been sucessful, otherwise a negative value if an error occured (in which case, cause is set appropriately).
See also:
rig_cleanup(), rig_open()

Definition at line 584 of file rig.c.

References caps, rig_state::comm_state, hamlib_port_t::dcd, rig_state::dcdport, hamlib_port_t::fd, par_close(), hamlib_port_t::ptt, rig_state::pttport, hamlib_port_t::rig, rig_caps::rig_close, RIG_DCD_NONE, RIG_DCD_PARALLEL, RIG_DCD_RIG, RIG_DCD_SERIAL_CAR, RIG_DCD_SERIAL_CTS, RIG_DCD_SERIAL_DSR, rig_debug(), RIG_DEBUG_ERR, RIG_DEBUG_VERBOSE, RIG_EINVAL, RIG_OK, RIG_PORT_PARALLEL, RIG_PORT_SERIAL, RIG_PORT_USB, RIG_PTT_NONE, RIG_PTT_PARALLEL, RIG_PTT_RIG, RIG_PTT_SERIAL_DTR, RIG_PTT_SERIAL_RTS, rig_state::rigport, ser_close(), state, rig_state::transceive, and hamlib_port_t::type.

Referenced by rig_cleanup().

{
      const struct rig_caps *caps;
      struct rig_state *rs;

      rig_debug(RIG_DEBUG_VERBOSE,"rig:rig_close called \n");

      if (!rig || !rig->caps)
            return -RIG_EINVAL;

      caps = rig->caps;
      rs = &rig->state;

      if (!rs->comm_state)
            return -RIG_EINVAL;

      if (rs->transceive != RIG_TRN_OFF) {
            remove_trn_rig(rig);
      }

      /*
       * Let the backend say 73s to the rig.
       * and ignore the return code.
       */
      if (caps->rig_close)
            caps->rig_close(rig);

      /* 
       * FIXME: what happens if PTT and rig ports are the same?
       *                (eg. ptt_type = RIG_PTT_SERIAL)
       */
      switch(rs->pttport.type.ptt) {
      case RIG_PTT_NONE:
      case RIG_PTT_RIG:
            break;
      case RIG_PTT_SERIAL_RTS:
      case RIG_PTT_SERIAL_DTR:
            ser_close(&rs->pttport);
            break;
      case RIG_PTT_PARALLEL:
            par_close(&rs->pttport);
            break;
      default:
            rig_debug(RIG_DEBUG_ERR, "Unsupported PTT type %d\n",
                                    rs->pttport.type.ptt);
      }

      switch(rs->dcdport.type.dcd) {
      case RIG_DCD_NONE:
      case RIG_DCD_RIG:
            break;
      case RIG_DCD_SERIAL_DSR:
      case RIG_DCD_SERIAL_CTS:
      case RIG_DCD_SERIAL_CAR:
            ser_close(&rs->dcdport);
            break;
      case RIG_DCD_PARALLEL:
            par_close(&rs->dcdport);
            break;
      default:
            rig_debug(RIG_DEBUG_ERR, "Unsupported DCD type %d\n",
                                    rs->dcdport.type.dcd);
      }

      rs->dcdport.fd = rs->pttport.fd = -1;

      if (rs->rigport.fd != -1) {
            switch(rs->rigport.type.rig) {
            case RIG_PORT_SERIAL:
                  ser_close(&rs->rigport);
                  break;
            case RIG_PORT_PARALLEL:
                  par_close(&rs->rigport);
                  break;
            case RIG_PORT_USB:
                  usb_port_close(&rs->rigport);
                  break;

            default:
                  close(rs->rigport.fd);
            }
            rs->rigport.fd = -1;
      }

      remove_opened_rig(rig);

      rs->comm_state = 0;

      return RIG_OK;
}


Generated by  Doxygen 1.6.0   Back to index