From: Frank Stettner Date: Tue, 17 Dec 2019 16:59:44 +0000 (+0100) Subject: hp-3478a: Add get/set/list of digits. X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=7812a5c802cc78c9ec5b6373e7e1884743d6857f;p=libsigrok.git hp-3478a: Add get/set/list of digits. --- diff --git a/src/hardware/hp-3478a/api.c b/src/hardware/hp-3478a/api.c index d4e40338..69c1d711 100644 --- a/src/hardware/hp-3478a/api.c +++ b/src/hardware/hp-3478a/api.c @@ -35,6 +35,7 @@ static const uint32_t devopts[] = { 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, + SR_CONF_DIGITS | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST, }; static const struct { @@ -49,7 +50,6 @@ static const struct { {SR_MQ_RESISTANCE, SR_MQFLAG_FOUR_WIRE}, }; - static const struct { enum sr_mq mq; enum sr_mqflag mqflag; @@ -97,6 +97,16 @@ static const struct { {SR_MQ_RESISTANCE, SR_MQFLAG_FOUR_WIRE, 7, "30MR"}, }; +/** Available digits as strings. */ +static const char *digits[] = { + "3.5", "4.5", "5.5", +}; + +/** Mapping between devc->spec_digits and digits string. */ +static const char *digits_map[] = { + "", "", "", "", "3.5", "4.5", "5.5", +}; + static struct sr_dev_driver hp_3478a_driver_info; static int create_front_channel(struct sr_dev_inst *sdi, int chan_idx) @@ -195,6 +205,12 @@ static int config_get(uint32_t key, GVariant **data, } *data = g_variant_new_string(range_str); break; + case SR_CONF_DIGITS: + ret = hp_3478a_get_status_bytes(sdi); + if (ret != SR_OK) + return ret; + *data = g_variant_new_string(digits_map[devc->spec_digits]); + break; default: return SR_ERR_NA; } @@ -211,6 +227,7 @@ static int config_set(uint32_t key, GVariant *data, GVariant *tuple_child; unsigned int i; const char *range_str; + const char *digits_str; (void)cg; @@ -237,6 +254,13 @@ static int config_set(uint32_t key, GVariant *data, } } return SR_ERR_NA; + case SR_CONF_DIGITS: + digits_str = g_variant_get_string(data, NULL); + for (i = 0; i < ARRAY_SIZE(rangeopts); i++) { + if (g_strcmp0(digits_map[i], digits_str) == 0) + return hp_3478a_set_digits(sdi, i); + } + return SR_ERR_NA; default: return SR_ERR_NA; } @@ -286,6 +310,9 @@ static int config_list(uint32_t key, GVariant **data, } *data = g_variant_builder_end(&gvb); break; + case SR_CONF_DIGITS: + *data = g_variant_new_strv(ARRAY_AND_SIZE(digits)); + break; default: return SR_ERR_NA; } @@ -308,7 +335,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) * NOTE: For faster readings, there are some things one can do: * - Turn off the display: sr_scpi_send(scpi, "D3SIGROK"). * - Set the line frequency to 60Hz via switch (back of the unit). - * - Set to 3.5 digits measurement (add config key SR_CONF_DIGITS). + * - Set to 3.5 digits measurement. */ /* Set to internal trigger. */ diff --git a/src/hardware/hp-3478a/protocol.c b/src/hardware/hp-3478a/protocol.c index da200e7a..74acd144 100644 --- a/src/hardware/hp-3478a/protocol.c +++ b/src/hardware/hp-3478a/protocol.c @@ -110,6 +110,24 @@ SR_PRIV int hp_3478a_set_range(const struct sr_dev_inst *sdi, int range_exp) return hp_3478a_get_status_bytes(sdi); } +SR_PRIV int hp_3478a_set_digits(const struct sr_dev_inst *sdi, uint8_t digits) +{ + 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->spec_digits == digits) + return SR_OK; + + /* digits are based on devc->spec_digits, so we have to substract 1 */ + ret = sr_scpi_send(scpi, "N%i", digits-1); + 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) { diff --git a/src/hardware/hp-3478a/protocol.h b/src/hardware/hp-3478a/protocol.h index 1b7f5cb1..169166c9 100644 --- a/src/hardware/hp-3478a/protocol.h +++ b/src/hardware/hp-3478a/protocol.h @@ -162,6 +162,7 @@ struct channel_context { SR_PRIV int hp_3478a_set_mq(const struct sr_dev_inst *sdi, enum sr_mq mq, enum sr_mqflag mq_flags); SR_PRIV int hp_3478a_set_range(const struct sr_dev_inst *sdi, int range_exp); +SR_PRIV int hp_3478a_set_digits(const struct sr_dev_inst *sdi, uint8_t digits); SR_PRIV int hp_3478a_get_status_bytes(const struct sr_dev_inst *sdi); SR_PRIV int hp_3478a_receive_data(int fd, int revents, void *cb_data);