X-Git-Url: http://sigrok.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fscpi%2Fscpi_vxi.c;h=774b8b52ca2f43db2e0d2bc807820ed9bdf049b0;hb=9417f26fd47556c4b4f6ecaa08a2860672664eb9;hp=2526b487fbf932bf27b9f3377c4f4df142c77a21;hpb=c1aae90038456a61d0f9313d34e6107c3440d3e7;p=libsigrok.git
diff --git a/src/scpi/scpi_vxi.c b/src/scpi/scpi_vxi.c
index 2526b487..774b8b52 100644
--- a/src/scpi/scpi_vxi.c
+++ b/src/scpi/scpi_vxi.c
@@ -20,11 +20,13 @@
* along with this program. If not, see .
*/
+#include
+#include "vxi.h"
#include
#include
-#include "vxi.h"
#include
#include "libsigrok-internal.h"
+#include "scpi.h"
#define LOG_PREFIX "scpi_vxi"
#define VXI_DEFAULT_TIMEOUT_MS 2000
@@ -58,9 +60,9 @@ static int scpi_vxi_dev_inst_new(void *priv, struct drv_context *drvc,
return SR_OK;
}
-static int scpi_vxi_open(void *priv)
+static int scpi_vxi_open(struct sr_scpi_dev_inst *scpi)
{
- struct scpi_vxi *vxi = priv;
+ struct scpi_vxi *vxi = scpi->priv;
Create_LinkParms link_parms;
Create_LinkResp *link_resp;
@@ -74,7 +76,7 @@ static int scpi_vxi_open(void *priv)
link_parms.clientId = (long) vxi->client;
link_parms.lockDevice = 0;
link_parms.lock_timeout = VXI_DEFAULT_TIMEOUT_MS;
- link_parms.device = "inst0";
+ link_parms.device = (char *)"inst0";
if (!(link_resp = create_link_1(&link_parms, vxi->client))) {
sr_err("Link creation failed for %s", vxi->address);
@@ -90,6 +92,16 @@ static int scpi_vxi_open(void *priv)
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)
{
@@ -116,30 +128,26 @@ static int scpi_vxi_send(void *priv, const char *command)
struct scpi_vxi *vxi = priv;
Device_WriteResp *write_resp;
Device_WriteParms write_parms;
- char *terminated_command;
- unsigned int len;
+ unsigned long len;
- terminated_command = g_strdup_printf("%s\r\n", command);
- len = strlen(terminated_command);
+ len = strlen(command);
write_parms.lid = vxi->link;
write_parms.io_timeout = VXI_DEFAULT_TIMEOUT_MS;
write_parms.lock_timeout = VXI_DEFAULT_TIMEOUT_MS;
write_parms.flags = DF_END;
write_parms.data.data_len = MIN(len, vxi->max_send_size);
- write_parms.data.data_val = terminated_command;
+ write_parms.data.data_val = (char *)command;
if (!(write_resp = device_write_1(&write_parms, vxi->client))
|| write_resp->error) {
- sr_err("Device write failed for %s with error %d",
+ sr_err("Device write failed for %s with error %ld",
vxi->address, write_resp ? write_resp->error : 0);
return SR_ERR;
}
- g_free(terminated_command);
-
if (write_resp->size < len)
- sr_dbg("Only sent %d/%d bytes of SCPI command: '%s'.",
+ sr_dbg("Only sent %lu/%lu bytes of SCPI command: '%s'.",
write_resp->size, len, command);
else
sr_spew("Successfully sent SCPI command: '%s'.", command);
@@ -176,13 +184,13 @@ static int scpi_vxi_read_data(void *priv, char *buf, int maxlen)
if (!(read_resp = device_read_1(&read_parms, vxi->client))
|| read_resp->error) {
- sr_err("Device read failed for %s with error %d",
+ sr_err("Device read failed for %s with error %ld",
vxi->address, read_resp ? read_resp->error : 0);
return SR_ERR;
}
memcpy(buf, read_resp->data.data_val, read_resp->data.data_len);
- vxi->read_complete = read_resp->reason & (RRR_SIZE | RRR_TERM | RRR_END);
+ vxi->read_complete = read_resp->reason & (RRR_TERM | RRR_END);
return read_resp->data.data_len; /* actual number of bytes received */
}
@@ -193,9 +201,9 @@ static int scpi_vxi_read_complete(void *priv)
return vxi->read_complete;
}
-static int scpi_vxi_close(void *priv)
+static int scpi_vxi_close(struct sr_scpi_dev_inst *scpi)
{
- struct scpi_vxi *vxi = priv;
+ struct scpi_vxi *vxi = scpi->priv;
Device_Error *dev_error;
if (!vxi->client)
@@ -223,9 +231,11 @@ static void scpi_vxi_free(void *priv)
SR_PRIV const struct sr_scpi_dev_inst scpi_vxi_dev = {
.name = "VXI",
.prefix = "vxi",
+ .transport = SCPI_TRANSPORT_VXI,
.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,