#include <string.h>
#include <libsigrok/libsigrok.h>
#include "libsigrok-internal.h"
+#include "scpi.h"
/** @cond PRIVATE */
#define LOG_PREFIX "device"
{
struct sr_channel *ch;
- ch = g_malloc0(sizeof(struct sr_channel));
+ ch = g_malloc0(sizeof(*ch));
ch->sdi = sdi;
ch->index = index;
ch->type = type;
{
struct sr_dev_inst *sdi;
- sdi = g_malloc0(sizeof(struct sr_dev_inst));
+ sdi = g_malloc0(sizeof(*sdi));
sdi->vendor = g_strdup(vendor);
sdi->model = g_strdup(model);
{
struct sr_usb_dev_inst *udi;
- udi = g_malloc0(sizeof(struct sr_usb_dev_inst));
+ udi = g_malloc0(sizeof(*udi));
udi->bus = bus;
udi->address = address;
udi->devhdl = hdl;
#endif
-#ifdef HAVE_LIBSERIALPORT
+#ifdef HAVE_SERIAL_COMM
/**
* Allocate and init a struct for a serial device instance.
{
struct sr_serial_dev_inst *serial;
- serial = g_malloc0(sizeof(struct sr_serial_dev_inst));
+ serial = g_malloc0(sizeof(*serial));
serial->port = g_strdup(port);
if (serialcomm)
serial->serialcomm = g_strdup(serialcomm);
{
struct sr_usbtmc_dev_inst *usbtmc;
- usbtmc = g_malloc0(sizeof(struct sr_usbtmc_dev_inst));
+ usbtmc = g_malloc0(sizeof(*usbtmc));
usbtmc->device = g_strdup(device);
usbtmc->fd = -1;
#ifdef HAVE_LIBUSB_1_0
struct drv_context *drvc;
int cnt, i, a, b;
- char connection_id[64];
+ char conn_id_usb[64];
struct sr_usb_dev_inst *usb;
struct libusb_device **devlist;
#endif
+#ifdef HAVE_SERIAL_COMM
+ struct sr_serial_dev_inst *serial;
+#endif
+
+ struct sr_scpi_dev_inst *scpi;
+ char *conn_id_scpi;
+
if (!sdi)
return NULL;
-#ifdef HAVE_LIBSERIALPORT
- struct sr_serial_dev_inst *serial;
-
+#ifdef HAVE_SERIAL_COMM
if ((!sdi->connection_id) && (sdi->inst_type == SR_INST_SERIAL)) {
- /* connection_id isn't populated, let's do that here. */
+ /* connection_id isn't populated, let's do that for serial devices. */
serial = sdi->conn;
((struct sr_dev_inst *)sdi)->connection_id = g_strdup(serial->port);
#ifdef HAVE_LIBUSB_1_0
if ((!sdi->connection_id) && (sdi->inst_type == SR_INST_USB)) {
- /* connection_id isn't populated, let's do that here. */
+ /* connection_id isn't populated, let's do that for USB devices. */
drvc = sdi->driver->context;
usb = sdi->conn;
if (b != usb->bus || a != usb->address)
continue;
- if (usb_get_port_path(devlist[i], connection_id, sizeof(connection_id)) < 0)
+ if (usb_get_port_path(devlist[i], conn_id_usb, sizeof(conn_id_usb)) < 0)
continue;
- ((struct sr_dev_inst *)sdi)->connection_id = g_strdup(connection_id);
+ ((struct sr_dev_inst *)sdi)->connection_id = g_strdup(conn_id_usb);
break;
}
}
#endif
+ if ((!sdi->connection_id) && (sdi->inst_type == SR_INST_SCPI)) {
+ /* connection_id isn't populated, let's do that for SCPI devices. */
+
+ scpi = sdi->conn;
+ sr_scpi_connection_id(scpi, &conn_id_scpi);
+ ((struct sr_dev_inst *)sdi)->connection_id = g_strdup(conn_id_scpi);
+ g_free(conn_id_scpi);
+ }
+
return sdi->connection_id;
}