* \brief Open serial port using port data only * \param rp port data structure (must spec port id eg /dev/ttyS1) * \return RIG_OK or < 0 if error */
| 213 | * \return RIG_OK or < 0 if error |
| 214 | */ |
| 215 | int HAMLIB_API serial_open(hamlib_port_t *rp) |
| 216 | { |
| 217 | |
| 218 | int fd; /* File descriptor for the port */ |
| 219 | int err; |
| 220 | |
| 221 | if (!rp) |
| 222 | { |
| 223 | return (-RIG_EINVAL); |
| 224 | } |
| 225 | |
| 226 | #if defined(WIN32) |
| 227 | int retcode = check_com_port_in_use(rp->pathname); |
| 228 | |
| 229 | switch (retcode) |
| 230 | { |
| 231 | case SER_IN_USE: |
| 232 | rig_debug(RIG_DEBUG_ERR, "%s: serial port %s is already open\n", __func__, |
| 233 | rp->pathname); |
| 234 | return -RIG_EACCESS; |
| 235 | |
| 236 | case SER_NO_EXIST: |
| 237 | rig_debug(RIG_DEBUG_ERR, "%s: serial port %s does not exist\n", __func__, |
| 238 | rp->pathname); |
| 239 | return -RIG_EIO; |
| 240 | |
| 241 | case SER_AVAILABLE: |
| 242 | rig_debug(RIG_DEBUG_VERBOSE, "%s: serial port %s is OK\n", __func__, rp->pathname); |
| 243 | break; |
| 244 | } |
| 245 | |
| 246 | #endif |
| 247 | |
| 248 | |
| 249 | rig_debug(RIG_DEBUG_VERBOSE, "%s: %s\n", __func__, rp->pathname); |
| 250 | |
| 251 | if (!strncmp(rp->pathname, "uh-rig", 6)) |
| 252 | { |
| 253 | /* |
| 254 | * If the pathname is EXACTLY "uh-rig", try to use a microHam device |
| 255 | * rather than a conventional serial port. |
| 256 | * The microHam devices ALWAYS use "no parity", and can either use no handshake |
| 257 | * or hardware handshake. Return with error if something else is requested. |
| 258 | */ |
| 259 | if (rp->parm.serial.parity != RIG_PARITY_NONE) |
| 260 | { |
| 261 | return (-RIG_EIO); |
| 262 | } |
| 263 | |
| 264 | if ((rp->parm.serial.handshake != RIG_HANDSHAKE_HARDWARE) && |
| 265 | (rp->parm.serial.handshake != RIG_HANDSHAKE_NONE)) |
| 266 | { |
| 267 | return (-RIG_EIO); |
| 268 | } |
| 269 | |
| 270 | /* |
| 271 | * Note that serial setup is also don in uh_open_radio. |
| 272 | * So we need to dig into serial_setup(). |
no test coverage detected