* \brief Open Parallel Port * \param port * \return file descriptor * * TODO: to be called before exiting: atexit(parport_cleanup) * void parport_cleanup() { ioctl(fd, PPRELEASE); } */
| 117 | * void parport_cleanup() { ioctl(fd, PPRELEASE); } |
| 118 | */ |
| 119 | int par_open(hamlib_port_t *port) |
| 120 | { |
| 121 | int fd; |
| 122 | #ifdef HAVE_LINUX_PPDEV_H |
| 123 | int mode; |
| 124 | #endif |
| 125 | |
| 126 | #if defined (__WIN64__) || defined(__WIN32__) |
| 127 | // cppcheck-suppress * |
| 128 | HANDLE handle; |
| 129 | #endif |
| 130 | |
| 131 | rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); |
| 132 | |
| 133 | if (!port->pathname[0]) |
| 134 | { |
| 135 | return -RIG_EINVAL; |
| 136 | } |
| 137 | |
| 138 | #ifdef HAVE_LINUX_PPDEV_H |
| 139 | /* TODO: open with O_NONBLOCK ? */ |
| 140 | fd = open(port->pathname, O_RDWR); |
| 141 | |
| 142 | if (fd < 0) |
| 143 | { |
| 144 | rig_debug(RIG_DEBUG_ERR, |
| 145 | "%s: opening device \"%s\": %s\n", |
| 146 | __func__, |
| 147 | port->pathname, |
| 148 | strerror(errno)); |
| 149 | return -RIG_EIO; |
| 150 | } |
| 151 | |
| 152 | mode = IEEE1284_MODE_COMPAT; |
| 153 | |
| 154 | if (ioctl(fd, PPSETMODE, &mode) != 0) |
| 155 | { |
| 156 | rig_debug(RIG_DEBUG_ERR, "%s: PPSETMODE \"%s\": %s\n", |
| 157 | __func__, |
| 158 | port->pathname, |
| 159 | strerror(errno)); |
| 160 | close(fd); |
| 161 | return -RIG_EIO; |
| 162 | } |
| 163 | |
| 164 | #elif defined(HAVE_DEV_PPBUS_PPI_H) |
| 165 | |
| 166 | fd = open(port->pathname, O_RDWR); |
| 167 | |
| 168 | if (fd < 0) |
| 169 | { |
| 170 | rig_debug(RIG_DEBUG_ERR, |
| 171 | "%s: opening device \"%s\": %s\n", |
| 172 | __func__, |
| 173 | port->pathname, |
| 174 | strerror(errno)); |
| 175 | return -RIG_EIO; |
| 176 | } |