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

int par_open ( hamlib_port_t port  ) 

Open Parallel Port.

Parameters:
port 
Returns:
file descriptor
TODO: to be called before exiting: atexit(parport_cleanup) void parport_cleanup() { ioctl(fd, PPRELEASE); }

Definition at line 101 of file parallel.c.

References hamlib_port_t::fd, hamlib_port_t::pathname, rig_debug(), RIG_DEBUG_ERR, RIG_EINVAL, RIG_EIO, and RIG_ENIMPL.

Referenced by rig_open(), and rot_open().

{
      int fd;
      int mode;

      if (!port->pathname)
            return -RIG_EINVAL;

#ifdef HAVE_LINUX_PPDEV_H
      fd = open(port->pathname, O_RDWR);
      if (fd < 0) {
            rig_debug(RIG_DEBUG_ERR, "Opening device \"%s\": %s\n", port->pathname, strerror(errno));
            return -RIG_EIO;
      }
      mode = IEEE1284_MODE_COMPAT;
      if (ioctl (fd, PPSETMODE, &mode) != 0) {
            rig_debug(RIG_DEBUG_ERR, "PPSETMODE \"%s\": %s\n", port->pathname, strerror(errno));
            close(fd);
            return -RIG_EIO;
      }

#elif defined(HAVE_DEV_PPBUS_PPI_H)

      fd = open(port->pathname, O_RDWR);
      if (fd < 0) {
            rig_debug(RIG_DEBUG_ERR, "Opening device \"%s\": %s\n", port->pathname, strerror(errno));
            return -RIG_EIO;
      }

#elif defined(WIN32)
      fd = (int)CreateFile(port->pathname, GENERIC_READ | GENERIC_WRITE,
            0, NULL, OPEN_EXISTING, 0, NULL);
      if (fd == (int)INVALID_HANDLE_VALUE) {
            rig_debug(RIG_DEBUG_ERR, "Opening device \"%s\"\n", port->pathname);
            CloseHandle((HANDLE)fd);
            return -RIG_EIO;
      }
#else
      return -RIG_ENIMPL;
#endif
      port->fd = fd;
      return fd;
}


Generated by  Doxygen 1.6.0   Back to index