* \brief Open a hamlib_port based on its rig port type * \param p rig port descriptor * \return status */
| 227 | * \return status |
| 228 | */ |
| 229 | int HAMLIB_API port_open(hamlib_port_t *p) |
| 230 | { |
| 231 | int status; |
| 232 | int want_state_delay = 0; |
| 233 | |
| 234 | p->fd = -1; |
| 235 | init_sync_data_pipe(p); |
| 236 | |
| 237 | if (p->asyncio) |
| 238 | { |
| 239 | status = create_sync_data_pipe(p); |
| 240 | |
| 241 | if (status < 0) |
| 242 | { |
| 243 | return (status); |
| 244 | } |
| 245 | } |
| 246 | |
| 247 | switch (p->type.rig) |
| 248 | { |
| 249 | case RIG_PORT_SERIAL: |
| 250 | status = serial_open(p); |
| 251 | |
| 252 | if (status < 0) |
| 253 | { |
| 254 | #if defined(WIN32) |
| 255 | // rig_debug(RIG_DEBUG_ERR, "%s: serial_open(%s) status=%d, err=%s\n", __func__, |
| 256 | // p->pathname, status, rigerror(status)); |
| 257 | #else |
| 258 | rig_debug(RIG_DEBUG_ERR, "%s: serial_open(%s) status=%d, err=%s\n", __func__, |
| 259 | p->pathname, status, strerror(errno)); |
| 260 | #endif |
| 261 | close_sync_data_pipe(p); |
| 262 | return (status); |
| 263 | } |
| 264 | |
| 265 | if (p->parm.serial.rts_state != RIG_SIGNAL_UNSET |
| 266 | && p->parm.serial.handshake != RIG_HANDSHAKE_HARDWARE) |
| 267 | { |
| 268 | status = ser_set_rts(p, |
| 269 | p->parm.serial.rts_state == RIG_SIGNAL_ON); |
| 270 | want_state_delay = 1; |
| 271 | } |
| 272 | |
| 273 | if (status != 0) |
| 274 | { |
| 275 | close_sync_data_pipe(p); |
| 276 | return (status); |
| 277 | } |
| 278 | |
| 279 | if (p->parm.serial.dtr_state != RIG_SIGNAL_UNSET) |
| 280 | { |
| 281 | status = ser_set_dtr(p, |
| 282 | p->parm.serial.dtr_state == RIG_SIGNAL_ON); |
| 283 | want_state_delay = 1; |
| 284 | } |
| 285 | |
| 286 | if (status != 0) |
no test coverage detected