From: Aurelien Jacobs Date: Sun, 19 Jan 2014 13:46:59 +0000 (+0100) Subject: rigol-ds: fix set_cfg() calls with float parameters to avoid locale issues X-Git-Tag: libsigrok-0.3.0~231 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=889ef4a01cbf50d381cda0a1331b794a2c6d26c8;p=libsigrok.git rigol-ds: fix set_cfg() calls with float parameters to avoid locale issues --- diff --git a/hardware/rigol-ds/api.c b/hardware/rigol-ds/api.c index 52a59a97..6220c61f 100644 --- a/hardware/rigol-ds/api.c +++ b/hardware/rigol-ds/api.c @@ -552,6 +552,7 @@ static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi, unsigned int i, j; int ret; const char *tmp_str; + char buffer[16]; if (!(devc = sdi->priv)) return SR_ERR_ARG; @@ -586,14 +587,17 @@ static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi, /* We have the trigger offset as a percentage of the frame, but * need to express this in seconds. */ t_dbl = -(devc->horiz_triggerpos - 0.5) * devc->timebase * devc->num_timebases; - ret = set_cfg(sdi, ":TIM:OFFS %.6f", t_dbl); + g_ascii_formatd(buffer, sizeof(buffer), "%.6f", t_dbl); + ret = set_cfg(sdi, ":TIM:OFFS %s", buffer); break; case SR_CONF_TIMEBASE: g_variant_get(data, "(tt)", &p, &q); for (i = 0; i < devc->num_timebases; i++) { if (devc->timebases[i][0] == p && devc->timebases[i][1] == q) { devc->timebase = (float)p / q; - ret = set_cfg(sdi, ":TIM:SCAL %.9f", devc->timebase); + g_ascii_formatd(buffer, sizeof(buffer), "%.9f", + devc->timebase); + ret = set_cfg(sdi, ":TIM:SCAL %s", buffer); break; } } @@ -637,8 +641,10 @@ static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi, if (vdivs[j][0] != p || vdivs[j][1] != q) continue; devc->vdiv[i] = (float)p / q; - return set_cfg(sdi, ":CHAN%d:SCAL %.3f", i + 1, - devc->vdiv[i]); + g_ascii_formatd(buffer, sizeof(buffer), "%.3f", + devc->vdiv[i]); + return set_cfg(sdi, ":CHAN%d:SCAL %s", i + 1, + buffer); } return SR_ERR_ARG; }