"CH2",
"EXT",
"AC Line",
+ "D0",
+ "D1",
+ "D2",
+ "D3",
+ "D4",
+ "D5",
+ "D6",
+ "D7",
+ "D8",
+ "D9",
+ "D10",
+ "D11",
+ "D12",
+ "D13",
+ "D14",
+ "D15",
};
static const char *coupling[] = {
gchar **tokens;
const char *manufacturer, *model, *version;
gboolean matched = FALSE;
+ gboolean has_digital = FALSE;
char buf[256];
+ gchar *channel_name;
(void)options;
for (i = 0; i < ARRAY_SIZE(supported_models); i++) {
if (!strcmp(model, supported_models[i])) {
matched = 1;
+ has_digital = g_str_has_suffix(model, "D");
break;
}
}
}
devc->limit_frames = 0;
devc->device = device;
+ devc->has_digital = has_digital;
sdi->priv = devc;
sdi->driver = di;
for (i = 0; i < 2; i++) {
- if (!(probe = sr_probe_new(0, SR_PROBE_ANALOG, TRUE,
+ if (!(probe = sr_probe_new(i, SR_PROBE_ANALOG, TRUE,
i == 0 ? "CH1" : "CH2")))
return NULL;
sdi->probes = g_slist_append(sdi->probes, probe);
}
+ if (devc->has_digital) {
+ for (i = 0; i < 16; i++) {
+ if (!(channel_name = g_strdup_printf("D%d", i)))
+ return NULL;
+ probe = sr_probe_new(i, SR_PROBE_LOGIC, TRUE, channel_name);
+ g_free(channel_name);
+ if (!probe)
+ return NULL;
+ sdi->probes = g_slist_append(sdi->probes, probe);
+ }
+ }
+
drvc->instances = g_slist_append(drvc->instances, sdi);
devices = g_slist_append(devices, sdi);
}
GVariant *tuple, *rational[2];
GVariantBuilder gvb;
unsigned int i;
-
- (void)sdi;
+ struct dev_context *devc = sdi->priv;
switch (key) {
case SR_CONF_DEVICE_OPTIONS:
break;
case SR_CONF_TRIGGER_SOURCE:
*data = g_variant_new_strv(trigger_sources,
- ARRAY_SIZE(trigger_sources));
+ devc->has_digital ? ARRAY_SIZE(trigger_sources) : 4);
break;
default:
return SR_ERR_ARG;
struct dev_context *devc;
struct sr_probe *probe;
GSList *l;
- int probenum;
char cmd[256];
(void)cb_data;
for (l = sdi->probes; l; l = l->next) {
probe = l->data;
- probenum = probe->name[2] == '1' ? 0 : 1;
- if (probe->enabled)
- devc->enabled_probes = g_slist_append(devc->enabled_probes, probe);
-
- if (probe->enabled != devc->channels[probenum]) {
- /* Enabled channel is currently disabled, or vice versa. */
- sprintf(cmd, ":CHAN%d:DISP %s", probenum + 1,
- probe->enabled ? "ON" : "OFF");
- if (rigol_ds1xx2_send(devc, cmd) != SR_OK)
- return SR_ERR;
+ sr_dbg("handling probe %s", probe->name);
+ if (probe->type == SR_PROBE_ANALOG) {
+ if (probe->enabled)
+ devc->enabled_analog_probes = g_slist_append(
+ 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 (rigol_ds1xx2_send(devc, cmd) != SR_OK)
+ return SR_ERR;
+ }
+ } else if (probe->type == SR_PROBE_LOGIC) {
+ if (probe->enabled)
+ devc->enabled_digital_probes = g_slist_append(
+ 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 (rigol_ds1xx2_send(devc, cmd) != SR_OK)
+ return SR_ERR;
+ }
}
}
- if (!devc->enabled_probes)
+ if (!devc->enabled_analog_probes && !devc->enabled_digital_probes)
return SR_ERR;
sr_source_add(devc->fd, G_IO_IN, 50, rigol_ds1xx2_receive, (void *)sdi);
std_session_send_df_header(cb_data, DRIVER_LOG_DOMAIN);
/* Fetch the first frame. */
- devc->channel_frame = devc->enabled_probes->data;
- if (rigol_ds1xx2_send(devc, ":WAV:DATA? CHAN%c",
- devc->channel_frame->name[2]) != SR_OK)
- return SR_ERR;
+ if (devc->enabled_analog_probes) {
+ devc->channel_frame = devc->enabled_analog_probes->data;
+ if (rigol_ds1xx2_send(devc, ":WAV:DATA? CHAN%d",
+ devc->channel_frame->index + 1) != SR_OK)
+ return SR_ERR;
+ } else {
+ devc->channel_frame = devc->enabled_digital_probes->data;
+ if (rigol_ds1xx2_send(devc, ":WAV:DATA? DIG") != SR_OK)
+ return SR_ERR;
+ }
devc->num_frame_bytes = 0;
return SR_ERR;
}
- g_slist_free(devc->enabled_probes);
- devc->enabled_probes = NULL;
+ g_slist_free(devc->enabled_analog_probes);
+ g_slist_free(devc->enabled_digital_probes);
+ devc->enabled_analog_probes = NULL;
+ devc->enabled_digital_probes = NULL;
sr_source_remove(devc->fd);
return SR_OK;
struct dev_context *devc;
struct sr_datafeed_packet packet;
struct sr_datafeed_analog analog;
- unsigned char buf[WAVEFORM_SIZE];
+ struct sr_datafeed_logic logic;
+ unsigned char buf[DIGITAL_WAVEFORM_SIZE];
double vdiv, offset;
- float data[WAVEFORM_SIZE];
- int probenum, len, i;
+ float data[ANALOG_WAVEFORM_SIZE];
+ int len, i, waveform_size;
+ struct sr_probe *probe;
if (!(sdi = cb_data))
return TRUE;
return TRUE;
if (revents == G_IO_IN) {
- len = read(fd, buf, WAVEFORM_SIZE - devc->num_frame_bytes);
+ probe = devc->channel_frame;
+ waveform_size = probe->type == SR_PROBE_ANALOG ?
+ ANALOG_WAVEFORM_SIZE : DIGITAL_WAVEFORM_SIZE;
+ len = read(fd, buf, waveform_size - devc->num_frame_bytes);
sr_dbg("Received %d bytes.", len);
if (len == -1)
return TRUE;
sr_session_send(sdi, &packet);
}
- probenum = devc->channel_frame->name[2] == '1' ? 0 : 1;
- for (i = 0; i < len; i++) {
- vdiv = devc->vdiv[probenum];
- offset = devc->vert_offset[probenum];
- data[i] = vdiv / 25.6 * (128 - buf[i]) - offset;
- }
- analog.probes = g_slist_append(NULL, devc->channel_frame);
- analog.num_samples = len;
- analog.data = data;
- analog.mq = SR_MQ_VOLTAGE;
- analog.unit = SR_UNIT_VOLT;
- analog.mqflags = 0;
- packet.type = SR_DF_ANALOG;
- packet.payload = &analog;
- sr_session_send(cb_data, &packet);
- g_slist_free(analog.probes);
-
- devc->num_frame_bytes += len;
-
- if (devc->num_frame_bytes != WAVEFORM_SIZE) {
- /* Don't have the whole frame yet. */
- return TRUE;
+ if (probe->type == SR_PROBE_ANALOG) {
+ for (i = 0; i < len; i++) {
+ vdiv = devc->vdiv[probe->index];
+ offset = devc->vert_offset[probe->index];
+ data[i] = vdiv / 25.6 * (128 - buf[i]) - offset;
+ }
+ analog.probes = g_slist_append(NULL, probe);
+ analog.num_samples = len;
+ analog.data = data;
+ analog.mq = SR_MQ_VOLTAGE;
+ analog.unit = SR_UNIT_VOLT;
+ analog.mqflags = 0;
+ packet.type = SR_DF_ANALOG;
+ packet.payload = &analog;
+ sr_session_send(cb_data, &packet);
+ g_slist_free(analog.probes);
+
+ if (len != ANALOG_WAVEFORM_SIZE)
+ /* Don't have the whole frame yet. */
+ return TRUE;
+ } else {
+ logic.length = len - 10;
+ logic.unitsize = 2;
+ logic.data = buf + 10;
+ packet.type = SR_DF_LOGIC;
+ packet.payload = &logic;
+ sr_session_send(cb_data, &packet);
+
+ if (len != DIGITAL_WAVEFORM_SIZE)
+ /* Don't have the whole frame yet. */
+ return TRUE;
}
/* End of the frame. */
sr_session_send(sdi, &packet);
devc->num_frame_bytes = 0;
- if (devc->channel_frame == devc->enabled_probes->data
- && devc->enabled_probes->next != NULL) {
- /* We got the frame for the first channel, but
- * there's a second channel. */
- devc->channel_frame = devc->enabled_probes->next->data;
+ if (devc->enabled_analog_probes
+ && devc->channel_frame == devc->enabled_analog_probes->data
+ && devc->enabled_analog_probes->next != NULL) {
+ /* We got the frame for the first analog channel, but
+ * there's a second analog channel. */
+ devc->channel_frame = devc->enabled_analog_probes->next->data;
rigol_ds1xx2_send(devc, ":WAV:DATA? CHAN%c",
devc->channel_frame->name[2]);
} else {
- /* Done with both channels in this frame. */
- if (++devc->num_frames == devc->limit_frames) {
+ /* Done with both analog channels in this frame. */
+ if (devc->enabled_digital_probes
+ && devc->channel_frame != devc->enabled_digital_probes->data) {
+ /* Now we need to get the digital data. */
+ devc->channel_frame = devc->enabled_digital_probes->data;
+ rigol_ds1xx2_send(devc, ":WAV:DATA? DIG");
+ } else if (++devc->num_frames == devc->limit_frames) {
+ /* End of last frame. */
sdi->driver->dev_acquisition_stop(sdi, cb_data);
} else {
- /* Get the next frame, starting with the first channel. */
- devc->channel_frame = devc->enabled_probes->data;
- rigol_ds1xx2_send(devc, ":WAV:DATA? CHAN%c",
- devc->channel_frame->name[2]);
+ /* Get the next frame, starting with the first analog channel. */
+ if (devc->enabled_analog_probes) {
+ devc->channel_frame = devc->enabled_analog_probes->data;
+ rigol_ds1xx2_send(devc, ":WAV:DATA? CHAN%c",
+ devc->channel_frame->name[2]);
+ } else {
+ devc->channel_frame = devc->enabled_digital_probes->data;
+ rigol_ds1xx2_send(devc, ":WAV:DATA? DIG");
+ }
}
}
}
SR_PRIV int rigol_ds1xx2_get_dev_cfg(const struct sr_dev_inst *sdi)
{
struct dev_context *devc;
- char *t_s;
+ char *t_s, *cmd;
+ int i, res;
devc = sdi->priv;
- /* Channel state. */
+ /* Analog channel state. */
if (get_cfg_string(sdi, ":CHAN1:DISP?", &t_s) != SR_OK)
return SR_ERR;
- devc->channels[0] = !strcmp(t_s, "ON") ? TRUE : FALSE;
+ devc->analog_channels[0] = !strcmp(t_s, "ON") ? TRUE : FALSE;
g_free(t_s);
if (get_cfg_string(sdi, ":CHAN2:DISP?", &t_s) != SR_OK)
return SR_ERR;
- devc->channels[1] = !strcmp(t_s, "ON") ? TRUE : FALSE;
+ devc->analog_channels[1] = !strcmp(t_s, "ON") ? TRUE : FALSE;
g_free(t_s);
- sr_dbg("Current channel state CH1 %s CH2 %s",
- devc->channels[0] ? "on" : "off",
- devc->channels[1] ? "on" : "off");
+ sr_dbg("Current analog channel state CH1 %s CH2 %s",
+ devc->analog_channels[0] ? "on" : "off",
+ devc->analog_channels[1] ? "on" : "off");
+
+ /* Digital channel state. */
+ if (devc->has_digital) {
+ sr_dbg("Current digital channel state:");
+ for (i = 0; i < 16; i++) {
+ cmd = g_strdup_printf(":DIG%d:TURN?", i);
+ res = get_cfg_string(sdi, cmd, &t_s);
+ g_free(cmd);
+ if (res != SR_OK)
+ return SR_ERR;
+ devc->digital_channels[i] = !strcmp(t_s, "ON") ? TRUE : FALSE;
+ g_free(t_s);
+ sr_dbg("D%d: %s", i, devc->digital_channels[i] ? "on" : "off");
+ }
+ }
/* Timebase. */
if (get_cfg_float(sdi, ":TIM:SCAL?", &devc->timebase) != SR_OK)