SR_CONF_LIMIT_SAMPLES | SR_CONF_GET | SR_CONF_SET,
SR_CONF_LIMIT_MSEC | SR_CONF_GET | SR_CONF_SET,
SR_CONF_MEASURED_QUANTITY | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
+ SR_CONF_RANGE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
};
static const struct {
enum sr_mqflag mqflag;
} mqopts[] = {
{SR_MQ_VOLTAGE, SR_MQFLAG_DC},
- {SR_MQ_VOLTAGE, SR_MQFLAG_DC | SR_MQFLAG_AUTORANGE},
- {SR_MQ_VOLTAGE, SR_MQFLAG_AC | SR_MQFLAG_RMS},
- {SR_MQ_VOLTAGE, SR_MQFLAG_AC | SR_MQFLAG_RMS | SR_MQFLAG_AUTORANGE},
+ {SR_MQ_VOLTAGE, SR_MQFLAG_AC},
{SR_MQ_CURRENT, SR_MQFLAG_DC},
- {SR_MQ_CURRENT, SR_MQFLAG_DC | SR_MQFLAG_AUTORANGE},
- {SR_MQ_CURRENT, SR_MQFLAG_AC | SR_MQFLAG_RMS},
- {SR_MQ_CURRENT, SR_MQFLAG_AC | SR_MQFLAG_RMS | SR_MQFLAG_AUTORANGE},
+ {SR_MQ_CURRENT, SR_MQFLAG_AC},
{SR_MQ_RESISTANCE, 0},
- {SR_MQ_RESISTANCE, 0 | SR_MQFLAG_AUTORANGE},
{SR_MQ_RESISTANCE, SR_MQFLAG_FOUR_WIRE},
- {SR_MQ_RESISTANCE, SR_MQFLAG_FOUR_WIRE | SR_MQFLAG_AUTORANGE},
+};
+
+
+static const struct {
+ enum sr_mq mq;
+ enum sr_mqflag mqflag;
+ int range_exp;
+ const char *range_str;
+} rangeopts[] = {
+ /* -99 is a dummy exponent for auto ranging. */
+ {SR_MQ_VOLTAGE, SR_MQFLAG_DC, -99, "Auto"},
+ {SR_MQ_VOLTAGE, SR_MQFLAG_DC, -2, "30mV"},
+ {SR_MQ_VOLTAGE, SR_MQFLAG_DC, -1, "300mV"},
+ {SR_MQ_VOLTAGE, SR_MQFLAG_DC, 0, "3V"},
+ {SR_MQ_VOLTAGE, SR_MQFLAG_DC, 1, "30V"},
+ {SR_MQ_VOLTAGE, SR_MQFLAG_DC, 2, "300V"},
+ /* -99 is a dummy exponent for auto ranging. */
+ {SR_MQ_VOLTAGE, SR_MQFLAG_AC, -99, "Auto"},
+ {SR_MQ_VOLTAGE, SR_MQFLAG_AC, -1, "300mV"},
+ {SR_MQ_VOLTAGE, SR_MQFLAG_AC, 0, "3V"},
+ {SR_MQ_VOLTAGE, SR_MQFLAG_AC, 1, "30V"},
+ {SR_MQ_VOLTAGE, SR_MQFLAG_AC, 2, "300V"},
+ /* -99 is a dummy exponent for auto ranging. */
+ {SR_MQ_CURRENT, SR_MQFLAG_DC, -99, "Auto"},
+ {SR_MQ_CURRENT, SR_MQFLAG_DC, -1, "300mV"},
+ {SR_MQ_CURRENT, SR_MQFLAG_DC, 0, "3V"},
+ /* -99 is a dummy exponent for auto ranging. */
+ {SR_MQ_CURRENT, SR_MQFLAG_AC, -99, "Auto"},
+ {SR_MQ_CURRENT, SR_MQFLAG_AC, -1, "300mV"},
+ {SR_MQ_CURRENT, SR_MQFLAG_AC, 0, "3V"},
+ /* -99 is a dummy exponent for auto ranging. */
+ {SR_MQ_RESISTANCE, 0, -99, "Auto"},
+ {SR_MQ_RESISTANCE, 0, 1, "30"},
+ {SR_MQ_RESISTANCE, 0, 2, "300"},
+ {SR_MQ_RESISTANCE, 0, 3, "3k"},
+ {SR_MQ_RESISTANCE, 0, 4, "30k"},
+ {SR_MQ_RESISTANCE, 0, 5, "300k"},
+ {SR_MQ_RESISTANCE, 0, 6, "3M"},
+ {SR_MQ_RESISTANCE, 0, 7, "30M"},
+ /* -99 is a dummy exponent for auto ranging. */
+ {SR_MQ_RESISTANCE, SR_MQFLAG_FOUR_WIRE, -99, "Auto"},
+ {SR_MQ_RESISTANCE, SR_MQFLAG_FOUR_WIRE, 1, "30R"},
+ {SR_MQ_RESISTANCE, SR_MQFLAG_FOUR_WIRE, 2, "300R"},
+ {SR_MQ_RESISTANCE, SR_MQFLAG_FOUR_WIRE, 3, "3kR"},
+ {SR_MQ_RESISTANCE, SR_MQFLAG_FOUR_WIRE, 4, "30kR"},
+ {SR_MQ_RESISTANCE, SR_MQFLAG_FOUR_WIRE, 5, "300kR"},
+ {SR_MQ_RESISTANCE, SR_MQFLAG_FOUR_WIRE, 6, "3MR"},
+ {SR_MQ_RESISTANCE, SR_MQFLAG_FOUR_WIRE, 7, "30MR"},
};
static struct sr_dev_driver hp_3478a_driver_info;
struct dev_context *devc;
int ret;
GVariant *arr[2];
+ unsigned int i;
+ const char *range_str;
(void)cg;
arr[1] = g_variant_new_uint64(devc->measurement_mq_flags);
*data = g_variant_new_tuple(arr, 2);
break;
+ case SR_CONF_RANGE:
+ ret = hp_3478a_get_status_bytes(sdi);
+ if (ret != SR_OK)
+ return ret;
+ range_str = "Auto";
+ for (i = 0; i < ARRAY_SIZE(rangeopts); i++) {
+ if (rangeopts[i].mq == devc->measurement_mq &&
+ rangeopts[i].mqflag == devc->measurement_mq_flags &&
+ rangeopts[i].range_exp == devc->range_exp) {
+ range_str = rangeopts[i].range_str;
+ break;
+ }
+ }
+ *data = g_variant_new_string(range_str);
+ break;
default:
return SR_ERR_NA;
}
enum sr_mq mq;
enum sr_mqflag mq_flags;
GVariant *tuple_child;
+ unsigned int i;
+ const char *range_str;
(void)cg;
mq_flags = g_variant_get_uint64(tuple_child);
g_variant_unref(tuple_child);
return hp_3478a_set_mq(sdi, mq, mq_flags);
+ case SR_CONF_RANGE:
+ range_str = g_variant_get_string(data, NULL);
+ for (i = 0; i < ARRAY_SIZE(rangeopts); i++) {
+ if (rangeopts[i].mq == devc->measurement_mq &&
+ rangeopts[i].mqflag == devc->measurement_mq_flags &&
+ g_strcmp0(rangeopts[i].range_str, range_str) == 0) {
+ return hp_3478a_set_range(sdi, rangeopts[i].range_exp);
+ }
+ }
+ return SR_ERR_NA;
default:
return SR_ERR_NA;
}
static int config_list(uint32_t key, GVariant **data,
const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
{
+ struct dev_context *devc;
+ int ret;
unsigned int i;
GVariant *gvar, *arr[2];
GVariantBuilder gvb;
+ devc = sdi->priv;
+
switch (key) {
case SR_CONF_SCAN_OPTIONS:
case SR_CONF_DEVICE_OPTIONS:
}
*data = g_variant_builder_end(&gvb);
break;
+ case SR_CONF_RANGE:
+ ret = hp_3478a_get_status_bytes(sdi);
+ if (ret != SR_OK)
+ return ret;
+ g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY);
+ for (i = 0; i < ARRAY_SIZE(rangeopts); i++) {
+ if (rangeopts[i].mq == devc->measurement_mq &&
+ rangeopts[i].mqflag == devc->measurement_mq_flags) {
+ g_variant_builder_add(&gvb, "s", rangeopts[i].range_str);
+ }
+ }
+ *data = g_variant_builder_end(&gvb);
+ break;
default:
return SR_ERR_NA;
}
return SR_ERR_NA;
}
+SR_PRIV int hp_3478a_set_range(const struct sr_dev_inst *sdi, int range_exp)
+{
+ int ret;
+ struct sr_scpi_dev_inst *scpi = sdi->conn;
+ struct dev_context *devc = sdi->priv;
+
+ /* No need to send command if we're not changing the range. */
+ if (devc->range_exp == range_exp)
+ return SR_OK;
+
+ /* -99 is a dummy exponent for auto ranging. */
+ if (range_exp == -99)
+ ret = sr_scpi_send(scpi, "RA");
+ else
+ ret = sr_scpi_send(scpi, "R%i", range_exp);
+ if (ret != SR_OK)
+ return ret;
+
+ return hp_3478a_get_status_bytes(sdi);
+}
+
static int parse_range_vdc(struct dev_context *devc, uint8_t range_byte)
{
- if ((range_byte & SB1_RANGE_BLOCK) == RANGE_VDC_30MV)
+ if ((range_byte & SB1_RANGE_BLOCK) == RANGE_VDC_30MV) {
+ devc->range_exp = -2;
devc->enc_digits = devc->spec_digits - 2;
- else if ((range_byte & SB1_RANGE_BLOCK) == RANGE_VDC_300MV)
+ } else if ((range_byte & SB1_RANGE_BLOCK) == RANGE_VDC_300MV) {
+ devc->range_exp = -1;
devc->enc_digits = devc->spec_digits - 3;
- else if ((range_byte & SB1_RANGE_BLOCK) == RANGE_VDC_3V)
+ } else if ((range_byte & SB1_RANGE_BLOCK) == RANGE_VDC_3V) {
+ devc->range_exp = 0;
devc->enc_digits = devc->spec_digits - 1;
- else if ((range_byte & SB1_RANGE_BLOCK) == RANGE_VDC_30V)
+ } else if ((range_byte & SB1_RANGE_BLOCK) == RANGE_VDC_30V) {
+ devc->range_exp = 1;
devc->enc_digits = devc->spec_digits - 2;
- else if ((range_byte & SB1_RANGE_BLOCK) == RANGE_VDC_300V)
+ } else if ((range_byte & SB1_RANGE_BLOCK) == RANGE_VDC_300V) {
+ devc->range_exp = 2;
devc->enc_digits = devc->spec_digits - 3;
- else
+ } else
return SR_ERR_DATA;
return SR_OK;
static int parse_range_vac(struct dev_context *devc, uint8_t range_byte)
{
- if ((range_byte & SB1_RANGE_BLOCK) == RANGE_VAC_300MV)
+ if ((range_byte & SB1_RANGE_BLOCK) == RANGE_VAC_300MV) {
+ devc->range_exp = -1;
devc->enc_digits = devc->spec_digits - 3;
- else if ((range_byte & SB1_RANGE_BLOCK) == RANGE_VAC_3V)
+ } else if ((range_byte & SB1_RANGE_BLOCK) == RANGE_VAC_3V) {
+ devc->range_exp = 0;
devc->enc_digits = devc->spec_digits - 1;
- else if ((range_byte & SB1_RANGE_BLOCK) == RANGE_VAC_30V)
+ } else if ((range_byte & SB1_RANGE_BLOCK) == RANGE_VAC_30V) {
+ devc->range_exp = 1;
devc->enc_digits = devc->spec_digits - 2;
- else if ((range_byte & SB1_RANGE_BLOCK) == RANGE_VAC_300V)
+ } else if ((range_byte & SB1_RANGE_BLOCK) == RANGE_VAC_300V) {
+ devc->range_exp = 2;
devc->enc_digits = devc->spec_digits - 3;
- else
+ } else
return SR_ERR_DATA;
return SR_OK;
static int parse_range_a(struct dev_context *devc, uint8_t range_byte)
{
- if ((range_byte & SB1_RANGE_BLOCK) == RANGE_A_300MA)
+ if ((range_byte & SB1_RANGE_BLOCK) == RANGE_A_300MA) {
+ devc->range_exp = -1;
devc->enc_digits = devc->spec_digits - 3;
- else if ((range_byte & SB1_RANGE_BLOCK) == RANGE_A_3A)
+ } else if ((range_byte & SB1_RANGE_BLOCK) == RANGE_A_3A) {
+ devc->range_exp = 0;
devc->enc_digits = devc->spec_digits - 1;
- else
+ } else
return SR_ERR_DATA;
return SR_OK;
static int parse_range_ohm(struct dev_context *devc, uint8_t range_byte)
{
- if ((range_byte & SB1_RANGE_BLOCK) == RANGE_OHM_30R)
+ if ((range_byte & SB1_RANGE_BLOCK) == RANGE_OHM_30R) {
+ devc->range_exp = 1;
devc->enc_digits = devc->spec_digits - 2;
- else if ((range_byte & SB1_RANGE_BLOCK) == RANGE_OHM_300R)
+ } else if ((range_byte & SB1_RANGE_BLOCK) == RANGE_OHM_300R) {
+ devc->range_exp = 2;
devc->enc_digits = devc->spec_digits - 3;
- else if ((range_byte & SB1_RANGE_BLOCK) == RANGE_OHM_3KR)
+ } else if ((range_byte & SB1_RANGE_BLOCK) == RANGE_OHM_3KR) {
+ devc->range_exp = 3;
devc->enc_digits = devc->spec_digits - 1;
- else if ((range_byte & SB1_RANGE_BLOCK) == RANGE_OHM_30KR)
+ } else if ((range_byte & SB1_RANGE_BLOCK) == RANGE_OHM_30KR) {
+ devc->range_exp = 4;
devc->enc_digits = devc->spec_digits - 2;
- else if ((range_byte & SB1_RANGE_BLOCK) == RANGE_OHM_300KR)
+ } else if ((range_byte & SB1_RANGE_BLOCK) == RANGE_OHM_300KR) {
+ devc->range_exp = 5;
devc->enc_digits = devc->spec_digits - 3;
- else if ((range_byte & SB1_RANGE_BLOCK) == RANGE_OHM_3MR)
+ } else if ((range_byte & SB1_RANGE_BLOCK) == RANGE_OHM_3MR) {
+ devc->range_exp = 6;
devc->enc_digits = devc->spec_digits - 1;
- else if ((range_byte & SB1_RANGE_BLOCK) == RANGE_OHM_30MR)
+ } else if ((range_byte & SB1_RANGE_BLOCK) == RANGE_OHM_30MR) {
+ devc->range_exp = 7;
devc->enc_digits = devc->spec_digits - 2;
- else
+ } else
return SR_ERR_DATA;
return SR_OK;
/* Function + Range */
devc->measurement_mq_flags = 0;
+ devc->acquisition_mq_flags = 0;
if ((function_byte & SB1_FUNCTION_BLOCK) == FUNCTION_VDC) {
devc->measurement_mq = SR_MQ_VOLTAGE;
devc->measurement_mq_flags |= SR_MQFLAG_DC;
+ devc->acquisition_mq_flags |= SR_MQFLAG_DC;
devc->measurement_unit = SR_UNIT_VOLT;
parse_range_vdc(devc, function_byte);
} else if ((function_byte & SB1_FUNCTION_BLOCK) == FUNCTION_VAC) {
devc->measurement_mq = SR_MQ_VOLTAGE;
- devc->measurement_mq_flags |= SR_MQFLAG_AC | SR_MQFLAG_RMS;
+ devc->measurement_mq_flags |= SR_MQFLAG_AC;
+ devc->acquisition_mq_flags |= SR_MQFLAG_AC | SR_MQFLAG_RMS;
devc->measurement_unit = SR_UNIT_VOLT;
parse_range_vac(devc, function_byte);
} else if ((function_byte & SB1_FUNCTION_BLOCK) == FUNCTION_2WR) {
} else if ((function_byte & SB1_FUNCTION_BLOCK) == FUNCTION_4WR) {
devc->measurement_mq = SR_MQ_RESISTANCE;
devc->measurement_mq_flags |= SR_MQFLAG_FOUR_WIRE;
+ devc->acquisition_mq_flags |= SR_MQFLAG_FOUR_WIRE;
devc->measurement_unit = SR_UNIT_OHM;
parse_range_ohm(devc, function_byte);
} else if ((function_byte & SB1_FUNCTION_BLOCK) == FUNCTION_ADC) {
devc->measurement_mq = SR_MQ_CURRENT;
devc->measurement_mq_flags |= SR_MQFLAG_DC;
+ devc->acquisition_mq_flags |= SR_MQFLAG_DC;
devc->measurement_unit = SR_UNIT_AMPERE;
parse_range_a(devc, function_byte);
} else if ((function_byte & SB1_FUNCTION_BLOCK) == FUNCTION_AAC) {
devc->measurement_mq = SR_MQ_CURRENT;
- devc->measurement_mq_flags |= SR_MQFLAG_AC | SR_MQFLAG_RMS;
+ devc->measurement_mq_flags |= SR_MQFLAG_AC;
+ devc->acquisition_mq_flags |= SR_MQFLAG_AC | SR_MQFLAG_RMS;
devc->measurement_unit = SR_UNIT_AMPERE;
parse_range_a(devc, function_byte);
} else if ((function_byte & SB1_FUNCTION_BLOCK) == FUNCTION_EXR) {
devc->auto_zero = FALSE;
/* Auto-Range */
- if ((status_byte & STATUS_AUTO_RANGE) == STATUS_AUTO_RANGE)
- devc->measurement_mq_flags |= SR_MQFLAG_AUTORANGE;
- else
- devc->measurement_mq_flags &= ~SR_MQFLAG_AUTORANGE;
+ if ((status_byte & STATUS_AUTO_RANGE) == STATUS_AUTO_RANGE) {
+ devc->acquisition_mq_flags |= SR_MQFLAG_AUTORANGE;
+ devc->range_exp = -99;
+ } else
+ devc->acquisition_mq_flags &= ~SR_MQFLAG_AUTORANGE;
/* Internal trigger */
if ((status_byte & STATUS_INT_TRIGGER) == STATUS_INT_TRIGGER)
encoding.digits = devc->enc_digits;
meaning.mq = devc->measurement_mq;
- meaning.mqflags = devc->measurement_mq_flags;
+ meaning.mqflags = devc->acquisition_mq_flags;
meaning.unit = devc->measurement_unit;
meaning.channels = sdi->channels;