Logo Search packages:      
Sourcecode: hamlib version File versions  Download package

int HAMLIB_API port_open ( hamlib_port_t p  ) 

Open a hamlib_port based on its rig port type.

Parameters:
p rig port descriptor
Returns:
status

Definition at line 63 of file iofunc.c.

References hamlib_port_t::fd, network_open(), par_open(), hamlib_port_t::parm, hamlib_port_t::pathname, hamlib_port_t::rig, RIG_EINVAL, RIG_EIO, RIG_HANDSHAKE_HARDWARE, RIG_OK, RIG_PORT_DEVICE, RIG_PORT_NETWORK, RIG_PORT_NONE, RIG_PORT_PARALLEL, RIG_PORT_RPC, RIG_PORT_SERIAL, RIG_PORT_USB, RIG_SIGNAL_ON, RIG_SIGNAL_UNSET, ser_set_dtr(), ser_set_rts(), hamlib_port_t::serial, serial_open(), and hamlib_port_t::type.

Referenced by rig_open().

{
      int status;
      int want_state_delay = 0;

      p->fd = -1;

      switch(p->type.rig) {
      case RIG_PORT_SERIAL:
            status = serial_open(p);
            if (status < 0)
                  return status;
            if (p->parm.serial.rts_state != RIG_SIGNAL_UNSET &&
                        p->parm.serial.handshake != RIG_HANDSHAKE_HARDWARE) {
                  status = ser_set_rts(p, 
                              p->parm.serial.rts_state == RIG_SIGNAL_ON);
                  want_state_delay = 1;
            }
            if (status != 0)
                  return status;
            if (p->parm.serial.dtr_state != RIG_SIGNAL_UNSET) {
                  status = ser_set_dtr(p, 
                              p->parm.serial.dtr_state == RIG_SIGNAL_ON);
                  want_state_delay = 1;
            }
            if (status != 0)
                  return status;
            /*
             * Wait whatever electrolytics in the circuit come up to voltage.
             * Is 100ms enough? Too much?
             */
            if (want_state_delay)
                  usleep(100*1000);

            break;

      case RIG_PORT_PARALLEL:
            status = par_open(p);
            if (status < 0)
                  return status;
            break;

      case RIG_PORT_DEVICE:
            status = open(p->pathname, O_RDWR, 0);
            if (status < 0)
                  return -RIG_EIO;
            p->fd = status;
            break;

      case RIG_PORT_USB:
            status = usb_port_open(p);
            if (status < 0)
                  return status;
            break;

      case RIG_PORT_NONE:
      case RIG_PORT_RPC:
            break;      /* ez :) */

      case RIG_PORT_NETWORK:
        /* FIXME: hardcoded network port */
            status = network_open(p, 4532);
            if (status < 0)
                  return status;
            break;

      default:
            return -RIG_EINVAL;
      }

      return RIG_OK;
}


Generated by  Doxygen 1.6.0   Back to index