+ udi->bus = bus;
+ udi->address = address;
+ udi->devhdl = hdl;
+
+ return udi;
+}
+
+/** @private */
+SR_PRIV void sr_usb_dev_inst_free(struct sr_usb_dev_inst *usb)
+{
+ g_free(usb);
+}
+
+#endif
+
+/**
+ * @private
+ *
+ * Both parameters are copied to newly allocated strings, and freed
+ * automatically by sr_serial_dev_inst_free().
+ *
+ * @param pathname OS-specific serial port specification. Examples:
+ * "/dev/ttyUSB0", "/dev/ttyACM1", "/dev/tty.Modem-0", "COM1".
+ * @param serialcomm A serial communication parameters string, in the form
+ * of <speed>/<data bits><parity><stopbits>, for example
+ * "9600/8n1" or "600/7o2". This is an optional parameter;
+ * it may be filled in later.
+ *
+ * @return A pointer to a newly initialized struct sr_serial_dev_inst,
+ * or NULL on error.
+ */
+SR_PRIV struct sr_serial_dev_inst *sr_serial_dev_inst_new(const char *port,
+ const char *serialcomm)
+{
+ struct sr_serial_dev_inst *serial;
+
+ if (!port) {
+ sr_err("Serial port required.");
+ return NULL;
+ }
+
+ if (!(serial = g_try_malloc0(sizeof(struct sr_serial_dev_inst)))) {
+ sr_err("Serial device instance malloc failed.");
+ return NULL;
+ }
+
+ serial->port = g_strdup(port);
+ if (serialcomm)
+ serial->serialcomm = g_strdup(serialcomm);
+ serial->fd = -1;
+
+ return serial;
+}
+
+/** @private */
+SR_PRIV void sr_serial_dev_inst_free(struct sr_serial_dev_inst *serial)
+{
+ g_free(serial->port);
+ g_free(serial->serialcomm);
+ g_free(serial);
+}
+
+/**
+ * Get the list of devices/instances of the specified driver.
+ *
+ * @param driver The driver to use. Must not be NULL.
+ *
+ * @return The list of devices/instances of this driver, or NULL upon errors
+ * or if the list is empty.
+ *
+ * @since 0.1.0 (but the API changed in 0.2.0)
+ */
+SR_API GSList *sr_dev_list(const struct sr_dev_driver *driver)
+{
+ if (driver && driver->dev_list)
+ return driver->dev_list();
+ else
+ return NULL;
+}
+
+/**
+ * Clear all devices/instances of the specified driver.
+ *
+ * @param driver The driver to use. Must not be NULL.
+ *
+ * @return SR_OK upon success, a negative error code upon errors.
+ *
+ * @since 0.2.0
+ */
+SR_API int sr_dev_clear(const struct sr_dev_driver *driver)
+{
+ if (driver && driver->dev_clear)
+ return driver->dev_clear();
+ else
+ return SR_OK;
+}
+
+/**
+ * Open the specified device.
+ *
+ * @param sdi Device instance to use. Must not be NULL.
+ *
+ * @return SR_OK upon success, a negative error code upon errors.
+ *
+ * @since 0.2.0
+ */
+SR_API int sr_dev_open(struct sr_dev_inst *sdi)
+{
+ int ret;
+
+ if (!sdi || !sdi->driver || !sdi->driver->dev_open)
+ return SR_ERR;
+
+ ret = sdi->driver->dev_open(sdi);
+
+ return ret;
+}
+
+/**
+ * Close the specified device.
+ *
+ * @param sdi Device instance to use. Must not be NULL.
+ *
+ * @return SR_OK upon success, a negative error code upon errors.
+ *
+ * @since 0.2.0
+ */
+SR_API int sr_dev_close(struct sr_dev_inst *sdi)
+{
+ int ret;
+
+ if (!sdi || !sdi->driver || !sdi->driver->dev_close)
+ return SR_ERR;
+
+ ret = sdi->driver->dev_close(sdi);
+
+ return ret;