0,
};
-static const char *probe_names[] = {
- "CH1", "CH2",
- NULL,
-};
-
static const struct sr_rational timebases[] = {
/* nanoseconds */
{ 2, 1000000000 },
NULL,
};
+static const char *supported_models[] = {
+ "DS1052E",
+ "DS1102E",
+ "DS1052D",
+ "DS1102D"
+};
+
SR_PRIV struct sr_dev_driver rigol_ds1xx2_driver_info;
static struct sr_dev_driver *di = &rigol_ds1xx2_driver_info;
if (!(devc = sdi->priv))
continue;
+ g_free(devc->device);
close(devc->fd);
sr_dev_inst_free(sdi);
struct dev_context *devc;
struct sr_probe *probe;
GSList *devices;
- int i;
+ GDir *dir;
+ const gchar *dev_name;
+ const gchar *dev_dir = "/dev/";
+ const gchar *prefix = "usbtmc";
+ gchar *device;
+ const gchar *idn_query = "*IDN?";
+ int len, num_tokens, fd, i;
+ const gchar *delimiter = ",";
+ gchar **tokens;
+ const char *manufacturer, *model, *version;
+ int num_models;
+ gboolean matched = FALSE;
+ char buf[256];
(void)options;
drvc = di->priv;
drvc->instances = NULL;
- if (!(sdi = sr_dev_inst_new(0, SR_ST_ACTIVE, "Rigol", "DS1xx2", NULL)))
- return NULL;
- if (!(devc = g_try_malloc0(sizeof(struct dev_context))))
+ dir = g_dir_open("/sys/class/usb/", 0, NULL);
+
+ if (dir == NULL)
return NULL;
- sdi->priv = devc;
- sdi->driver = di;
+ while ((dev_name = g_dir_read_name(dir)) != NULL) {
+ if (strncmp(dev_name, prefix, strlen(prefix)))
+ continue;
+
+ device = g_strconcat(dev_dir, dev_name, NULL);
+
+ fd = open(device, O_RDWR);
+ len = write(fd, idn_query, strlen(idn_query));
+ len = read(fd, buf, sizeof(buf));
+ close(fd);
+ if (len == 0) {
+ g_free(device);
+ return NULL;
+ }
+
+ buf[len] = 0;
+ tokens = g_strsplit(buf, delimiter, 0);
+ close(fd);
+ sr_dbg("response: %s %d [%s]", device, len, buf);
+
+ for (num_tokens = 0; tokens[num_tokens] != NULL; num_tokens++);
+
+ if (num_tokens < 4) {
+ g_strfreev(tokens);
+ g_free(device);
+ return NULL;
+ }
+
+ manufacturer = tokens[0];
+ model = tokens[1];
+ version = tokens[3];
+
+ if (strcmp(manufacturer, "Rigol Technologies")) {
+ g_strfreev(tokens);
+ g_free(device);
+ return NULL;
+ }
+
+ num_models = sizeof(supported_models) / sizeof(supported_models[0]);
+
+ for (i = 0; i < num_models; i++) {
+ if (!strcmp(model, supported_models[i])) {
+ matched = 1;
+ break;
+ }
+ }
- for (i = 0; i < 2; i++)
- {
- if (!(probe = sr_probe_new(0, SR_PROBE_ANALOG, TRUE, i == 0 ? "CH1" : "CH2")))
+ if (!matched || !(sdi = sr_dev_inst_new(0, SR_ST_ACTIVE,
+ manufacturer, model, version))) {
+ g_strfreev(tokens);
+ g_free(device);
return NULL;
- sdi->probes = g_slist_append(sdi->probes, probe);
+ }
+
+ g_strfreev(tokens);
+
+ if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) {
+ sr_err("Device context malloc failed.");
+ g_free(device);
+ return NULL;
+ }
+
+ devc->device = device;
+
+ sdi->priv = devc;
+ sdi->driver = di;
+
+ for (i = 0; i < 2; i++) {
+ if (!(probe = sr_probe_new(0, SR_PROBE_ANALOG, TRUE,
+ i == 0 ? "CH1" : "CH2")))
+ return NULL;
+ sdi->probes = g_slist_append(sdi->probes, probe);
+ }
+
+ drvc->instances = g_slist_append(drvc->instances, sdi);
+ devices = g_slist_append(devices, sdi);
}
- drvc->instances = g_slist_append(drvc->instances, sdi);
- devices = g_slist_append(devices, sdi);
+
+ g_dir_close(dir);
return devices;
}
static int hw_dev_open(struct sr_dev_inst *sdi)
{
- int fd = open("/dev/usbtmc1", O_RDWR);
+ struct dev_context *devc;
+ int fd;
+
+ devc = sdi->priv;
- if (fd == -1)
+ if ((fd = open(devc->device, O_RDWR)) == -1)
return SR_ERR;
- struct dev_context *devc = sdi->priv;
devc->fd = fd;
devc->scale = 1;
static int hw_dev_close(struct sr_dev_inst *sdi)
{
- struct dev_context *devc = sdi->priv;
+ struct dev_context *devc;
+
+ devc = sdi->priv;
close(devc->fd);
case SR_DI_HWCAPS:
*data = hwcaps;
break;
- case SR_DI_NUM_PROBES:
- *data = GINT_TO_POINTER(NUM_PROBES);
- break;
- case SR_DI_PROBE_NAMES:
- *data = probe_names;
- break;
case SR_DI_TIMEBASES:
*data = timebases;
break;
*data = coupling;
break;
default:
- sr_err("Unknown info_id: %d.", info_id);
return SR_ERR_ARG;
}
static int hw_dev_config_set(const struct sr_dev_inst *sdi, int hwcap,
const void *value)
{
- struct dev_context *devc = sdi->priv;
+ struct dev_context *devc;
uint64_t tmp_u64;
float tmp_float;
struct sr_rational tmp_rat;
int ret, i, j;
char *channel;
+ devc = sdi->priv;
+
if (sdi->status != SR_ST_ACTIVE) {
sr_err("Device inactive, can't set config options.");
return SR_ERR;
ret = SR_OK;
switch (hwcap) {
- case SR_HWCAP_LIMIT_FRAMES:
+ case SR_HWCAP_LIMIT_FRAMES:
devc->limit_frames = *(const uint64_t *)value;
break;
case SR_HWCAP_TRIGGER_SLOPE:
tmp_u64 = *(const int *)value;
- rigol_ds1xx2_send_data(devc->fd, ":TRIG:EDGE:SLOP %s\n", tmp_u64 ? "POS" : "NEG");
+ rigol_ds1xx2_send_data(devc->fd, ":TRIG:EDGE:SLOP %s\n",
+ tmp_u64 ? "POS" : "NEG");
break;
case SR_HWCAP_HORIZ_TRIGGERPOS:
tmp_float = *(const float *)value;
break;
case SR_HWCAP_TIMEBASE:
tmp_rat = *(const struct sr_rational *)value;
- rigol_ds1xx2_send_data(devc->fd, ":TIM:SCAL %.9f\n", (float) tmp_rat.p / tmp_rat.q);
+ rigol_ds1xx2_send_data(devc->fd, ":TIM:SCAL %.9f\n",
+ (float)tmp_rat.p / tmp_rat.q);
break;
case SR_HWCAP_TRIGGER_SOURCE:
if (!strcmp(value, "CH1"))
channel = "EXT";
else if (!strcmp(value, "AC Line"))
channel = "ACL";
- else
- {
+ else {
ret = SR_ERR_ARG;
break;
}
for (i = 0; vdivs[i].p && vdivs[i].q; i++) {
if (vdivs[i].p == tmp_rat.p
&& vdivs[i].q == tmp_rat.q) {
- devc->scale = (float) tmp_rat.p / tmp_rat.q;
+ devc->scale = (float)tmp_rat.p / tmp_rat.q;
for (j = 0; j < 2; j++)
- rigol_ds1xx2_send_data(devc->fd, ":CHAN%d:SCAL %.3f\n", j, devc->scale);
+ rigol_ds1xx2_send_data(devc->fd,
+ ":CHAN%d:SCAL %.3f\n", j, devc->scale);
break;
}
}
for (i = 0; coupling[i]; i++) {
if (!strcmp(value, coupling[i])) {
for (j = 0; j < 2; j++)
- rigol_ds1xx2_send_data(devc->fd, ":CHAN%d:COUP %s\n", j, coupling[i]);
+ rigol_ds1xx2_send_data(devc->fd,
+ ":CHAN%d:COUP %s\n", j, coupling[i]);
break;
}
}
default:
sr_err("Unknown hardware capability: %d.", hwcap);
ret = SR_ERR_ARG;
+ break;
}
return ret;
static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
void *cb_data)
{
- struct dev_context *devc = sdi->priv;
+ struct dev_context *devc;
struct sr_datafeed_packet packet;
struct sr_datafeed_header header;
struct sr_datafeed_meta_analog meta;
char buf[256];
int len;
+
(void)cb_data;
+ devc = sdi->priv;
+
devc->num_frames = 0;
sr_source_add(devc->fd, G_IO_IN, 50, rigol_ds1xx2_receive_data, (void *)sdi);
len = read(devc->fd, buf, sizeof(buf));
buf[len] = 0;
devc->scale = atof(buf);
- sr_dbg("scale is %.3f", devc->scale);
+ sr_dbg("Scale is %.3f.", devc->scale);
rigol_ds1xx2_send_data(devc->fd, ":CHAN1:OFFS?\n");
len = read(devc->fd, buf, sizeof(buf));
buf[len] = 0;
devc->offset = atof(buf);
- sr_dbg("offset is %.6f", devc->offset);
+ sr_dbg("Offset is %.6f.", devc->offset);
rigol_ds1xx2_send_data(devc->fd, ":WAV:DATA?\n");
return SR_OK;
static int hw_dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
{
- struct dev_context *devc = sdi->priv;
+ struct dev_context *devc;
+
(void)cb_data;
+ devc = sdi->priv;
+
if (sdi->status != SR_ST_ACTIVE) {
sr_err("Device inactive, can't stop acquisition.");
return SR_ERR;