X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Frigol-ds%2Fprotocol.c;h=e68fb08e68bcc184f16db9ae622fb3625cac0832;hb=01dd7a4cc769d3e683cb29c5cf791e9c61034f31;hp=d9d8dc7ea1d79f51352d813146b58f9971840b95;hpb=9ea62f2e0ac1ae9ee01215148177ae4e6f344078;p=libsigrok.git diff --git a/src/hardware/rigol-ds/protocol.c b/src/hardware/rigol-ds/protocol.c index d9d8dc7e..e68fb08e 100644 --- a/src/hardware/rigol-ds/protocol.c +++ b/src/hardware/rigol-ds/protocol.c @@ -220,11 +220,19 @@ static int rigol_ds_check_stop(const struct sr_dev_inst *sdi) if (devc->model->series->protocol != PROTOCOL_V3) return SR_OK; - if (rigol_ds_config_set(sdi, ":WAV:SOUR CHAN%d", - ch->index + 1) != SR_OK) - return SR_ERR; + if (ch->type == SR_CHANNEL_LOGIC) { + if (rigol_ds_config_set(sdi->conn, ":WAV:SOUR LA") != SR_OK) + return SR_ERR; + } else { + if (rigol_ds_config_set(sdi, ":WAV:SOUR CHAN%d", + ch->index + 1) != SR_OK) + return SR_ERR; + } /* Check that the number of samples will be accepted */ - if (rigol_ds_config_set(sdi, ":WAV:POIN %d", devc->analog_frame_size) != SR_OK) + if (rigol_ds_config_set(sdi, ":WAV:POIN %d", + ch->type == SR_CHANNEL_LOGIC ? + devc->digital_frame_size : + devc->analog_frame_size) != SR_OK) return SR_ERR; if (sr_scpi_get_int(sdi->conn, "*ESR?", &tmp) != SR_OK) return SR_ERR; @@ -431,9 +439,14 @@ SR_PRIV int rigol_ds_channel_start(const struct sr_dev_inst *sdi) rigol_ds_set_wait_event(devc, WAIT_NONE); break; case PROTOCOL_V3: - if (rigol_ds_config_set(sdi, ":WAV:SOUR CHAN%d", - ch->index + 1) != SR_OK) - return SR_ERR; + if (ch->type == SR_CHANNEL_LOGIC) { + if (rigol_ds_config_set(sdi->conn, ":WAV:SOUR LA") != SR_OK) + return SR_ERR; + } else { + if (rigol_ds_config_set(sdi, ":WAV:SOUR CHAN%d", + ch->index + 1) != SR_OK) + return SR_ERR; + } if (devc->data_source != DATA_SOURCE_LIVE) { if (rigol_ds_config_set(sdi, ":WAV:RES") != SR_OK) return SR_ERR; @@ -595,10 +608,10 @@ SR_PRIV int rigol_ds_receive(int fd, int revents, void *cb_data) if (devc->num_block_bytes == 0) { if (devc->model->series->protocol >= PROTOCOL_V4) { - if (sr_scpi_send(sdi->conn, ":WAV:START %d", + if (rigol_ds_config_set(sdi, ":WAV:START %d", devc->num_channel_bytes + 1) != SR_OK) return TRUE; - if (sr_scpi_send(sdi->conn, ":WAV:STOP %d", + if (rigol_ds_config_set(sdi, ":WAV:STOP %d", MIN(devc->num_channel_bytes + ACQ_BLOCK_SIZE, devc->analog_frame_size)) != SR_OK) return TRUE; @@ -672,7 +685,9 @@ SR_PRIV int rigol_ds_receive(int fd, int revents, void *cb_data) else for (i = 0; i < len; i++) devc->data[i] = (128 - devc->buffer[i]) * vdiv - offset; - sr_analog_init(&analog, &encoding, &meaning, &spec, 0); + float vdivlog = log10f(vdiv); + int digits = -(int)vdivlog + (vdivlog < 0.0); + sr_analog_init(&analog, &encoding, &meaning, &spec, digits); analog.meaning->channels = g_slist_append(NULL, ch); analog.num_samples = len; analog.data = devc->data; @@ -769,6 +784,7 @@ SR_PRIV int rigol_ds_receive(int fd, int revents, void *cb_data) SR_PRIV int rigol_ds_get_dev_cfg(const struct sr_dev_inst *sdi) { struct dev_context *devc; + struct sr_channel *ch; char *cmd; unsigned int i; int res; @@ -782,6 +798,8 @@ SR_PRIV int rigol_ds_get_dev_cfg(const struct sr_dev_inst *sdi) g_free(cmd); if (res != SR_OK) return SR_ERR; + ch = g_slist_nth_data(sdi->channels, i); + ch->enabled = devc->analog_channels[i]; } sr_dbg("Current analog channel state:"); for (i = 0; i < devc->model->analog_channels; i++) @@ -790,7 +808,7 @@ SR_PRIV int rigol_ds_get_dev_cfg(const struct sr_dev_inst *sdi) /* Digital channel state. */ if (devc->model->has_digital) { if (sr_scpi_get_bool(sdi->conn, - devc->model->series->protocol >= PROTOCOL_V4 ? + devc->model->series->protocol >= PROTOCOL_V3 ? ":LA:STAT?" : ":LA:DISP?", &devc->la_enabled) != SR_OK) return SR_ERR; @@ -798,12 +816,14 @@ SR_PRIV int rigol_ds_get_dev_cfg(const struct sr_dev_inst *sdi) devc->la_enabled ? "enabled" : "disabled"); for (i = 0; i < ARRAY_SIZE(devc->digital_channels); i++) { cmd = g_strdup_printf( - devc->model->series->protocol >= PROTOCOL_V4 ? + devc->model->series->protocol >= PROTOCOL_V3 ? ":LA:DIG%d:DISP?" : ":DIG%d:TURN?", i); res = sr_scpi_get_bool(sdi->conn, cmd, &devc->digital_channels[i]); g_free(cmd); if (res != SR_OK) return SR_ERR; + ch = g_slist_nth_data(sdi->channels, i + devc->model->analog_channels); + ch->enabled = devc->digital_channels[i]; sr_dbg("D%d: %s", i, devc->digital_channels[i] ? "on" : "off"); } }