X-Git-Url: http://sigrok.org/gitweb/?a=blobdiff_plain;f=hardware%2Frigol-ds%2Fapi.c;h=aafbb6b841eb5f788da2b628c0c6e8e600d62917;hb=07ccb2b3f1beda0f2bbb7cdbb830975b7bc739f2;hp=201a6f5d79e9ea414b93f050d9e78338f115c6e1;hpb=962af1a379f2c1715b22f0779ed3ebc6f0d8c2ec;p=libsigrok.git diff --git a/hardware/rigol-ds/api.c b/hardware/rigol-ds/api.c index 201a6f5d..aafbb6b8 100644 --- a/hardware/rigol-ds/api.c +++ b/hardware/rigol-ds/api.c @@ -242,16 +242,16 @@ static int probe_port(const char *resource, const char *serialcomm, GSList **dev *devices = NULL; if (strncmp(resource, usbtmc_prefix, strlen(usbtmc_prefix)) == 0) { - sr_dbg("Opening USBTMC device %s", resource); + 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); + 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_dbg("Invalid parameters"); + sr_err("Invalid parameters."); g_strfreev(tokens); return SR_ERR_ARG; } @@ -260,7 +260,7 @@ static int probe_port(const char *resource, const char *serialcomm, GSList **dev if (!scpi) return SR_ERR_MALLOC; } else { - sr_dbg("Opening serial device %s", resource); + sr_dbg("Opening serial device %s.", resource); if (!(scpi = scpi_serial_dev_inst_new(resource, serialcomm))) return SR_ERR_MALLOC; } @@ -279,6 +279,7 @@ static int probe_port(const char *resource, const char *serialcomm, GSList **dev if (strcasecmp(hw_info->manufacturer, "Rigol Technologies")) { sr_scpi_hw_info_free(hw_info); + sr_scpi_close(scpi); sr_scpi_free(scpi); return SR_ERR_NA; } @@ -294,11 +295,13 @@ static int probe_port(const char *resource, const char *serialcomm, GSList **dev hw_info->manufacturer, hw_info->model, hw_info->firmware_version))) { sr_scpi_hw_info_free(hw_info); + sr_scpi_close(scpi); sr_scpi_free(scpi); return SR_ERR_NA; } sr_scpi_hw_info_free(hw_info); + sr_scpi_close(scpi); sdi->conn = scpi; @@ -779,7 +782,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) struct dev_context *devc; struct sr_probe *probe; GSList *l; - char cmd[256]; if (sdi->status != SR_ST_ACTIVE) return SR_ERR_DEV_CLOSED; @@ -787,19 +789,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) scpi = sdi->conn; devc = sdi->priv; - if (devc->data_source == DATA_SOURCE_LIVE) { - if (sr_scpi_send(sdi->conn, ":RUN") != SR_OK) - return SR_ERR; - } else if (devc->data_source == DATA_SOURCE_MEMORY) { - if (devc->model->series != RIGOL_DS2000) { - sr_err("Data source 'Memory' not supported for this device"); - return SR_ERR; - } - } else if (devc->data_source == DATA_SOURCE_SEGMENTED) { - sr_err("Data source 'Segmented' not yet supported"); - return SR_ERR; - } - for (l = sdi->probes; l; l = l->next) { probe = l->data; sr_dbg("handling probe %s", probe->name); @@ -809,9 +798,8 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) devc->enabled_analog_probes, probe); if (probe->enabled != devc->analog_channels[probe->index]) { /* Enabled channel is currently disabled, or vice versa. */ - sprintf(cmd, ":CHAN%d:DISP %s", probe->index + 1, - probe->enabled ? "ON" : "OFF"); - if (sr_scpi_send(sdi->conn, cmd) != SR_OK) + if (set_cfg(sdi, ":CHAN%d:DISP %s", probe->index + 1, + probe->enabled ? "ON" : "OFF") != SR_OK) return SR_ERR; } } else if (probe->type == SR_PROBE_LOGIC) { @@ -820,36 +808,45 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) devc->enabled_digital_probes, probe); if (probe->enabled != devc->digital_channels[probe->index]) { /* Enabled channel is currently disabled, or vice versa. */ - sprintf(cmd, ":DIG%d:TURN %s", probe->index, - probe->enabled ? "ON" : "OFF"); - if (sr_scpi_send(sdi->conn, cmd) != SR_OK) + if (set_cfg(sdi, ":DIG%d:TURN %s", probe->index, + probe->enabled ? "ON" : "OFF") != SR_OK) return SR_ERR; } } } + if (!devc->enabled_analog_probes && !devc->enabled_digital_probes) return SR_ERR; + if (devc->data_source == DATA_SOURCE_LIVE) { + if (set_cfg(sdi, ":RUN") != SR_OK) + return SR_ERR; + } else if (devc->data_source == DATA_SOURCE_MEMORY) { + if (devc->model->series != RIGOL_DS2000) { + sr_err("Data source 'Memory' not supported for this device"); + return SR_ERR; + } + } else if (devc->data_source == DATA_SOURCE_SEGMENTED) { + sr_err("Data source 'Segmented' not yet supported"); + return SR_ERR; + } + sr_scpi_source_add(scpi, G_IO_IN, 50, rigol_ds_receive, (void *)sdi); /* Send header packet to the session bus. */ std_session_send_df_header(cb_data, LOG_PREFIX); if (devc->model->protocol == PROTOCOL_LEGACY) { + devc->analog_frame_size = (devc->model->series == RIGOL_VS5000 ? + VS5000_ANALOG_LIVE_WAVEFORM_SIZE : + DS1000_ANALOG_LIVE_WAVEFORM_SIZE); /* Fetch the first frame. */ - if (devc->enabled_analog_probes) { - devc->analog_frame_size = DS1000_ANALOG_LIVE_WAVEFORM_SIZE; - devc->channel_frame = devc->enabled_analog_probes->data; - if (sr_scpi_send(sdi->conn, ":WAV:DATA? CHAN%d", - devc->channel_frame->index + 1) != SR_OK) - return SR_ERR; - } else { - devc->channel_frame = devc->enabled_digital_probes->data; - if (sr_scpi_send(sdi->conn, ":WAV:DATA? DIG") != SR_OK) - return SR_ERR; - } - - devc->num_frame_bytes = 0; + if (devc->enabled_analog_probes) + devc->channel = devc->enabled_analog_probes->data; + else + devc->channel = devc->enabled_digital_probes->data; + if (rigol_ds_channel_start(sdi) != SR_OK) + return SR_ERR; } else { if (devc->enabled_analog_probes) { if (devc->data_source == DATA_SOURCE_MEMORY) @@ -861,15 +858,15 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) /* Apparently for the DS2000 the memory * depth can only be set in Running state - * this matches the behaviour of the UI. */ - if (sr_scpi_send(sdi->conn, ":RUN") != SR_OK) + if (set_cfg(sdi, ":RUN") != SR_OK) return SR_ERR; - if (sr_scpi_send(sdi->conn, "ACQ:MDEP %d", devc->analog_frame_size) != SR_OK) + if (set_cfg(sdi, "ACQ:MDEP %d", devc->analog_frame_size) != SR_OK) return SR_ERR; - if (sr_scpi_send(sdi->conn, ":STOP") != SR_OK) + if (set_cfg(sdi, ":STOP") != SR_OK) return SR_ERR; } else devc->analog_frame_size = DS2000_ANALOG_LIVE_WAVEFORM_SIZE; - devc->channel_frame = devc->enabled_analog_probes->data; + devc->channel = devc->enabled_analog_probes->data; if (rigol_ds_capture_start(sdi) != SR_OK) return SR_ERR; }