#include <string.h>
#include <libsigrok/libsigrok.h>
#include "libsigrok-internal.h"
+#include "scpi.h"
/** @cond PRIVATE */
#define LOG_PREFIX "device"
#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_LIBSERIALPORT
+ 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;
-
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;
}
int (*dev_inst_new)(void *priv, struct drv_context *drvc,
const char *resource, char **params, const char *serialcomm);
int (*open)(struct sr_scpi_dev_inst *scpi);
+ int (*connection_id)(struct sr_scpi_dev_inst *scpi, char **connection_id);
int (*source_add)(struct sr_session *session, void *priv, int events,
int timeout, sr_receive_data_callback cb, void *cb_data);
int (*source_remove)(struct sr_session *session, void *priv);
SR_PRIV struct sr_scpi_dev_inst *scpi_dev_inst_new(struct drv_context *drvc,
const char *resource, const char *serialcomm);
SR_PRIV int sr_scpi_open(struct sr_scpi_dev_inst *scpi);
+SR_PRIV int sr_scpi_connection_id(struct sr_scpi_dev_inst *scpi,
+ char **connection_id);
SR_PRIV int sr_scpi_source_add(struct sr_session *session,
struct sr_scpi_dev_inst *scpi, int events, int timeout,
sr_receive_data_callback cb, void *cb_data);
return scpi->open(scpi);
}
+/**
+ * Get the connection ID of the SCPI device.
+ *
+ * @param scpi Previously initialized SCPI device structure.
+ * @param connection_id Pointer where to store the connection ID. The caller
+ * is responsible for g_free()ing the string when it is no longer needed.
+ *
+ * @return SR_OK on success, SR_ERR on failure.
+ */
+SR_PRIV int sr_scpi_connection_id(struct sr_scpi_dev_inst *scpi,
+ char **connection_id)
+{
+ return scpi->connection_id(scpi, connection_id);
+}
+
/**
* Add an event source for an SCPI device.
*
return SR_OK;
}
+static int scpi_gpib_connection_id(struct sr_scpi_dev_inst *scpi,
+ char **connection_id)
+{
+ struct scpi_gpib *gscpi = scpi->priv;
+
+ *connection_id = g_strdup_printf("%s/%s", scpi->prefix, gscpi->name);
+
+ return SR_OK;
+}
+
static int scpi_gpib_source_add(struct sr_session *session, void *priv,
int events, int timeout, sr_receive_data_callback cb, void *cb_data)
{
}
SR_PRIV const struct sr_scpi_dev_inst scpi_libgpib_dev = {
- .name = "GPIB",
- .prefix = "libgpib",
- .priv_size = sizeof(struct scpi_gpib),
- .dev_inst_new = scpi_gpib_dev_inst_new,
- .open = scpi_gpib_open,
- .source_add = scpi_gpib_source_add,
+ .name = "GPIB",
+ .prefix = "libgpib",
+ .priv_size = sizeof(struct scpi_gpib),
+ .dev_inst_new = scpi_gpib_dev_inst_new,
+ .open = scpi_gpib_open,
+ .connection_id = scpi_gpib_connection_id,
+ .source_add = scpi_gpib_source_add,
.source_remove = scpi_gpib_source_remove,
- .send = scpi_gpib_send,
- .read_begin = scpi_gpib_read_begin,
- .read_data = scpi_gpib_read_data,
+ .send = scpi_gpib_send,
+ .read_begin = scpi_gpib_read_begin,
+ .read_data = scpi_gpib_read_data,
.read_complete = scpi_gpib_read_complete,
- .close = scpi_gpib_close,
- .free = scpi_gpib_free,
+ .close = scpi_gpib_close,
+ .free = scpi_gpib_free,
};
return SR_OK;
}
+static int scpi_serial_connection_id(struct sr_scpi_dev_inst *scpi,
+ char **connection_id)
+{
+ struct scpi_serial *sscpi = scpi->priv;
+ struct sr_serial_dev_inst *serial = sscpi->serial;
+
+ *connection_id = g_strdup(serial->port);
+
+ return SR_OK;
+}
+
static int scpi_serial_source_add(struct sr_session *session, void *priv,
int events, int timeout, sr_receive_data_callback cb, void *cb_data)
{
.scan = scpi_serial_scan,
.dev_inst_new = scpi_serial_dev_inst_new,
.open = scpi_serial_open,
+ .connection_id = scpi_serial_connection_id,
.source_add = scpi_serial_source_add,
.source_remove = scpi_serial_source_remove,
.send = scpi_serial_send,
return SR_OK;
}
+static int scpi_tcp_connection_id(struct sr_scpi_dev_inst *scpi,
+ char **connection_id)
+{
+ struct scpi_tcp *tcp = scpi->priv;
+
+ *connection_id = g_strdup_printf("%s/%s:%s",
+ scpi->prefix, tcp->address, tcp->port);
+
+ return SR_OK;
+}
+
static int scpi_tcp_source_add(struct sr_session *session, void *priv,
int events, int timeout, sr_receive_data_callback cb, void *cb_data)
{
.priv_size = sizeof(struct scpi_tcp),
.dev_inst_new = scpi_tcp_dev_inst_new,
.open = scpi_tcp_open,
+ .connection_id = scpi_tcp_connection_id,
.source_add = scpi_tcp_source_add,
.source_remove = scpi_tcp_source_remove,
.send = scpi_tcp_send,
.priv_size = sizeof(struct scpi_tcp),
.dev_inst_new = scpi_tcp_dev_inst_new,
.open = scpi_tcp_open,
+ .connection_id = scpi_tcp_connection_id,
.source_add = scpi_tcp_source_add,
.source_remove = scpi_tcp_source_remove,
.send = scpi_tcp_send,
*/
#include <config.h>
+#include <inttypes.h>
#include <string.h>
#include <libsigrok/libsigrok.h>
#include "libsigrok-internal.h"
return SR_OK;
}
+static int scpi_usbtmc_libusb_connection_id(struct sr_scpi_dev_inst *scpi,
+ char **connection_id)
+{
+ struct scpi_usbtmc_libusb *uscpi = scpi->priv;
+ struct sr_usb_dev_inst *usb = uscpi->usb;
+
+ *connection_id = g_strdup_printf("%s/%" PRIu8 ".%" PRIu8 "",
+ scpi->prefix, usb->bus, usb->address);
+
+ return SR_OK;
+}
+
static int scpi_usbtmc_libusb_source_add(struct sr_session *session,
void *priv, int events, int timeout, sr_receive_data_callback cb,
void *cb_data)
.scan = scpi_usbtmc_libusb_scan,
.dev_inst_new = scpi_usbtmc_libusb_dev_inst_new,
.open = scpi_usbtmc_libusb_open,
+ .connection_id = scpi_usbtmc_libusb_connection_id,
.source_add = scpi_usbtmc_libusb_source_add,
.source_remove = scpi_usbtmc_libusb_source_remove,
.send = scpi_usbtmc_libusb_send,
return SR_OK;
}
+static int scpi_visa_connection_id(struct sr_scpi_dev_inst *scpi,
+ char **connection_id)
+{
+ struct scpi_visa *vscpi = scpi->priv;
+
+ *connection_id = g_strdup_printf("%s/%s", scpi->prefix, vscpi->resource);
+
+ return SR_OK;
+}
+
static int scpi_visa_source_add(struct sr_session *session, void *priv,
int events, int timeout, sr_receive_data_callback cb, void *cb_data)
{
}
SR_PRIV const struct sr_scpi_dev_inst scpi_visa_dev = {
- .name = "VISA",
- .prefix = "visa",
- .priv_size = sizeof(struct scpi_visa),
- .dev_inst_new = scpi_visa_dev_inst_new,
- .open = scpi_visa_open,
- .source_add = scpi_visa_source_add,
+ .name = "VISA",
+ .prefix = "visa",
+ .priv_size = sizeof(struct scpi_visa),
+ .dev_inst_new = scpi_visa_dev_inst_new,
+ .open = scpi_visa_open,
+ .connection_id = scpi_visa_connection_id,
+ .source_add = scpi_visa_source_add,
.source_remove = scpi_visa_source_remove,
- .send = scpi_visa_send,
- .read_begin = scpi_visa_read_begin,
- .read_data = scpi_visa_read_data,
+ .send = scpi_visa_send,
+ .read_begin = scpi_visa_read_begin,
+ .read_data = scpi_visa_read_data,
.read_complete = scpi_visa_read_complete,
- .close = scpi_visa_close,
- .free = scpi_visa_free,
+ .close = scpi_visa_close,
+ .free = scpi_visa_free,
};
return SR_OK;
}
+static int scpi_vxi_connection_id(struct sr_scpi_dev_inst *scpi,
+ char **connection_id)
+{
+ struct scpi_vxi *vxi = scpi->priv;
+
+ *connection_id = g_strdup_printf("%s/%s", scpi->prefix, vxi->address);
+
+ return SR_OK;
+}
+
static int scpi_vxi_source_add(struct sr_session *session, void *priv,
int events, int timeout, sr_receive_data_callback cb, void *cb_data)
{
.priv_size = sizeof(struct scpi_vxi),
.dev_inst_new = scpi_vxi_dev_inst_new,
.open = scpi_vxi_open,
+ .connection_id = scpi_vxi_connection_id,
.source_add = scpi_vxi_source_add,
.source_remove = scpi_vxi_source_remove,
.send = scpi_vxi_send,