]> sigrok.org Git - libsigrok.git/blobdiff - hardware/fluke-dmm/api.c
fluke-dmm: Use sr_dev_inst to store connection handle
[libsigrok.git] / hardware / fluke-dmm / api.c
index 92092fab4f7ec77fb7aedb5b97fe14bbae443bcc..080301c428fded5cddcca063fffb372e7be636e8 100644 (file)
@@ -65,6 +65,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))
@@ -76,7 +77,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);
@@ -157,7 +159,7 @@ static GSList *fluke_scan(const char *conn, const char *serialcomm)
                                        return NULL;
                                }
                                devc->profile = &supported_flukedmm[i];
-                               devc->serial = serial;
+                               sdi->conn = serial;
                                sdi->priv = devc;
                                sdi->driver = di;
                                if (!(probe = sr_probe_new(0, SR_PROBE_ANALOG, TRUE, "P1")))
@@ -225,14 +227,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 | SERIAL_NONBLOCK) != SR_OK)
+       serial = sdi->conn;
+       if (serial_open(serial, SERIAL_RDWR | SERIAL_NONBLOCK) != SR_OK)
                return SR_ERR;
 
        sdi->status = SR_ST_ACTIVE;
@@ -242,12 +240,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;
        }
 
@@ -322,6 +319,7 @@ 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 (!(devc = sdi->priv)) {
                sr_err("sdi->priv was NULL.");
@@ -334,9 +332,10 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
        std_session_send_df_header(cb_data, DRIVER_LOG_DOMAIN);
 
        /* Poll every 100ms, or whenever some data comes in. */
-       sr_source_add(devc->serial->fd, G_IO_IN, 50, fluke_receive_data, (void *)sdi);
+       serial = sdi->conn;
+       sr_source_add(serial->fd, G_IO_IN, 50, fluke_receive_data, (void *)sdi);
 
-       if (serial_write(devc->serial, "QM\r", 3) == -1) {
+       if (serial_write(serial, "QM\r", 3) == -1) {
                sr_err("Unable to send QM: %s.", strerror(errno));
                return SR_ERR;
        }
@@ -349,7 +348,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 flukedmm_driver_info = {