]> sigrok.org Git - libsigrok.git/blobdiff - hardware/colead-slm/api.c
Get rid of obsolete SR_DI_NUM_PROBES and SR_DI_PROBE_NAMES.
[libsigrok.git] / hardware / colead-slm / api.c
index eb3fa187c20851facff21e019439f709a145512f..627793852dcaea1e5b95f286628a11a5cb7fdfc5 100644 (file)
@@ -27,6 +27,9 @@
 #include <errno.h>
 #include <string.h>
 
+/* The Colead SL-5868P uses this. */
+#define SERIALCOMM "2400/8n1"
+
 static const int hwopts[] = {
        SR_HWOPT_CONN,
        SR_HWOPT_SERIALCOMM,
@@ -41,11 +44,6 @@ static const int hwcaps[] = {
        0,
 };
 
-static const char *probe_names[] = {
-       "P1",
-       NULL,
-};
-
 SR_PRIV struct sr_dev_driver colead_slm_driver_info;
 static struct sr_dev_driver *di = &colead_slm_driver_info;
 
@@ -74,7 +72,7 @@ static int clear_instances(void)
        return SR_OK;
 }
 
-static int hw_init(void)
+static int hw_init(struct sr_context *sr_ctx)
 {
        struct drv_context *drvc;
 
@@ -83,6 +81,7 @@ static int hw_init(void)
                return SR_ERR;
        }
 
+       drvc->sr_ctx = sr_ctx;
        di->priv = drvc;
 
        return SR_OK;
@@ -116,6 +115,8 @@ static GSList *hw_scan(GSList *options)
        }
        if (!conn)
                return NULL;
+       if (!serialcomm)
+               serialcomm = SERIALCOMM;
 
        if (!(sdi = sr_dev_inst_new(0, SR_ST_INACTIVE, "Colead",
                        "SL-5868P", NULL)))
@@ -126,12 +127,9 @@ static GSList *hw_scan(GSList *options)
                return NULL;
        }
 
-       if (!serialcomm)
-               /* The Colead SL-5868P uses this. */
-               serialcomm = "2400/8n1";
+       if (!(devc->serial = sr_serial_dev_inst_new(conn, serialcomm)))
+               return NULL;
 
-       devc->serial = sr_serial_dev_inst_new(conn, -1);
-       devc->serialcomm = g_strdup(serialcomm);
        sdi->priv = devc;
        sdi->driver = di;
        if (!(probe = sr_probe_new(0, SR_PROBE_ANALOG, TRUE, "P1")))
@@ -161,17 +159,9 @@ static int hw_dev_open(struct sr_dev_inst *sdi)
                return SR_ERR_BUG;
        }
 
-       sr_dbg("opening %s with %s", devc->serial->port, devc->serialcomm);
-       devc->serial->fd = serial_open(devc->serial->port, O_RDWR | O_NONBLOCK);
-       if (devc->serial->fd == -1) {
-               sr_err("Couldn't open serial port '%s'.",
-                      devc->serial->port);
+       if (serial_open(devc->serial, SERIAL_RDWR) != SR_OK)
                return SR_ERR;
-       }
-       if (serial_set_paramstr(devc->serial->fd, devc->serialcomm) != SR_OK) {
-               sr_err("Unable to set serial parameters.");
-               return SR_ERR;
-       }
+
        sdi->status = SR_ST_ACTIVE;
 
        return SR_OK;
@@ -187,8 +177,7 @@ static int hw_dev_close(struct sr_dev_inst *sdi)
        }
 
        if (devc->serial && devc->serial->fd != -1) {
-               serial_close(devc->serial->fd);
-               devc->serial->fd = -1;
+               serial_close(devc->serial);
                sdi->status = SR_ST_INACTIVE;
        }
 
@@ -215,12 +204,6 @@ static int hw_info_get(int info_id, const void **data,
        case SR_DI_HWCAPS:
                *data = hwcaps;
                break;
-       case SR_DI_NUM_PROBES:
-               *data = GINT_TO_POINTER(1);
-               break;
-       case SR_DI_PROBE_NAMES:
-               *data = probe_names;
-               break;
        default:
                return SR_ERR_ARG;
        }