Replace rigol_ds_send() function with sr_scpi_send().

This commit is contained in:
Martin Ling 2013-12-04 10:25:15 +00:00
parent 504f40a574
commit 17b5b20264
3 changed files with 27 additions and 41 deletions

View File

@ -197,7 +197,7 @@ static int set_cfg(const struct sr_dev_inst *sdi, const char *format, ...)
va_start(args, format); va_start(args, format);
vsnprintf(buf, 255, format, args); vsnprintf(buf, 255, format, args);
va_end(args); va_end(args);
if (rigol_ds_send(sdi, buf) != SR_OK) if (sr_scpi_send(sdi->conn, buf) != SR_OK)
return SR_ERR; return SR_ERR;
/* When setting a bunch of parameters in a row, the DS1052E scrambles /* When setting a bunch of parameters in a row, the DS1052E scrambles
@ -740,7 +740,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
devc = sdi->priv; devc = sdi->priv;
if (devc->data_source == DATA_SOURCE_LIVE) { if (devc->data_source == DATA_SOURCE_LIVE) {
if (rigol_ds_send(sdi, ":RUN") != SR_OK) if (sr_scpi_send(sdi->conn, ":RUN") != SR_OK)
return SR_ERR; return SR_ERR;
} else if (devc->data_source == DATA_SOURCE_MEMORY) { } else if (devc->data_source == DATA_SOURCE_MEMORY) {
if (devc->model->series != RIGOL_DS2000) { if (devc->model->series != RIGOL_DS2000) {
@ -763,7 +763,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
/* Enabled channel is currently disabled, or vice versa. */ /* Enabled channel is currently disabled, or vice versa. */
sprintf(cmd, ":CHAN%d:DISP %s", probe->index + 1, sprintf(cmd, ":CHAN%d:DISP %s", probe->index + 1,
probe->enabled ? "ON" : "OFF"); probe->enabled ? "ON" : "OFF");
if (rigol_ds_send(sdi, cmd) != SR_OK) if (sr_scpi_send(sdi->conn, cmd) != SR_OK)
return SR_ERR; return SR_ERR;
} }
} else if (probe->type == SR_PROBE_LOGIC) { } else if (probe->type == SR_PROBE_LOGIC) {
@ -774,7 +774,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
/* Enabled channel is currently disabled, or vice versa. */ /* Enabled channel is currently disabled, or vice versa. */
sprintf(cmd, ":DIG%d:TURN %s", probe->index, sprintf(cmd, ":DIG%d:TURN %s", probe->index,
probe->enabled ? "ON" : "OFF"); probe->enabled ? "ON" : "OFF");
if (rigol_ds_send(sdi, cmd) != SR_OK) if (sr_scpi_send(sdi->conn, cmd) != SR_OK)
return SR_ERR; return SR_ERR;
} }
} }
@ -792,12 +792,12 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
if (devc->enabled_analog_probes) { if (devc->enabled_analog_probes) {
devc->analog_frame_size = DS1000_ANALOG_LIVE_WAVEFORM_SIZE; devc->analog_frame_size = DS1000_ANALOG_LIVE_WAVEFORM_SIZE;
devc->channel_frame = devc->enabled_analog_probes->data; devc->channel_frame = devc->enabled_analog_probes->data;
if (rigol_ds_send(sdi, ":WAV:DATA? CHAN%d", if (sr_scpi_send(sdi->conn, ":WAV:DATA? CHAN%d",
devc->channel_frame->index + 1) != SR_OK) devc->channel_frame->index + 1) != SR_OK)
return SR_ERR; return SR_ERR;
} else { } else {
devc->channel_frame = devc->enabled_digital_probes->data; devc->channel_frame = devc->enabled_digital_probes->data;
if (rigol_ds_send(sdi, ":WAV:DATA? DIG") != SR_OK) if (sr_scpi_send(sdi->conn, ":WAV:DATA? DIG") != SR_OK)
return SR_ERR; return SR_ERR;
} }
@ -813,11 +813,11 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
/* Apparently for the DS2000 the memory /* Apparently for the DS2000 the memory
* depth can only be set in Running state - * depth can only be set in Running state -
* this matches the behaviour of the UI. */ * this matches the behaviour of the UI. */
if (rigol_ds_send(sdi, ":RUN") != SR_OK) if (sr_scpi_send(sdi->conn, ":RUN") != SR_OK)
return SR_ERR; return SR_ERR;
if (rigol_ds_send(sdi, "ACQ:MDEP %d", devc->analog_frame_size) != SR_OK) if (sr_scpi_send(sdi->conn, "ACQ:MDEP %d", devc->analog_frame_size) != SR_OK)
return SR_ERR; return SR_ERR;
if (rigol_ds_send(sdi, ":STOP") != SR_OK) if (sr_scpi_send(sdi->conn, ":STOP") != SR_OK)
return SR_ERR; return SR_ERR;
} else } else
devc->analog_frame_size = DS2000_ANALOG_LIVE_WAVEFORM_SIZE; devc->analog_frame_size = DS2000_ANALOG_LIVE_WAVEFORM_SIZE;

View File

@ -216,11 +216,11 @@ static int rigol_ds_check_stop(const struct sr_dev_inst *sdi)
if (!(devc = sdi->priv)) if (!(devc = sdi->priv))
return SR_ERR; return SR_ERR;
if (rigol_ds_send(sdi, ":WAV:SOUR CHAN%d", if (sr_scpi_send(sdi->conn, ":WAV:SOUR CHAN%d",
devc->channel_frame->index + 1) != SR_OK) devc->channel_frame->index + 1) != SR_OK)
return SR_ERR; return SR_ERR;
/* Check that the number of samples will be accepted */ /* Check that the number of samples will be accepted */
if (rigol_ds_send(sdi, ":WAV:POIN %d;*OPC", devc->analog_frame_size) != SR_OK) if (sr_scpi_send(sdi->conn, ":WAV:POIN %d;*OPC", devc->analog_frame_size) != SR_OK)
return SR_ERR; return SR_ERR;
if (get_cfg_int(sdi, "*ESR?", &tmp) != SR_OK) if (get_cfg_int(sdi, "*ESR?", &tmp) != SR_OK)
return SR_ERR; return SR_ERR;
@ -240,7 +240,7 @@ static int rigol_ds_check_stop(const struct sr_dev_inst *sdi)
sr_warn("Single shot acquisition failed, retrying..."); sr_warn("Single shot acquisition failed, retrying...");
/* Sleep a bit, otherwise the single shot will often fail */ /* Sleep a bit, otherwise the single shot will often fail */
g_usleep(500000); g_usleep(500000);
rigol_ds_send(sdi, ":SING"); sr_scpi_send(sdi->conn, ":SING");
rigol_ds_set_wait_event(devc, WAIT_STOP); rigol_ds_set_wait_event(devc, WAIT_STOP);
return SR_ERR; return SR_ERR;
} }
@ -299,16 +299,16 @@ SR_PRIV int rigol_ds_capture_start(const struct sr_dev_inst *sdi)
sr_dbg("Starting data capture for frameset %lu of %lu", sr_dbg("Starting data capture for frameset %lu of %lu",
devc->num_frames + 1, devc->limit_frames); devc->num_frames + 1, devc->limit_frames);
if (rigol_ds_send(sdi, ":WAV:FORM BYTE") != SR_OK) if (sr_scpi_send(sdi->conn, ":WAV:FORM BYTE") != SR_OK)
return SR_ERR; return SR_ERR;
if (devc->data_source == DATA_SOURCE_LIVE) { if (devc->data_source == DATA_SOURCE_LIVE) {
if (rigol_ds_send(sdi, ":WAV:MODE NORM") != SR_OK) if (sr_scpi_send(sdi->conn, ":WAV:MODE NORM") != SR_OK)
return SR_ERR; return SR_ERR;
rigol_ds_set_wait_event(devc, WAIT_TRIGGER); rigol_ds_set_wait_event(devc, WAIT_TRIGGER);
} else { } else {
if (rigol_ds_send(sdi, ":WAV:MODE RAW") != SR_OK) if (sr_scpi_send(sdi->conn, ":WAV:MODE RAW") != SR_OK)
return SR_ERR; return SR_ERR;
if (rigol_ds_send(sdi, ":SING", devc->analog_frame_size) != SR_OK) if (sr_scpi_send(sdi->conn, ":SING", devc->analog_frame_size) != SR_OK)
return SR_ERR; return SR_ERR;
rigol_ds_set_wait_event(devc, WAIT_STOP); rigol_ds_set_wait_event(devc, WAIT_STOP);
} }
@ -327,13 +327,13 @@ SR_PRIV int rigol_ds_channel_start(const struct sr_dev_inst *sdi)
sr_dbg("Starting reading data from channel %d", sr_dbg("Starting reading data from channel %d",
devc->channel_frame->index + 1); devc->channel_frame->index + 1);
if (rigol_ds_send(sdi, ":WAV:SOUR CHAN%d", if (sr_scpi_send(sdi->conn, ":WAV:SOUR CHAN%d",
devc->channel_frame->index + 1) != SR_OK) devc->channel_frame->index + 1) != SR_OK)
return SR_ERR; return SR_ERR;
if (devc->data_source != DATA_SOURCE_LIVE) { if (devc->data_source != DATA_SOURCE_LIVE) {
if (rigol_ds_send(sdi, ":WAV:RES") != SR_OK) if (sr_scpi_send(sdi->conn, ":WAV:RES") != SR_OK)
return SR_ERR; return SR_ERR;
if (rigol_ds_send(sdi, ":WAV:BEG") != SR_OK) if (sr_scpi_send(sdi->conn, ":WAV:BEG") != SR_OK)
return SR_ERR; return SR_ERR;
rigol_ds_set_wait_event(devc, WAIT_BLOCK); rigol_ds_set_wait_event(devc, WAIT_BLOCK);
} else } else
@ -440,7 +440,7 @@ SR_PRIV int rigol_ds_receive(int fd, int revents, void *cb_data)
if (devc->num_block_bytes == 0) { if (devc->num_block_bytes == 0) {
sr_dbg("New block header expected"); sr_dbg("New block header expected");
if (rigol_ds_send(sdi, ":WAV:DATA?") != SR_OK) if (sr_scpi_send(sdi->conn, ":WAV:DATA?") != SR_OK)
return TRUE; return TRUE;
len = rigol_ds_read_header(scpi); len = rigol_ds_read_header(scpi);
if (len == -1) if (len == -1)
@ -556,7 +556,7 @@ SR_PRIV int rigol_ds_receive(int fd, int revents, void *cb_data)
* to the next channel causes an error. Fun with * to the next channel causes an error. Fun with
* firmware... * firmware...
*/ */
rigol_ds_send(sdi, ":WAV:END"); sr_scpi_send(sdi->conn, ":WAV:END");
} }
if (devc->enabled_analog_probes if (devc->enabled_analog_probes
@ -568,7 +568,7 @@ SR_PRIV int rigol_ds_receive(int fd, int revents, void *cb_data)
if (devc->model->protocol == PROTOCOL_IEEE488_2) { if (devc->model->protocol == PROTOCOL_IEEE488_2) {
rigol_ds_channel_start(sdi); rigol_ds_channel_start(sdi);
} else { } else {
rigol_ds_send(sdi, ":WAV:DATA? CHAN%c", sr_scpi_send(sdi->conn, ":WAV:DATA? CHAN%c",
devc->channel_frame->name[2]); devc->channel_frame->name[2]);
} }
} else { } else {
@ -577,7 +577,7 @@ SR_PRIV int rigol_ds_receive(int fd, int revents, void *cb_data)
&& devc->channel_frame != devc->enabled_digital_probes->data) { && devc->channel_frame != devc->enabled_digital_probes->data) {
/* Now we need to get the digital data. */ /* Now we need to get the digital data. */
devc->channel_frame = devc->enabled_digital_probes->data; devc->channel_frame = devc->enabled_digital_probes->data;
rigol_ds_send(sdi, ":WAV:DATA? DIG"); sr_scpi_send(sdi->conn, ":WAV:DATA? DIG");
} else if (++devc->num_frames == devc->limit_frames) { } else if (++devc->num_frames == devc->limit_frames) {
/* End of last frame. */ /* End of last frame. */
packet.type = SR_DF_END; packet.type = SR_DF_END;
@ -593,11 +593,11 @@ SR_PRIV int rigol_ds_receive(int fd, int revents, void *cb_data)
} else { } else {
if (devc->enabled_analog_probes) { if (devc->enabled_analog_probes) {
devc->channel_frame = devc->enabled_analog_probes->data; devc->channel_frame = devc->enabled_analog_probes->data;
rigol_ds_send(sdi, ":WAV:DATA? CHAN%c", sr_scpi_send(sdi->conn, ":WAV:DATA? CHAN%c",
devc->channel_frame->name[2]); devc->channel_frame->name[2]);
} else { } else {
devc->channel_frame = devc->enabled_digital_probes->data; devc->channel_frame = devc->enabled_digital_probes->data;
rigol_ds_send(sdi, ":WAV:DATA? DIG"); sr_scpi_send(sdi->conn, ":WAV:DATA? DIG");
} }
} }
} }
@ -607,19 +607,6 @@ SR_PRIV int rigol_ds_receive(int fd, int revents, void *cb_data)
return TRUE; return TRUE;
} }
SR_PRIV int rigol_ds_send(const struct sr_dev_inst *sdi, const char *format, ...)
{
va_list args;
char buf[256];
struct sr_scpi_dev_inst *scpi = sdi->conn;
va_start(args, format);
vsnprintf(buf, 255, format, args);
va_end(args);
return sr_scpi_send(scpi, buf);
}
static int get_cfg(const struct sr_dev_inst *sdi, char *cmd, char *reply, size_t maxlen) static int get_cfg(const struct sr_dev_inst *sdi, char *cmd, char *reply, size_t maxlen)
{ {
int len; int len;
@ -737,11 +724,11 @@ SR_PRIV int rigol_ds_get_dev_cfg(const struct sr_dev_inst *sdi)
if (devc->model->protocol == PROTOCOL_IEEE488_2) { if (devc->model->protocol == PROTOCOL_IEEE488_2) {
/* Vertical reference - not certain if this is the place to read it. */ /* Vertical reference - not certain if this is the place to read it. */
if (rigol_ds_send(sdi, ":WAV:SOUR CHAN1") != SR_OK) if (sr_scpi_send(sdi->conn, ":WAV:SOUR CHAN1") != SR_OK)
return SR_ERR; return SR_ERR;
if (get_cfg_int(sdi, ":WAV:YREF?", &devc->vert_reference[0]) != SR_OK) if (get_cfg_int(sdi, ":WAV:YREF?", &devc->vert_reference[0]) != SR_OK)
return SR_ERR; return SR_ERR;
if (rigol_ds_send(sdi, ":WAV:SOUR CHAN2") != SR_OK) if (sr_scpi_send(sdi->conn, ":WAV:SOUR CHAN2") != SR_OK)
return SR_ERR; return SR_ERR;
if (get_cfg_int(sdi, ":WAV:YREF?", &devc->vert_reference[1]) != SR_OK) if (get_cfg_int(sdi, ":WAV:YREF?", &devc->vert_reference[1]) != SR_OK)
return SR_ERR; return SR_ERR;

View File

@ -138,7 +138,6 @@ struct dev_context {
SR_PRIV int rigol_ds_capture_start(const struct sr_dev_inst *sdi); SR_PRIV int rigol_ds_capture_start(const struct sr_dev_inst *sdi);
SR_PRIV int rigol_ds_receive(int fd, int revents, void *cb_data); SR_PRIV int rigol_ds_receive(int fd, int revents, void *cb_data);
SR_PRIV int rigol_ds_send(const struct sr_dev_inst *sdi, const char *format, ...);
SR_PRIV int rigol_ds_get_dev_cfg(const struct sr_dev_inst *sdi); SR_PRIV int rigol_ds_get_dev_cfg(const struct sr_dev_inst *sdi);
#endif #endif