Hi,
> I've just merged an older patch from Benjamin Larsson that somehow fell
> through the cracks (entirely my fault), which solves parts of the issue
> by only allowing DC coupling selection.
>
> IIRC, there was a PulseView bug with drop-downs with only one item (e.g.
> just "DC") so for the time being the driver will report a list of two
> items ("DC" and "DC") until that's fixed.
>
> Please feel free to additionally implement "Ignore requests to set
> coupling for the Hantek", that's not in yet.
>
Here's a patch to "Ignore requests to set coupling for the Hantek",
this clears the LIBUSB errors for me
Also in the patch:
- There is a crash in the patch from Benjamin Larsson beacuse
config_list can be called with sdi = NULL.
This can be reproduced by doing: "sigrok-cli.exe --driver hantek-6xxx --show"
- There seems to be a very unsafe loop in config_set when setting
COUPLING; the coupling vector is
assumed to be zero terminated, but is not declared as such.
Note: The same issue is present also for other hardware, at least
for libsigrok/src/hardware/hantek-dso/api.c
The patch is only for hantek-6xxx though.
diff --git a/src/hardware/hantek-6xxx/api.c b/src/hardware/hantek-6xxx/api.c
index cbcd15b..db7218d 100644
--- a/src/hardware/hantek-6xxx/api.c
+++ b/src/hardware/hantek-6xxx/api.c
@@ -62,12 +62,12 @@ static const struct hantek_6xxx_profile dev_profiles[] = {
{
0x04b4, 0x6022, 0x04b5, 0x6022,
"Hantek", "6022BE", "hantek-6022be.fw",
- dc_coupling, ARRAY_SIZE(dc_coupling),
+ dc_coupling, ARRAY_SIZE(dc_coupling), FALSE,
},
{
0x8102, 0x8102, 0x1D50, 0x608E,
"Sainsmart", "DDS120", "sainsmart-dds120.fw",
- acdc_coupling, ARRAY_SIZE(acdc_coupling),
+ acdc_coupling, ARRAY_SIZE(acdc_coupling), TRUE,
},
ALL_ZERO
};
@@ -440,13 +440,13 @@ static int config_set(uint32_t key, GVariant
*data, const struct sr_dev_inst *sd
break;
case SR_CONF_COUPLING:
tmp_str = g_variant_get_string(data, NULL);
- for (i = 0; devc->coupling_vals[i]; i++) {
+ for (i = 0; i < devc->coupling_tab_size; i++) {
if (!strcmp(tmp_str, devc->coupling_vals[i])) {
devc->coupling[ch_idx] = i;
break;
}
}
- if (devc->coupling_vals[i] == 0)
+ if (i == devc->coupling_tab_size)
ret = SR_ERR_ARG;
break;
default:
@@ -465,10 +465,9 @@ static int config_list(uint32_t key, GVariant
**data, const struct sr_dev_inst *
GVariantBuilder gvb;
unsigned int i;
GVariant *gvar;
- struct dev_context *devc;
-
- devc = sdi->priv;
+ struct dev_context *devc = NULL;
+ if(sdi) devc = sdi->priv;
if (key == SR_CONF_SCAN_OPTIONS) {
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
@@ -506,7 +505,10 @@ static int config_list(uint32_t key, GVariant
**data, const struct sr_dev_inst *
devopts_cg, ARRAY_SIZE(devopts_cg),
sizeof(uint32_t));
break;
case SR_CONF_COUPLING:
- *data =
g_variant_new_strv(devc->coupling_vals, devc->coupling_tab_size);
+ if (devc)
+ *data =
g_variant_new_strv(devc->coupling_vals, devc->coupling_tab_size);
+ else
+ return SR_ERR_NA;
break;
case SR_CONF_VDIV:
g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY);
diff --git a/src/hardware/hantek-6xxx/protocol.c
b/src/hardware/hantek-6xxx/protocol.c
index 12a56ab..5e9a6ee 100644
--- a/src/hardware/hantek-6xxx/protocol.c
+++ b/src/hardware/hantek-6xxx/protocol.c
@@ -220,9 +220,14 @@ SR_PRIV int hantek_6xxx_update_coupling(const
struct sr_dev_inst *sdi)
struct dev_context *devc = sdi->priv;
uint8_t coupling = 0xFF & ((devc->coupling[1] << 4) |
devc->coupling[0]);
- sr_dbg("update coupling 0x%x", coupling);
-
- return write_control(sdi, COUPLING_REG, coupling);
+ if (devc->has_coupling) {
+ sr_dbg("update coupling 0x%x", coupling);
+
+ return write_control(sdi, COUPLING_REG, coupling);
+ } else {
+ sr_dbg("coupling not supported");
+ return SR_OK;
+ }
}
SR_PRIV int hantek_6xxx_update_channels(const struct sr_dev_inst *sdi)
diff --git a/src/hardware/hantek-6xxx/protocol.h
b/src/hardware/hantek-6xxx/protocol.h
index 0c54ec9..abe30f4 100644
--- a/src/hardware/hantek-6xxx/protocol.h
+++ b/src/hardware/hantek-6xxx/protocol.h
@@ -99,6 +99,7 @@ struct hantek_6xxx_profile {
const char *firmware;
const char **coupling_vals;
uint8_t coupling_tab_size;
+ boolean has_coupling;
};
struct dev_context {
@@ -127,6 +128,7 @@ struct dev_context {
int coupling[NUM_CHANNELS];
const char **coupling_vals;
uint8_t coupling_tab_size;
+ boolean has_coupling;
uint64_t samplerate;
uint64_t limit_msec;
------------------------------------------------------------------------------
_______________________________________________
sigrok-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sigrok-devel