X-Git-Url: http://sigrok.org/gitweb/?a=blobdiff_plain;f=hardware%2Fcolead-slm%2Fapi.c;h=7464f473f6acf12c2b560e1e81d2ed621b2eb9bb;hb=a0c7e23ad871c0e77dd8632c76f87bec1c6fd002;hp=7ae2892b072d4f9e2cf68216c227ec50723a7949;hpb=bd6fbf628abef9fab5293e016ad11e1a1ac4a0a9;p=libsigrok.git diff --git a/hardware/colead-slm/api.c b/hardware/colead-slm/api.c index 7ae2892b..7464f473 100644 --- a/hardware/colead-slm/api.c +++ b/hardware/colead-slm/api.c @@ -51,6 +51,7 @@ static int clear_instances(void) struct sr_dev_inst *sdi; struct drv_context *drvc; struct dev_context *devc; + struct sr_serial_dev_inst *serial; GSList *l; if (!(drvc = di->priv)) @@ -61,7 +62,8 @@ static int clear_instances(void) continue; if (!(devc = sdi->priv)) continue; - sr_serial_dev_inst_free(devc->serial); + serial = sdi->conn; + sr_serial_dev_inst_free(serial); sr_dev_inst_free(sdi); } g_slist_free(drvc->instances); @@ -116,9 +118,10 @@ static GSList *hw_scan(GSList *options) return NULL; } - if (!(devc->serial = sr_serial_dev_inst_new(conn, serialcomm))) + if (!(sdi->conn = sr_serial_dev_inst_new(conn, serialcomm))) return NULL; + sdi->inst_type = SR_INST_SERIAL; sdi->priv = devc; sdi->driver = di; if (!(probe = sr_probe_new(0, SR_PROBE_ANALOG, TRUE, "P1"))) @@ -137,14 +140,10 @@ static GSList *hw_dev_list(void) static int hw_dev_open(struct sr_dev_inst *sdi) { - struct dev_context *devc; - - if (!(devc = sdi->priv)) { - sr_err("sdi->priv was NULL."); - return SR_ERR_BUG; - } + struct sr_serial_dev_inst *serial; - if (serial_open(devc->serial, SERIAL_RDWR) != SR_OK) + serial = sdi->conn; + if (serial_open(serial, SERIAL_RDWR) != SR_OK) return SR_ERR; sdi->status = SR_ST_ACTIVE; @@ -154,12 +153,11 @@ static int hw_dev_open(struct sr_dev_inst *sdi) static int hw_dev_close(struct sr_dev_inst *sdi) { - struct dev_context *devc; - - devc = sdi->priv; + struct sr_serial_dev_inst *serial; - if (devc->serial && devc->serial->fd != -1) { - serial_close(devc->serial); + serial = sdi->conn; + if (serial && serial->fd != -1) { + serial_close(serial); sdi->status = SR_ST_INACTIVE; } @@ -178,7 +176,7 @@ static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi) struct dev_context *devc; if (sdi->status != SR_ST_ACTIVE) - return SR_ERR; + return SR_ERR_DEV_CLOSED; if (!(devc = sdi->priv)) { sr_err("sdi->priv was NULL."); @@ -233,6 +231,10 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) { struct dev_context *devc; + struct sr_serial_dev_inst *serial; + + if (sdi->status != SR_ST_ACTIVE) + return SR_ERR_DEV_CLOSED; if (!(devc = sdi->priv)) { sr_err("sdi->priv was NULL."); @@ -245,7 +247,8 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi, std_session_send_df_header(cb_data, DRIVER_LOG_DOMAIN); /* Poll every 150ms, or whenever some data comes in. */ - sr_source_add(devc->serial->fd, G_IO_IN, 150, colead_slm_receive_data, + serial = sdi->conn; + sr_source_add(serial->fd, G_IO_IN, 150, colead_slm_receive_data, (void *)sdi); return SR_OK; @@ -254,7 +257,7 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi, static int hw_dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data) { return std_hw_dev_acquisition_stop_serial(sdi, cb_data, hw_dev_close, - ((struct dev_context *)(sdi->priv))->serial, DRIVER_LOG_DOMAIN); + sdi->conn, DRIVER_LOG_DOMAIN); } SR_PRIV struct sr_dev_driver colead_slm_driver_info = {