return SR_ERR;
}
+SR_PRIV struct sr_scpi_dev_inst *scpi_dev_inst_new(const char *resource,
+ const char *serialcomm)
+{
+ struct sr_scpi_dev_inst *scpi = NULL;
+ const char *usbtmc_prefix = "/dev/usbtmc";
+ const char *tcp_prefix = "tcp/";
+ const char *vxi_prefix = "vxi/";
+ gchar **tokens, *address, *port, *instrument;
+
+ if (strncmp(resource, usbtmc_prefix, strlen(usbtmc_prefix)) == 0) {
+ sr_dbg("Opening USBTMC device %s.", resource);
+ scpi = scpi_usbtmc_dev_inst_new(resource);
+ } else if (strncmp(resource, tcp_prefix, strlen(tcp_prefix)) == 0) {
+ sr_dbg("Opening TCP connection %s.", resource);
+ tokens = g_strsplit(resource + strlen(tcp_prefix), "/", 0);
+ address = tokens[0];
+ port = tokens[1];
+ if (address && port && !tokens[2])
+ scpi = scpi_tcp_dev_inst_new(address, port);
+ else
+ sr_err("Invalid parameters.");
+ g_strfreev(tokens);
+ } else if (HAVE_RPC && !strncmp(resource, vxi_prefix, strlen(vxi_prefix))) {
+ sr_dbg("Opening VXI connection %s.", resource);
+ tokens = g_strsplit(resource + strlen(tcp_prefix), "/", 0);
+ address = tokens[0];
+ instrument = tokens[1];
+ if (address && (!instrument || !tokens[2]))
+ scpi = scpi_vxi_dev_inst_new(address, instrument);
+ else
+ sr_err("Invalid parameters.");
+ g_strfreev(tokens);
+ } else {
+ sr_dbg("Opening serial device %s.", resource);
+ scpi = scpi_serial_dev_inst_new(resource, serialcomm);
+ }
+ return scpi;
+}
+
/**
* Open SCPI device.
*
scpi = NULL;
hw_info = NULL;
- if (!(scpi = scpi_serial_dev_inst_new(serial_device, serial_options)))
+ if (!(scpi = scpi_dev_inst_new(serial_device, serial_options)))
goto fail;
sr_info("Probing %s.", serial_device);
{
struct dev_context *devc;
struct sr_dev_inst *sdi;
- const char *usbtmc_prefix = "/dev/usbtmc";
- const char *tcp_prefix = "tcp/";
- const char *vxi_prefix = "vxi/";
- gchar **tokens, *address, *port, *instrument;
struct sr_scpi_dev_inst *scpi;
struct sr_scpi_hw_info *hw_info;
struct sr_probe *probe;
*devices = NULL;
- if (strncmp(resource, usbtmc_prefix, strlen(usbtmc_prefix)) == 0) {
- sr_dbg("Opening USBTMC device %s.", resource);
- if (!(scpi = scpi_usbtmc_dev_inst_new(resource)))
- return SR_ERR_MALLOC;
- } else if (strncmp(resource, tcp_prefix, strlen(tcp_prefix)) == 0) {
- sr_dbg("Opening TCP connection %s.", resource);
- tokens = g_strsplit(resource + strlen(tcp_prefix), "/", 0);
- address = tokens[0];
- port = tokens[1];
- if (!address || !port || tokens[2]) {
- sr_err("Invalid parameters.");
- g_strfreev(tokens);
- return SR_ERR_ARG;
- }
- scpi = scpi_tcp_dev_inst_new(address, port);
- g_strfreev(tokens);
- if (!scpi)
- return SR_ERR_MALLOC;
- } else if (HAVE_RPC && !strncmp(resource, vxi_prefix, strlen(vxi_prefix))) {
- sr_dbg("Opening VXI connection %s.", resource);
- tokens = g_strsplit(resource + strlen(tcp_prefix), "/", 0);
- address = tokens[0];
- instrument = tokens[1];
- if (!address) {
- sr_err("Invalid parameters.");
- g_strfreev(tokens);
- return SR_ERR_ARG;
- }
- scpi = scpi_vxi_dev_inst_new(address, instrument);
- g_strfreev(tokens);
- if (!scpi)
- return SR_ERR_MALLOC;
- } else {
- sr_dbg("Opening serial device %s.", resource);
- if (!(scpi = scpi_serial_dev_inst_new(resource, serialcomm)))
- return SR_ERR_MALLOC;
- }
+ if (!(scpi = scpi_dev_inst_new(resource, serialcomm)))
+ return SR_ERR;
if (sr_scpi_open(scpi) != SR_OK) {
sr_info("Couldn't open SCPI device.");
void *priv;
};
+SR_PRIV struct sr_scpi_dev_inst *scpi_dev_inst_new(const char *resource,
+ const char *serialcomm);
SR_PRIV int sr_scpi_open(struct sr_scpi_dev_inst *scpi);
SR_PRIV int sr_scpi_source_add(struct sr_scpi_dev_inst *scpi, int events,
int timeout, sr_receive_data_callback_t cb, void *cb_data);