Logo Search packages:      
Sourcecode: libgphoto2 version File versions

int gp_port_set_info ( GPPort port,
GPPortInfo  info 
)

Configure a port.

Makes a port functional by passing in the necessary path information (from the serial:/dev/ttyS0 or similar variables). After calling this function, you can access the port using for example gp_port_open().

Parameters:
port a GPPort
info the GPPortInfo to set
Returns:
a gphoto2 error code

Definition at line 142 of file gphoto2-port.c.

References _GPPortSettingsUSB::altsetting, _GPPortSettingsSerial::bits, CHECK_NULL, _GPPortSettingsUSB::config, _GPPortSettings::disk, GP_ERROR_LIBRARY, gp_log(), GP_LOG_ERROR, GP_OK, GP_PORT_DISK, GP_PORT_SERIAL, gp_port_set_settings(), gp_port_set_timeout(), GP_PORT_USB, _GPPortSettingsUSB::inep, _GPPortPrivateCore::info, _GPPortSettingsUSB::interface, _GPPortPrivateCore::lh, _GPPortInfo::library_filename, _GPPortSettingsDisk::mountpoint, _GPPortPrivateCore::ops, _GPPortSettingsUSB::outep, _GPPortSettingsSerial::parity, _GPPortInfo::path, _GPPort::pc, _GPPortSettingsUSB::port, _GPPortSettingsSerial::port, _GPPortSettings::serial, _GPPort::settings, _GPPortSettingsSerial::speed, _GPPortSettingsSerial::stopbits, _GPPortInfo::type, _GPPort::type, and _GPPortSettings::usb.

Referenced by gp_abilities_list_detect().

{
      GPPortLibraryOperations ops_func;

      CHECK_NULL (port);

      memcpy (&port->pc->info, &info, sizeof (GPPortInfo));
      port->type = info.type;

      /* Clean up */
      if (port->pc->ops) {
            gp_port_exit (port);
            free (port->pc->ops);
            port->pc->ops = NULL;
      }
      if (port->pc->lh) {
            lt_dlclose (port->pc->lh);
            lt_dlexit ();
      }

      lt_dlinit ();
      port->pc->lh = lt_dlopenext (info.library_filename);
      if (!port->pc->lh) {
            gp_log (GP_LOG_ERROR, "gphoto2-port", _("Could not load "
                  "'%s' ('%s')."), info.library_filename,
                  lt_dlerror ());
            lt_dlexit ();
            return (GP_ERROR_LIBRARY);
      }

      /* Load the operations */
      ops_func = lt_dlsym (port->pc->lh, "gp_port_library_operations");
      if (!ops_func) {
            gp_log (GP_LOG_ERROR, "gphoto2-port", _("Could not find "
                  "'gp_port_library_operations' in '%s' ('%s')"),
                  info.library_filename, lt_dlerror ());
            lt_dlclose (port->pc->lh);
            lt_dlexit ();
            port->pc->lh = NULL;
            return (GP_ERROR_LIBRARY);
      }
      port->pc->ops = ops_func ();
      gp_port_init (port);

      /* Initialize the settings to some default ones */
      switch (info.type) {
      case GP_PORT_SERIAL:
            strncpy (port->settings.serial.port, info.path,
                   sizeof (port->settings.serial.port));
            port->settings.serial.speed = 0;
            port->settings.serial.bits = 8;
            port->settings.serial.parity = 0;
            port->settings.serial.stopbits = 1;
            gp_port_set_timeout (port, 500);
            break;
      case GP_PORT_USB:
            strncpy (port->settings.usb.port, info.path,
                   sizeof (port->settings.usb.port));
            port->settings.usb.inep = -1;
            port->settings.usb.outep = -1;
            port->settings.usb.config = -1;
            port->settings.usb.interface = 0;
            port->settings.usb.altsetting = -1;
            gp_port_set_timeout (port, 5000);
            break;
      case GP_PORT_DISK:
            strncpy(port->settings.disk.mountpoint, 
                  strchr(info.path, ':') + 1, 
                  sizeof(port->settings.disk.mountpoint));
            break;
      default:
            /* Nothing in here */
            break;
      }
      gp_port_set_settings (port, port->settings);

      return (GP_OK);
}


Generated by  Doxygen 1.6.0   Back to index