hp-3478a: Fix switching from 4-wire to 2-wire measurement.
The measured quantity flags for the measurement mode can only contain one flag at maximum. Therefore the quantity flags handling can be simplified, which also fixes a bug when switching from 4-wire resistance measurement to 2-wire mode.
This commit is contained in:
parent
8ef4fb3347
commit
569165c0e4
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* This file is part of the libsigrok project.
|
||||
*
|
||||
* Copyright (C) 2017 Frank Stettner <frank-stettner@gmx.net>
|
||||
* Copyright (C) 2017-2021 Frank Stettner <frank-stettner@gmx.net>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -203,7 +203,7 @@ static int config_get(uint32_t key, GVariant **data,
|
|||
if (ret != SR_OK)
|
||||
return ret;
|
||||
arr[0] = g_variant_new_uint32(devc->measurement_mq);
|
||||
arr[1] = g_variant_new_uint64(devc->measurement_mq_flags);
|
||||
arr[1] = g_variant_new_uint64(devc->measurement_mq_flag);
|
||||
*data = g_variant_new_tuple(arr, 2);
|
||||
break;
|
||||
case SR_CONF_RANGE:
|
||||
|
@ -213,7 +213,7 @@ static int config_get(uint32_t key, GVariant **data,
|
|||
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].mqflag == devc->measurement_mq_flag &&
|
||||
rangeopts[i].range_exp == devc->range_exp) {
|
||||
range_str = rangeopts[i].range_str;
|
||||
break;
|
||||
|
@ -265,7 +265,7 @@ static int config_set(uint32_t key, GVariant *data,
|
|||
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 &&
|
||||
rangeopts[i].mqflag == devc->measurement_mq_flag &&
|
||||
g_strcmp0(rangeopts[i].range_str, range_str) == 0) {
|
||||
return hp_3478a_set_range(sdi, rangeopts[i].range_exp);
|
||||
}
|
||||
|
@ -321,7 +321,7 @@ static int config_list(uint32_t key, GVariant **data,
|
|||
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) {
|
||||
rangeopts[i].mqflag == devc->measurement_mq_flag) {
|
||||
g_variant_builder_add(&gvb, "s", rangeopts[i].range_str);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* This file is part of the libsigrok project.
|
||||
*
|
||||
* Copyright (C) 2017-2018 Frank Stettner <frank-stettner@gmx.net>
|
||||
* Copyright (C) 2017-2021 Frank Stettner <frank-stettner@gmx.net>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -69,9 +69,8 @@ SR_PRIV int hp_3478a_set_mq(const struct sr_dev_inst *sdi, enum sr_mq mq,
|
|||
struct sr_scpi_dev_inst *scpi = sdi->conn;
|
||||
struct dev_context *devc = sdi->priv;
|
||||
|
||||
/* No need to send command if we're not changing measurement type. */
|
||||
if (devc->measurement_mq == mq &&
|
||||
((devc->measurement_mq_flags & mq_flags) == mq_flags))
|
||||
/* No need to send a command if we're not changing the measurement type. */
|
||||
if (devc->measurement_mq == mq && devc->measurement_mq_flag == mq_flags)
|
||||
return SR_OK;
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(sr_mq_to_cmd_map); i++) {
|
||||
|
@ -227,17 +226,17 @@ static int parse_function_byte(struct dev_context *devc, uint8_t function_byte)
|
|||
return SR_ERR_DATA;
|
||||
|
||||
/* Function + Range */
|
||||
devc->measurement_mq_flags = 0;
|
||||
devc->measurement_mq_flag = 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->measurement_mq_flag = 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;
|
||||
devc->measurement_mq_flag = 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);
|
||||
|
@ -247,19 +246,19 @@ static int parse_function_byte(struct dev_context *devc, uint8_t function_byte)
|
|||
parse_range_ohm(devc, function_byte);
|
||||
} else if ((function_byte & SB1_FUNCTION_BLOCK) == FUNCTION_4WR) {
|
||||
devc->measurement_mq = SR_MQ_RESISTANCE;
|
||||
devc->measurement_mq_flags |= SR_MQFLAG_FOUR_WIRE;
|
||||
devc->measurement_mq_flag = 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->measurement_mq_flag = 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;
|
||||
devc->measurement_mq_flag = 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);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* This file is part of the libsigrok project.
|
||||
*
|
||||
* Copyright (C) 2017 Frank Stettner <frank-stettner@gmx.net>
|
||||
* Copyright (C) 2017-2021 Frank Stettner <frank-stettner@gmx.net>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -31,7 +31,7 @@
|
|||
#define SB1_RANGE_BLOCK 0b00011100
|
||||
#define SB1_DIGITS_BLOCK 0b00000011
|
||||
|
||||
/* Status Byte 1 (Function) */
|
||||
/** Status Byte 1 (Function) */
|
||||
enum sb1_function {
|
||||
FUNCTION_VDC = 0b00100000,
|
||||
FUNCTION_VAC = 0b01000000,
|
||||
|
@ -42,7 +42,7 @@ enum sb1_function {
|
|||
FUNCTION_EXR = 0b11100000,
|
||||
};
|
||||
|
||||
/* Status Byte 1 (Range V DC) */
|
||||
/** Status Byte 1 (Range V DC) */
|
||||
enum sb1_range_vdc {
|
||||
RANGE_VDC_30MV = 0b00000100,
|
||||
RANGE_VDC_300MV = 0b00001000,
|
||||
|
@ -51,7 +51,7 @@ enum sb1_range_vdc {
|
|||
RANGE_VDC_300V = 0b00010100,
|
||||
};
|
||||
|
||||
/* Status Byte 1 (Range V AC) */
|
||||
/** Status Byte 1 (Range V AC) */
|
||||
enum sb1_range_vac {
|
||||
RANGE_VAC_300MV = 0b00000100,
|
||||
RANGE_VAC_3V = 0b00001000,
|
||||
|
@ -59,13 +59,13 @@ enum sb1_range_vac {
|
|||
RANGE_VAC_300V = 0b00010000,
|
||||
};
|
||||
|
||||
/* Status Byte 1 (Range A) */
|
||||
/** Status Byte 1 (Range A) */
|
||||
enum sb1_range_a {
|
||||
RANGE_A_300MA = 0b00000100,
|
||||
RANGE_A_3A = 0b00001000,
|
||||
};
|
||||
|
||||
/* Status Byte 1 (Range Ohm) */
|
||||
/** Status Byte 1 (Range Ohm) */
|
||||
enum sb1_range_ohm {
|
||||
RANGE_OHM_30R = 0b00000100,
|
||||
RANGE_OHM_300R = 0b00001000,
|
||||
|
@ -76,14 +76,14 @@ enum sb1_range_ohm {
|
|||
RANGE_OHM_30MR = 0b00011100,
|
||||
};
|
||||
|
||||
/* Status Byte 1 (Digits) */
|
||||
/** Status Byte 1 (Digits) */
|
||||
enum sb1_digits {
|
||||
DIGITS_5_5 = 0b00000001,
|
||||
DIGITS_4_5 = 0b00000010,
|
||||
DIGITS_3_5 = 0b00000011,
|
||||
};
|
||||
|
||||
/* Status Byte 2 */
|
||||
/** Status Byte 2 */
|
||||
enum sb2_status {
|
||||
STATUS_INT_TRIGGER = (1 << 0),
|
||||
STATUS_AUTO_RANGE = (1 << 1),
|
||||
|
@ -94,7 +94,7 @@ enum sb2_status {
|
|||
STATUS_EXT_TRIGGER = (1 << 6),
|
||||
};
|
||||
|
||||
/* Status Byte 3 (Serial Poll Mask) */
|
||||
/** Status Byte 3 (Serial Poll Mask) */
|
||||
enum sb3_srq {
|
||||
SRQ_BUS_AVAIL = (1 << 0),
|
||||
SRQ_SYNTAX_ERR = (1 << 2),
|
||||
|
@ -104,7 +104,7 @@ enum sb3_srq {
|
|||
SRQ_POWER_ON = (1 << 7),
|
||||
};
|
||||
|
||||
/* Status Byte 4 (Error) */
|
||||
/** Status Byte 4 (Error) */
|
||||
enum sb4_error {
|
||||
ERROR_SELF_TEST = (1 << 0),
|
||||
ERROR_RAM_SELF_TEST = (1 << 1),
|
||||
|
@ -114,20 +114,20 @@ enum sb4_error {
|
|||
ERROR_AD_LINK = (1 << 5),
|
||||
};
|
||||
|
||||
/* Channel connector (front terminals or rear terminals. */
|
||||
/** Channel connector (front terminals or rear terminals. */
|
||||
enum terminal_connector {
|
||||
TERMINAL_FRONT,
|
||||
TERMINAL_REAR,
|
||||
};
|
||||
|
||||
/* Possible triggers */
|
||||
/** Available triggers */
|
||||
enum trigger_state {
|
||||
TRIGGER_UNDEFINED,
|
||||
TRIGGER_EXTERNAL,
|
||||
TRIGGER_INTERNAL,
|
||||
};
|
||||
|
||||
/* Possible line frequencies */
|
||||
/** Available line frequencies */
|
||||
enum line_freq {
|
||||
LINE_50HZ,
|
||||
LINE_60HZ,
|
||||
|
@ -138,9 +138,15 @@ struct dev_context {
|
|||
|
||||
double measurement;
|
||||
enum sr_mq measurement_mq;
|
||||
/** The measurement mq flags only contain flags for AC, DC and 4-wire. */
|
||||
enum sr_mqflag measurement_mq_flags;
|
||||
/** The acquisition mq flags also contain flags for autoranging and RMS. */
|
||||
/**
|
||||
* The measurement mq flag can contain none or one of the
|
||||
* following flags: AC, DC, or 4-wire.
|
||||
*/
|
||||
enum sr_mqflag measurement_mq_flag;
|
||||
/**
|
||||
* The acquisition mq flags can contain multiple flags,
|
||||
* for example autoranging, RMS, etc.
|
||||
*/
|
||||
enum sr_mqflag acquisition_mq_flags;
|
||||
enum sr_unit measurement_unit;
|
||||
int range_exp;
|
||||
|
|
Loading…
Reference in New Issue