X-Git-Url: http://sigrok.org/gitweb/?a=blobdiff_plain;f=std.c;fp=std.c;h=7dc020b999f736bd36d60628862dbd11f9065475;hb=23dc6661667b05a91b01ab6a6fa425aa57af6daf;hp=2b4dec3fc7903f5e474092e985c42acdfe3295cb;hpb=d43b090816f61e77d8054084e85202de1a1ebeb7;p=libsigrok.git diff --git a/std.c b/std.c index 2b4dec3f..7dc020b9 100644 --- a/std.c +++ b/std.c @@ -103,6 +103,32 @@ SR_PRIV int std_session_send_df_header(const struct sr_dev_inst *sdi, #ifdef HAVE_LIBSERIALPORT +/* + * Standard serial driver dev_open() helper. + * + * This function can be used to implement the dev_open() driver API + * callback in drivers that use a serial port. The port is opened + * with the SERIAL_RDWR and SERIAL_NONBLOCK flags. + * + * If the open succeeded, the status field of the given sdi is set + * to SR_ST_ACTIVE. + * + * @retval SR_OK Success. + * @retval SR_ERR Serial port open failed. + */ +SR_PRIV int std_serial_dev_open(struct sr_dev_inst *sdi) +{ + struct sr_serial_dev_inst *serial; + + serial = sdi->conn; + if (serial_open(serial, SERIAL_RDWR | SERIAL_NONBLOCK) != SR_OK) + return SR_ERR; + + sdi->status = SR_ST_ACTIVE; + + return SR_OK; +} + /* * Standard sr_session_stop() API helper. *