]>
Commit | Line | Data |
---|---|---|
7a396ff5 GS |
1 | /* |
2 | * This file is part of the libsigrok project. | |
3 | * | |
4 | * Copyright (C) 2018 Gerhard Sittig <gerhard.sittig@gmx.net> | |
5 | * | |
6 | * This program is free software: you can redistribute it and/or modify | |
7 | * it under the terms of the GNU General Public License as published by | |
8 | * the Free Software Foundation, either version 3 of the License, or | |
9 | * (at your option) any later version. | |
10 | * | |
11 | * This program is distributed in the hope that it will be useful, | |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | * GNU General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU General Public License | |
17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
18 | */ | |
19 | ||
3cdad416 | 20 | #include <string.h> |
7a396ff5 GS |
21 | #include "protocol.h" |
22 | ||
0617bb5a GS |
23 | static struct sr_dev_driver scpi_dmm_driver_info; |
24 | ||
3cdad416 GS |
25 | static const uint32_t scanopts[] = { |
26 | SR_CONF_CONN, | |
31e65c62 | 27 | SR_CONF_SERIALCOMM, |
3cdad416 GS |
28 | }; |
29 | ||
30 | static const uint32_t drvopts[] = { | |
31 | SR_CONF_MULTIMETER, | |
32 | }; | |
33 | ||
1d2f9963 | 34 | static const uint32_t devopts_generic[] = { |
3cdad416 | 35 | SR_CONF_CONTINUOUS, |
7d95afb9 | 36 | SR_CONF_CONN | SR_CONF_GET, |
3cdad416 GS |
37 | SR_CONF_LIMIT_SAMPLES | SR_CONF_GET | SR_CONF_SET, |
38 | SR_CONF_LIMIT_MSEC | SR_CONF_GET | SR_CONF_SET, | |
39 | SR_CONF_MEASURED_QUANTITY | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST, | |
40 | }; | |
41 | ||
a0418c20 GS |
42 | static const uint32_t devopts_generic_range[] = { |
43 | SR_CONF_CONTINUOUS, | |
44 | SR_CONF_CONN | SR_CONF_GET, | |
45 | SR_CONF_LIMIT_SAMPLES | SR_CONF_GET | SR_CONF_SET, | |
46 | SR_CONF_LIMIT_MSEC | SR_CONF_GET | SR_CONF_SET, | |
47 | SR_CONF_MEASURED_QUANTITY | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST, | |
48 | SR_CONF_RANGE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST, | |
49 | }; | |
50 | ||
3cdad416 GS |
51 | static const struct scpi_command cmdset_agilent[] = { |
52 | { DMM_CMD_SETUP_REMOTE, "\n", }, | |
118da66f | 53 | { DMM_CMD_SETUP_LOCAL, "SYST:LOC", }, |
3cdad416 GS |
54 | { DMM_CMD_SETUP_FUNC, "CONF:%s", }, |
55 | { DMM_CMD_QUERY_FUNC, "CONF?", }, | |
7fcdc35e | 56 | { DMM_CMD_START_ACQ, "INIT", }, |
3cdad416 | 57 | { DMM_CMD_STOP_ACQ, "ABORT", }, |
b74cc88d | 58 | { DMM_CMD_QUERY_VALUE, "FETCH?", }, |
3cdad416 | 59 | { DMM_CMD_QUERY_PREC, "CONF?", }, |
a0418c20 GS |
60 | { DMM_CMD_QUERY_RANGE_AUTO, "%s:RANGE:AUTO?", }, |
61 | { DMM_CMD_QUERY_RANGE, "%s:RANGE?", }, | |
b74cc88d | 62 | { DMM_CMD_SETUP_RANGE, "CONF:%s %s", }, |
3cdad416 GS |
63 | ALL_ZERO, |
64 | }; | |
65 | ||
a1619831 | 66 | /* |
1c8110db | 67 | * cmdset_hp is used for the 34401A, which was added to this code after the |
a1619831 AG |
68 | * 34405A and 34465A. It differs in starting the measurement with INIT: using |
69 | * MEAS without a trailing '?' (as used for the 34405A) is not valid for the | |
1c8110db FS |
70 | * 34401A and gives an error. |
71 | * I'm surprised the same instruction sequence doesn't work and INIT may | |
72 | * work for both, but I don't have the others to re-test. | |
a1619831 | 73 | * |
85cff5cf MW |
74 | * cmdset_hp also works well for the 34410A, using cmdset_agilent throws an |
75 | * error on 'MEAS' without a '?'. | |
76 | * | |
1c8110db FS |
77 | * On the 34401A, |
78 | * MEAS <optional parameters> ? configures, arms, triggers and waits | |
a1619831 AG |
79 | * for a reading |
80 | * CONF <parameters> configures | |
1c8110db | 81 | * INIT prepares for triggering (trigger mode is not set, assumed |
a1619831 AG |
82 | * internal - external might time out) |
83 | * *OPC waits for completion, and | |
84 | * READ? retrieves the result | |
85 | */ | |
86 | static const struct scpi_command cmdset_hp[] = { | |
87 | { DMM_CMD_SETUP_REMOTE, "\n", }, | |
88 | { DMM_CMD_SETUP_FUNC, "CONF:%s", }, | |
89 | { DMM_CMD_QUERY_FUNC, "CONF?", }, | |
90 | { DMM_CMD_START_ACQ, "INIT", }, | |
91 | { DMM_CMD_STOP_ACQ, "ABORT", }, | |
92 | { DMM_CMD_QUERY_VALUE, "READ?", }, | |
93 | { DMM_CMD_QUERY_PREC, "CONF?", }, | |
94 | ALL_ZERO, | |
95 | }; | |
96 | ||
d0b602f0 TK |
97 | static const struct scpi_command cmdset_gwinstek[] = { |
98 | { DMM_CMD_SETUP_REMOTE, "SYST:REM", }, | |
4c80a272 | 99 | { DMM_CMD_SETUP_LOCAL, "SYST:LOC", }, |
d0b602f0 TK |
100 | { DMM_CMD_SETUP_FUNC, "CONF:%s", }, |
101 | { DMM_CMD_QUERY_FUNC, "CONF:STAT:FUNC?", }, | |
102 | { DMM_CMD_START_ACQ, "*CLS;SYST:REM", }, | |
d0b602f0 TK |
103 | { DMM_CMD_QUERY_VALUE, "VAL1?", }, |
104 | { DMM_CMD_QUERY_PREC, "SENS:DET:RATE?", }, | |
105 | ALL_ZERO, | |
106 | }; | |
107 | ||
868fc65e TK |
108 | static const struct scpi_command cmdset_gwinstek_906x[] = { |
109 | { DMM_CMD_SETUP_REMOTE, "SYST:REM", }, | |
4c80a272 | 110 | { DMM_CMD_SETUP_LOCAL, "SYST:LOC", }, |
868fc65e TK |
111 | { DMM_CMD_SETUP_FUNC, "CONF:%s", }, |
112 | { DMM_CMD_QUERY_FUNC, "CONF?", }, | |
860ee00a TK |
113 | { DMM_CMD_START_ACQ, "INIT", }, |
114 | { DMM_CMD_STOP_ACQ, "ABORT", }, | |
868fc65e TK |
115 | { DMM_CMD_QUERY_VALUE, "VAL1?", }, |
116 | { DMM_CMD_QUERY_PREC, "SENS:DET:RATE?", }, | |
117 | ALL_ZERO, | |
118 | }; | |
119 | ||
2111d157 PA |
120 | static const struct scpi_command cmdset_owon[] = { |
121 | { DMM_CMD_SETUP_REMOTE, "SYST:REM", }, | |
122 | { DMM_CMD_SETUP_LOCAL, "SYST:LOC", }, | |
123 | { DMM_CMD_SETUP_FUNC, "CONF:%s", }, | |
124 | { DMM_CMD_QUERY_FUNC, "FUNC?", }, | |
125 | { DMM_CMD_QUERY_VALUE, "MEAS1?", }, | |
126 | ALL_ZERO, | |
127 | }; | |
128 | ||
64d03de1 | 129 | static const struct mqopt_item mqopts_agilent_34405a[] = { |
1de14d67 | 130 | { SR_MQ_VOLTAGE, SR_MQFLAG_DC, "VOLT:DC", "VOLT ", NO_DFLT_PREC, FLAGS_NONE, }, |
e90551c3 | 131 | { SR_MQ_VOLTAGE, SR_MQFLAG_AC, "VOLT:AC", "VOLT:AC ", NO_DFLT_PREC, FLAG_CONF_DELAY | FLAG_MEAS_DELAY, }, |
1de14d67 | 132 | { SR_MQ_CURRENT, SR_MQFLAG_DC, "CURR:DC", "CURR ", NO_DFLT_PREC, FLAGS_NONE, }, |
e90551c3 GS |
133 | { SR_MQ_CURRENT, SR_MQFLAG_AC, "CURR:AC", "CURR:AC ", NO_DFLT_PREC, FLAG_CONF_DELAY | FLAG_MEAS_DELAY, }, |
134 | { SR_MQ_RESISTANCE, 0, "RES", "RES ", NO_DFLT_PREC, FLAG_MEAS_DELAY, }, | |
135 | { SR_MQ_RESISTANCE, SR_MQFLAG_FOUR_WIRE, "FRES", "FRES ", NO_DFLT_PREC, FLAG_MEAS_DELAY, }, | |
5bf642db | 136 | { SR_MQ_CONTINUITY, 0, "CONT", "CONT", -1, FLAG_NO_RANGE, }, |
1de14d67 | 137 | { SR_MQ_CAPACITANCE, 0, "CAP", "CAP ", NO_DFLT_PREC, FLAGS_NONE, }, |
5bf642db | 138 | { SR_MQ_VOLTAGE, SR_MQFLAG_DC | SR_MQFLAG_DIODE, "DIOD", "DIOD", -4, FLAG_NO_RANGE, }, |
e90551c3 GS |
139 | { SR_MQ_TEMPERATURE, 0, "TEMP", "TEMP ", NO_DFLT_PREC, FLAG_NO_RANGE | FLAG_MEAS_DELAY, }, |
140 | { SR_MQ_FREQUENCY, 0, "FREQ", "FREQ ", NO_DFLT_PREC, FLAG_NO_RANGE | FLAG_MEAS_DELAY, }, | |
3cdad416 GS |
141 | }; |
142 | ||
a1619831 | 143 | static const struct mqopt_item mqopts_agilent_34401a[] = { |
1de14d67 GS |
144 | { SR_MQ_VOLTAGE, SR_MQFLAG_DC, "VOLT:DC", "VOLT ", NO_DFLT_PREC, FLAGS_NONE, }, |
145 | { SR_MQ_VOLTAGE, SR_MQFLAG_AC, "VOLT:AC", "VOLT:AC ", NO_DFLT_PREC, FLAGS_NONE, }, | |
146 | { SR_MQ_CURRENT, SR_MQFLAG_DC, "CURR:DC", "CURR ", NO_DFLT_PREC, FLAGS_NONE, }, | |
147 | { SR_MQ_CURRENT, SR_MQFLAG_AC, "CURR:AC", "CURR:AC ", NO_DFLT_PREC, FLAGS_NONE, }, | |
148 | { SR_MQ_RESISTANCE, 0, "RES", "RES ", NO_DFLT_PREC, FLAGS_NONE, }, | |
149 | { SR_MQ_RESISTANCE, SR_MQFLAG_FOUR_WIRE, "FRES", "FRES ", NO_DFLT_PREC, FLAGS_NONE, }, | |
150 | { SR_MQ_CONTINUITY, 0, "CONT", "CONT", -1, FLAGS_NONE, }, | |
151 | { SR_MQ_VOLTAGE, SR_MQFLAG_DC | SR_MQFLAG_DIODE, "DIOD", "DIOD", -4, FLAGS_NONE, }, | |
152 | { SR_MQ_FREQUENCY, 0, "FREQ", "FREQ ", NO_DFLT_PREC, FLAGS_NONE, }, | |
153 | { SR_MQ_TIME, 0, "PER", "PER ", NO_DFLT_PREC, FLAGS_NONE, }, | |
a1619831 AG |
154 | }; |
155 | ||
d0b602f0 | 156 | static const struct mqopt_item mqopts_gwinstek_gdm8200a[] = { |
1de14d67 GS |
157 | { SR_MQ_VOLTAGE, SR_MQFLAG_DC, "VOLT:DC", "01", NO_DFLT_PREC, FLAGS_NONE, }, |
158 | { SR_MQ_VOLTAGE, SR_MQFLAG_AC, "VOLT:AC", "02", NO_DFLT_PREC, FLAGS_NONE, }, | |
159 | { SR_MQ_CURRENT, SR_MQFLAG_DC, "CURR:DC", "03", NO_DFLT_PREC, FLAGS_NONE, }, | |
160 | { SR_MQ_CURRENT, SR_MQFLAG_AC, "CURR:AC", "04", NO_DFLT_PREC, FLAGS_NONE, }, | |
161 | { SR_MQ_CURRENT, SR_MQFLAG_DC, "CURR:DC", "05", NO_DFLT_PREC, FLAGS_NONE, }, /* mA */ | |
162 | { SR_MQ_CURRENT, SR_MQFLAG_AC, "CURR:AC", "06", NO_DFLT_PREC, FLAGS_NONE, }, /* mA */ | |
163 | { SR_MQ_RESISTANCE, 0, "RES", "07", NO_DFLT_PREC, FLAGS_NONE, }, | |
164 | { SR_MQ_RESISTANCE, SR_MQFLAG_FOUR_WIRE, "FRES", "16", NO_DFLT_PREC, FLAGS_NONE, }, | |
165 | { SR_MQ_CONTINUITY, 0, "CONT", "13", -1, FLAGS_NONE, }, | |
166 | { SR_MQ_VOLTAGE, SR_MQFLAG_DC | SR_MQFLAG_DIODE, "DIOD", "17", -4, FLAGS_NONE, }, | |
167 | { SR_MQ_TEMPERATURE, 0, "TEMP", "09", NO_DFLT_PREC, FLAGS_NONE, }, /* Celsius */ | |
168 | { SR_MQ_TEMPERATURE, 0, "TEMP", "15", NO_DFLT_PREC, FLAGS_NONE, }, /* Fahrenheit */ | |
169 | { SR_MQ_FREQUENCY, 0, "FREQ", "08", NO_DFLT_PREC, FLAGS_NONE, }, | |
170 | { SR_MQ_TIME, 0, "PER", "14", NO_DFLT_PREC, FLAGS_NONE, }, | |
d0b602f0 TK |
171 | }; |
172 | ||
868fc65e | 173 | static const struct mqopt_item mqopts_gwinstek_gdm906x[] = { |
1de14d67 GS |
174 | { SR_MQ_VOLTAGE, SR_MQFLAG_DC, "VOLT:DC", "VOLT ", NO_DFLT_PREC, FLAGS_NONE, }, |
175 | { SR_MQ_VOLTAGE, SR_MQFLAG_AC, "VOLT:AC", "VOLT:AC", NO_DFLT_PREC, FLAGS_NONE, }, | |
176 | { SR_MQ_CURRENT, SR_MQFLAG_DC, "CURR:DC", "CURR ", NO_DFLT_PREC, FLAGS_NONE, }, | |
177 | { SR_MQ_CURRENT, SR_MQFLAG_AC, "CURR:AC", "CURR:AC", NO_DFLT_PREC, FLAGS_NONE, }, | |
178 | { SR_MQ_RESISTANCE, 0, "RES", "RES", NO_DFLT_PREC, FLAGS_NONE, }, | |
179 | { SR_MQ_RESISTANCE, SR_MQFLAG_FOUR_WIRE, "FRES", "FRES", NO_DFLT_PREC, FLAGS_NONE, }, | |
180 | { SR_MQ_CONTINUITY, 0, "CONT", "CONT", -1, FLAGS_NONE, }, | |
181 | { SR_MQ_VOLTAGE, SR_MQFLAG_DC | SR_MQFLAG_DIODE, "DIOD", "DIOD", -4, FLAGS_NONE, }, | |
182 | { SR_MQ_TEMPERATURE, 0, "TEMP", "TEMP", NO_DFLT_PREC, FLAGS_NONE, }, | |
183 | { SR_MQ_FREQUENCY, 0, "FREQ", "FREQ", NO_DFLT_PREC, FLAGS_NONE, }, | |
184 | { SR_MQ_TIME, 0, "PER", "PER", NO_DFLT_PREC, FLAGS_NONE, }, | |
185 | { SR_MQ_CAPACITANCE, 0, "CAP", "CAP", NO_DFLT_PREC, FLAGS_NONE, }, | |
868fc65e TK |
186 | }; |
187 | ||
2111d157 | 188 | static const struct mqopt_item mqopts_owon_xdm2041[] = { |
1de14d67 GS |
189 | { SR_MQ_VOLTAGE, SR_MQFLAG_AC, "VOLT:AC", "VOLT AC", NO_DFLT_PREC, FLAGS_NONE, }, |
190 | { SR_MQ_VOLTAGE, SR_MQFLAG_DC, "VOLT:DC", "VOLT", NO_DFLT_PREC, FLAGS_NONE, }, | |
191 | { SR_MQ_CURRENT, SR_MQFLAG_AC, "CURR:AC", "CURR AC", NO_DFLT_PREC, FLAGS_NONE, }, | |
192 | { SR_MQ_CURRENT, SR_MQFLAG_DC, "CURR:DC", "CURR", NO_DFLT_PREC, FLAGS_NONE, }, | |
193 | { SR_MQ_RESISTANCE, 0, "RES", "RES", NO_DFLT_PREC, FLAGS_NONE, }, | |
194 | { SR_MQ_RESISTANCE, SR_MQFLAG_FOUR_WIRE, "FRES", "FRES", NO_DFLT_PREC, FLAGS_NONE, }, | |
195 | { SR_MQ_CONTINUITY, 0, "CONT", "CONT", -1, FLAGS_NONE, }, | |
196 | { SR_MQ_VOLTAGE, SR_MQFLAG_DC | SR_MQFLAG_DIODE, "DIOD", "DIOD", -4, FLAGS_NONE, }, | |
197 | { SR_MQ_TEMPERATURE, 0, "TEMP", "TEMP", NO_DFLT_PREC, FLAGS_NONE, }, | |
198 | { SR_MQ_FREQUENCY, 0, "FREQ", "FREQ", NO_DFLT_PREC, FLAGS_NONE, }, | |
199 | { SR_MQ_CAPACITANCE, 0, "CAP", "CAP", NO_DFLT_PREC, FLAGS_NONE, }, | |
2111d157 PA |
200 | }; |
201 | ||
3cdad416 GS |
202 | SR_PRIV const struct scpi_dmm_model models[] = { |
203 | { | |
204 | "Agilent", "34405A", | |
64d03de1 | 205 | 1, 5, cmdset_agilent, ARRAY_AND_SIZE(mqopts_agilent_34405a), |
3cdad416 | 206 | scpi_dmm_get_meas_agilent, |
a0418c20 | 207 | ARRAY_AND_SIZE(devopts_generic_range), |
e90551c3 | 208 | 0, 200 * 1000, 2500 * 1000, 0, FALSE, |
a0418c20 | 209 | scpi_dmm_get_range_text, scpi_dmm_set_range_from_text, NULL, |
3cdad416 | 210 | }, |
85cff5cf MW |
211 | { |
212 | "Agilent", "34410A", | |
213 | 1, 6, cmdset_hp, ARRAY_AND_SIZE(mqopts_agilent_34405a), | |
214 | scpi_dmm_get_meas_agilent, | |
215 | ARRAY_AND_SIZE(devopts_generic), | |
e90551c3 | 216 | 0, 0, 0, 0, FALSE, |
a0418c20 | 217 | NULL, NULL, NULL, |
d8064712 SP |
218 | }, |
219 | { | |
220 | "Agilent", "34460A", | |
221 | 1, 6, cmdset_agilent, ARRAY_AND_SIZE(mqopts_agilent_34405a), | |
222 | scpi_dmm_get_meas_agilent, | |
223 | ARRAY_AND_SIZE(devopts_generic_range), | |
224 | 0, 0, 10 * 1000, 0, FALSE, | |
225 | scpi_dmm_get_range_text, scpi_dmm_set_range_from_text, NULL, | |
85cff5cf | 226 | }, |
d0b602f0 TK |
227 | { |
228 | "GW", "GDM8251A", | |
229 | 1, 6, cmdset_gwinstek, ARRAY_AND_SIZE(mqopts_gwinstek_gdm8200a), | |
230 | scpi_dmm_get_meas_gwinstek, | |
231 | ARRAY_AND_SIZE(devopts_generic), | |
e90551c3 | 232 | 2500 * 1000, 0, 0, 0, FALSE, |
a0418c20 | 233 | NULL, NULL, NULL, |
d0b602f0 TK |
234 | }, |
235 | { | |
236 | "GW", "GDM8255A", | |
237 | 1, 6, cmdset_gwinstek, ARRAY_AND_SIZE(mqopts_gwinstek_gdm8200a), | |
238 | scpi_dmm_get_meas_gwinstek, | |
239 | ARRAY_AND_SIZE(devopts_generic), | |
e90551c3 | 240 | 2500 * 1000, 0, 0, 0, FALSE, |
a0418c20 | 241 | NULL, NULL, NULL, |
d0b602f0 | 242 | }, |
868fc65e TK |
243 | { |
244 | "GWInstek", "GDM9060", | |
245 | 1, 6, cmdset_gwinstek_906x, ARRAY_AND_SIZE(mqopts_gwinstek_gdm906x), | |
246 | scpi_dmm_get_meas_agilent, | |
247 | ARRAY_AND_SIZE(devopts_generic), | |
e90551c3 | 248 | 0, 0, 0, 0, FALSE, |
a0418c20 | 249 | NULL, NULL, NULL, |
868fc65e TK |
250 | }, |
251 | { | |
252 | "GWInstek", "GDM9061", | |
253 | 1, 6, cmdset_gwinstek_906x, ARRAY_AND_SIZE(mqopts_gwinstek_gdm906x), | |
254 | scpi_dmm_get_meas_agilent, | |
255 | ARRAY_AND_SIZE(devopts_generic), | |
e90551c3 | 256 | 0, 0, 0, 0, FALSE, |
a0418c20 | 257 | NULL, NULL, NULL, |
868fc65e | 258 | }, |
25879a34 GS |
259 | { |
260 | "HP", "34401A", | |
261 | 1, 6, cmdset_hp, ARRAY_AND_SIZE(mqopts_agilent_34401a), | |
262 | scpi_dmm_get_meas_agilent, | |
263 | ARRAY_AND_SIZE(devopts_generic), | |
264 | /* 34401A: typ. 1020ms for AC readings (default is 1000ms). */ | |
e90551c3 | 265 | 1500 * 1000, 0, 0, 0, FALSE, |
a0418c20 | 266 | NULL, NULL, NULL, |
25879a34 GS |
267 | }, |
268 | { | |
269 | "Keysight", "34465A", | |
e3c85285 | 270 | 1, 6, cmdset_agilent, ARRAY_AND_SIZE(mqopts_agilent_34405a), |
25879a34 | 271 | scpi_dmm_get_meas_agilent, |
a0418c20 | 272 | ARRAY_AND_SIZE(devopts_generic_range), |
18426d1c | 273 | 0, 0, 10 * 1000, 0, FALSE, |
a0418c20 | 274 | scpi_dmm_get_range_text, scpi_dmm_set_range_from_text, NULL, |
25879a34 | 275 | }, |
2111d157 PA |
276 | { |
277 | "OWON", "XDM2041", | |
278 | 1, 5, cmdset_owon, ARRAY_AND_SIZE(mqopts_owon_xdm2041), | |
279 | scpi_dmm_get_meas_gwinstek, | |
280 | ARRAY_AND_SIZE(devopts_generic), | |
e90551c3 | 281 | 0, 0, 0, 1e9, TRUE, |
a0418c20 | 282 | NULL, NULL, NULL, |
2111d157 | 283 | }, |
3cdad416 GS |
284 | }; |
285 | ||
286 | static const struct scpi_dmm_model *is_compatible(const char *vendor, const char *model) | |
7a396ff5 | 287 | { |
3cdad416 GS |
288 | size_t i; |
289 | const struct scpi_dmm_model *entry; | |
290 | ||
291 | for (i = 0; i < ARRAY_SIZE(models); i++) { | |
292 | entry = &models[i]; | |
293 | if (!entry->vendor || !entry->model) | |
294 | continue; | |
295 | if (strcmp(vendor, entry->vendor) != 0) | |
296 | continue; | |
297 | if (strcmp(model, entry->model) != 0) | |
298 | continue; | |
299 | return entry; | |
300 | } | |
7a396ff5 | 301 | |
3cdad416 GS |
302 | return NULL; |
303 | } | |
7a396ff5 | 304 | |
ddeaa49d PA |
305 | /* |
306 | * Some devices (such as Owon XDM2041) do not support the standard | |
307 | * OPeration Complete? command. This function tests the command with | |
308 | * a short timeout, and returns TRUE if any reply (busy or not) is received. | |
309 | */ | |
310 | static gboolean probe_opc_support(struct sr_scpi_dev_inst *scpi) | |
311 | { | |
312 | gboolean result; | |
313 | GString *response; | |
314 | ||
315 | response = g_string_sized_new(128); | |
316 | result = TRUE; | |
317 | if (sr_scpi_get_data(scpi, SCPI_CMD_OPC, &response) != SR_OK) | |
318 | result = FALSE; | |
319 | g_string_free(response, TRUE); | |
320 | ||
321 | return result; | |
322 | } | |
323 | ||
3cdad416 GS |
324 | static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi) |
325 | { | |
326 | struct sr_scpi_hw_info *hw_info; | |
327 | int ret; | |
328 | const char *vendor; | |
329 | const struct scpi_dmm_model *model; | |
330 | struct sr_dev_inst *sdi; | |
331 | struct dev_context *devc; | |
332 | size_t i; | |
333 | gchar *channel_name; | |
4c80a272 | 334 | const char *command; |
3cdad416 | 335 | |
28877994 | 336 | ret = sr_scpi_get_hw_id(scpi, &hw_info); |
3cdad416 GS |
337 | if (ret != SR_OK) { |
338 | sr_info("Could not get IDN response."); | |
339 | return NULL; | |
340 | } | |
341 | vendor = sr_vendor_alias(hw_info->manufacturer); | |
342 | model = is_compatible(vendor, hw_info->model); | |
343 | if (!model) { | |
344 | sr_scpi_hw_info_free(hw_info); | |
345 | return NULL; | |
346 | } | |
7a396ff5 | 347 | |
cae328b5 GS |
348 | if (model->check_opc && !probe_opc_support(scpi)) |
349 | scpi->no_opc_command = TRUE; | |
350 | ||
3cdad416 GS |
351 | sdi = g_malloc0(sizeof(*sdi)); |
352 | sdi->vendor = g_strdup(hw_info->manufacturer); | |
353 | sdi->model = g_strdup(hw_info->model); | |
354 | sdi->version = g_strdup(hw_info->firmware_version); | |
355 | sdi->serial_num = g_strdup(hw_info->serial_number); | |
356 | sdi->conn = scpi; | |
357 | sdi->driver = &scpi_dmm_driver_info; | |
358 | sdi->inst_type = SR_INST_SCPI; | |
7d95afb9 GS |
359 | ret = sr_scpi_connection_id(scpi, &sdi->connection_id); |
360 | if (ret != SR_OK) { | |
361 | g_free(sdi->connection_id); | |
362 | sdi->connection_id = NULL; | |
363 | } | |
3cdad416 | 364 | sr_scpi_hw_info_free(hw_info); |
1c8110db | 365 | if (model->read_timeout_us) /* non-default read timeout */ |
a1619831 | 366 | scpi->read_timeout_us = model->read_timeout_us; |
3cdad416 GS |
367 | devc = g_malloc0(sizeof(*devc)); |
368 | sdi->priv = devc; | |
369 | devc->num_channels = model->num_channels; | |
370 | devc->cmdset = model->cmdset; | |
371 | devc->model = model; | |
372 | ||
373 | for (i = 0; i < devc->num_channels; i++) { | |
374 | channel_name = g_strdup_printf("P%zu", i + 1); | |
375 | sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, channel_name); | |
376 | } | |
377 | ||
4c80a272 TK |
378 | /* |
379 | * If device has DMM_CMD_SETUP_LOCAL command, send it now. To avoid | |
380 | * leaving device in remote mode (if only a "scan" is run). | |
381 | */ | |
382 | command = sr_scpi_cmd_get(devc->cmdset, DMM_CMD_SETUP_LOCAL); | |
383 | if (command && *command) { | |
384 | scpi_dmm_cmd_delay(scpi); | |
385 | sr_scpi_send(scpi, command); | |
386 | } | |
387 | ||
3cdad416 GS |
388 | return sdi; |
389 | } | |
7a396ff5 | 390 | |
3cdad416 GS |
391 | static GSList *scan(struct sr_dev_driver *di, GSList *options) |
392 | { | |
393 | return sr_scpi_scan(di->context, options, probe_device); | |
7a396ff5 GS |
394 | } |
395 | ||
396 | static int dev_open(struct sr_dev_inst *sdi) | |
397 | { | |
3cdad416 GS |
398 | struct sr_scpi_dev_inst *scpi; |
399 | int ret; | |
7a396ff5 | 400 | |
3cdad416 GS |
401 | scpi = sdi->conn; |
402 | ret = sr_scpi_open(scpi); | |
403 | if (ret < 0) { | |
404 | sr_err("Failed to open SCPI device: %s.", sr_strerror(ret)); | |
405 | return SR_ERR; | |
406 | } | |
7a396ff5 GS |
407 | |
408 | return SR_OK; | |
409 | } | |
410 | ||
411 | static int dev_close(struct sr_dev_inst *sdi) | |
412 | { | |
4c80a272 | 413 | struct dev_context *devc; |
3cdad416 | 414 | struct sr_scpi_dev_inst *scpi; |
4c80a272 | 415 | const char *command; |
7a396ff5 | 416 | |
4c80a272 | 417 | devc = sdi->priv; |
3cdad416 GS |
418 | scpi = sdi->conn; |
419 | if (!scpi) | |
420 | return SR_ERR_BUG; | |
7a396ff5 | 421 | |
3cdad416 GS |
422 | sr_dbg("DIAG: sdi->status %d.", sdi->status - SR_ST_NOT_FOUND); |
423 | if (sdi->status <= SR_ST_INACTIVE) | |
424 | return SR_OK; | |
425 | ||
4c80a272 TK |
426 | /* |
427 | * If device has DMM_CMD_SETUP_LOCAL command, send it now | |
428 | * to avoid leaving device in remote mode. | |
429 | */ | |
430 | command = sr_scpi_cmd_get(devc->cmdset, DMM_CMD_SETUP_LOCAL); | |
431 | if (command && *command) { | |
432 | scpi_dmm_cmd_delay(scpi); | |
433 | sr_scpi_send(scpi, command); | |
434 | } | |
435 | ||
3cdad416 | 436 | return sr_scpi_close(scpi); |
7a396ff5 GS |
437 | } |
438 | ||
439 | static int config_get(uint32_t key, GVariant **data, | |
440 | const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) | |
441 | { | |
3cdad416 GS |
442 | struct dev_context *devc; |
443 | enum sr_mq mq; | |
444 | enum sr_mqflag mqflag; | |
445 | GVariant *arr[2]; | |
7a396ff5 | 446 | int ret; |
a0418c20 | 447 | const char *range; |
7a396ff5 | 448 | |
7a396ff5 GS |
449 | (void)cg; |
450 | ||
3cdad416 GS |
451 | devc = sdi->priv; |
452 | ||
7a396ff5 | 453 | switch (key) { |
7d95afb9 GS |
454 | case SR_CONF_CONN: |
455 | if (!sdi || !sdi->connection_id) | |
456 | return SR_ERR_NA; | |
457 | *data = g_variant_new_string(sdi->connection_id); | |
458 | return SR_OK; | |
3cdad416 GS |
459 | case SR_CONF_LIMIT_SAMPLES: |
460 | case SR_CONF_LIMIT_MSEC: | |
461 | return sr_sw_limits_config_get(&devc->limits, key, data); | |
462 | case SR_CONF_MEASURED_QUANTITY: | |
08f3b427 | 463 | ret = scpi_dmm_get_mq(sdi, &mq, &mqflag, NULL, NULL); |
3cdad416 GS |
464 | if (ret != SR_OK) |
465 | return ret; | |
466 | arr[0] = g_variant_new_uint32(mq); | |
467 | arr[1] = g_variant_new_uint64(mqflag); | |
468 | *data = g_variant_new_tuple(arr, ARRAY_SIZE(arr)); | |
469 | return SR_OK; | |
a0418c20 GS |
470 | case SR_CONF_RANGE: |
471 | if (!devc || !devc->model->get_range_text) | |
472 | return SR_ERR_NA; | |
473 | range = devc->model->get_range_text(sdi); | |
474 | if (!range || !*range) | |
475 | return SR_ERR_NA; | |
476 | *data = g_variant_new_string(range); | |
477 | return SR_OK; | |
7a396ff5 GS |
478 | default: |
479 | return SR_ERR_NA; | |
480 | } | |
7a396ff5 GS |
481 | } |
482 | ||
483 | static int config_set(uint32_t key, GVariant *data, | |
484 | const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) | |
485 | { | |
3cdad416 GS |
486 | struct dev_context *devc; |
487 | enum sr_mq mq; | |
488 | enum sr_mqflag mqflag; | |
489 | GVariant *tuple_child; | |
a0418c20 | 490 | const char *range; |
7a396ff5 | 491 | |
7a396ff5 GS |
492 | (void)cg; |
493 | ||
3cdad416 GS |
494 | devc = sdi->priv; |
495 | ||
7a396ff5 | 496 | switch (key) { |
3cdad416 GS |
497 | case SR_CONF_LIMIT_SAMPLES: |
498 | case SR_CONF_LIMIT_MSEC: | |
499 | return sr_sw_limits_config_set(&devc->limits, key, data); | |
500 | case SR_CONF_MEASURED_QUANTITY: | |
501 | tuple_child = g_variant_get_child_value(data, 0); | |
502 | mq = g_variant_get_uint32(tuple_child); | |
ff5fb185 | 503 | g_variant_unref(tuple_child); |
3cdad416 GS |
504 | tuple_child = g_variant_get_child_value(data, 1); |
505 | mqflag = g_variant_get_uint64(tuple_child); | |
506 | g_variant_unref(tuple_child); | |
507 | return scpi_dmm_set_mq(sdi, mq, mqflag); | |
a0418c20 GS |
508 | case SR_CONF_RANGE: |
509 | if (!devc || !devc->model->set_range_from_text) | |
510 | return SR_ERR_NA; | |
511 | range = g_variant_get_string(data, NULL); | |
512 | return devc->model->set_range_from_text(sdi, range); | |
7a396ff5 | 513 | default: |
3cdad416 | 514 | return SR_ERR_NA; |
7a396ff5 | 515 | } |
7a396ff5 GS |
516 | } |
517 | ||
518 | static int config_list(uint32_t key, GVariant **data, | |
519 | const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) | |
520 | { | |
3cdad416 GS |
521 | struct dev_context *devc; |
522 | GVariant *gvar, *arr[2]; | |
523 | GVariantBuilder gvb; | |
524 | size_t i; | |
7a396ff5 | 525 | |
7a396ff5 GS |
526 | (void)cg; |
527 | ||
3cdad416 GS |
528 | devc = sdi ? sdi->priv : NULL; |
529 | ||
7a396ff5 | 530 | switch (key) { |
3cdad416 GS |
531 | case SR_CONF_SCAN_OPTIONS: |
532 | case SR_CONF_DEVICE_OPTIONS: | |
1d2f9963 GS |
533 | if (!devc) |
534 | return STD_CONFIG_LIST(key, data, sdi, cg, | |
535 | scanopts, drvopts, devopts_generic); | |
536 | return std_opts_config_list(key, data, sdi, cg, | |
537 | ARRAY_AND_SIZE(scanopts), ARRAY_AND_SIZE(drvopts), | |
538 | devc->model->devopts, devc->model->devopts_size); | |
3cdad416 GS |
539 | case SR_CONF_MEASURED_QUANTITY: |
540 | /* TODO Use std_gvar_measured_quantities() when available. */ | |
541 | if (!devc) | |
542 | return SR_ERR_ARG; | |
543 | g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY); | |
544 | for (i = 0; i < devc->model->mqopt_size; i++) { | |
545 | arr[0] = g_variant_new_uint32(devc->model->mqopts[i].mq); | |
546 | arr[1] = g_variant_new_uint64(devc->model->mqopts[i].mqflag); | |
547 | gvar = g_variant_new_tuple(arr, ARRAY_SIZE(arr)); | |
548 | g_variant_builder_add_value(&gvb, gvar); | |
549 | } | |
550 | *data = g_variant_builder_end(&gvb); | |
551 | return SR_OK; | |
a0418c20 GS |
552 | case SR_CONF_RANGE: |
553 | if (!devc || !devc->model->get_range_text_list) | |
554 | return SR_ERR_NA; | |
555 | *data = devc->model->get_range_text_list(sdi); | |
556 | return SR_OK; | |
7a396ff5 | 557 | default: |
3cdad416 | 558 | (void)devc; |
7a396ff5 GS |
559 | return SR_ERR_NA; |
560 | } | |
7a396ff5 GS |
561 | } |
562 | ||
563 | static int dev_acquisition_start(const struct sr_dev_inst *sdi) | |
564 | { | |
3cdad416 GS |
565 | struct sr_scpi_dev_inst *scpi; |
566 | struct dev_context *devc; | |
567 | int ret; | |
08f3b427 | 568 | const struct mqopt_item *item; |
3cdad416 | 569 | const char *command; |
d0b602f0 | 570 | char *response; |
e90551c3 | 571 | gboolean do_mq_meas_delay; |
3cdad416 GS |
572 | |
573 | scpi = sdi->conn; | |
574 | devc = sdi->priv; | |
575 | ||
576 | ret = scpi_dmm_get_mq(sdi, &devc->start_acq_mq.curr_mq, | |
08f3b427 | 577 | &devc->start_acq_mq.curr_mqflag, NULL, &item); |
3cdad416 GS |
578 | if (ret != SR_OK) |
579 | return ret; | |
580 | ||
d0b602f0 TK |
581 | /* |
582 | * Query for current precision if DMM supports the command | |
583 | */ | |
584 | command = sr_scpi_cmd_get(devc->cmdset, DMM_CMD_QUERY_PREC); | |
585 | if (command && *command) { | |
586 | scpi_dmm_cmd_delay(scpi); | |
587 | ret = sr_scpi_get_string(scpi, command, &response); | |
588 | if (ret == SR_OK) { | |
589 | g_strstrip(response); | |
33aa8117 GS |
590 | g_free(devc->precision); |
591 | devc->precision = g_strdup(response); | |
d0b602f0 TK |
592 | g_free(response); |
593 | sr_dbg("%s: Precision: '%s'", __func__, devc->precision); | |
594 | } else { | |
33aa8117 GS |
595 | sr_info("Precision query ('%s') failed: %d", |
596 | command, ret); | |
d0b602f0 TK |
597 | } |
598 | } | |
599 | ||
3cdad416 GS |
600 | command = sr_scpi_cmd_get(devc->cmdset, DMM_CMD_START_ACQ); |
601 | if (command && *command) { | |
3cdad416 | 602 | scpi_dmm_cmd_delay(scpi); |
28877994 | 603 | ret = sr_scpi_send(scpi, command); |
3cdad416 GS |
604 | if (ret != SR_OK) |
605 | return ret; | |
606 | } | |
7a396ff5 | 607 | |
e90551c3 GS |
608 | do_mq_meas_delay = item->drv_flags & FLAG_MEAS_DELAY; |
609 | if (do_mq_meas_delay && devc->model->meas_delay_us) | |
610 | g_usleep(devc->model->meas_delay_us); | |
611 | ||
3cdad416 GS |
612 | sr_sw_limits_acquisition_start(&devc->limits); |
613 | ret = std_session_send_df_header(sdi); | |
614 | if (ret != SR_OK) | |
615 | return ret; | |
616 | ||
617 | ret = sr_scpi_source_add(sdi->session, scpi, G_IO_IN, 10, | |
618 | scpi_dmm_receive_data, (void *)sdi); | |
619 | if (ret != SR_OK) | |
620 | return ret; | |
7a396ff5 GS |
621 | |
622 | return SR_OK; | |
623 | } | |
624 | ||
625 | static int dev_acquisition_stop(struct sr_dev_inst *sdi) | |
626 | { | |
3cdad416 GS |
627 | struct sr_scpi_dev_inst *scpi; |
628 | struct dev_context *devc; | |
629 | const char *command; | |
630 | ||
631 | scpi = sdi->conn; | |
632 | devc = sdi->priv; | |
7a396ff5 | 633 | |
3cdad416 GS |
634 | command = sr_scpi_cmd_get(devc->cmdset, DMM_CMD_STOP_ACQ); |
635 | if (command && *command) { | |
3cdad416 | 636 | scpi_dmm_cmd_delay(scpi); |
28877994 | 637 | (void)sr_scpi_send(scpi, command); |
3cdad416 GS |
638 | } |
639 | sr_scpi_source_remove(sdi->session, scpi); | |
640 | ||
641 | std_session_send_df_end(sdi); | |
7a396ff5 | 642 | |
33aa8117 GS |
643 | g_free(devc->precision); |
644 | devc->precision = NULL; | |
d0b602f0 | 645 | |
7a396ff5 GS |
646 | return SR_OK; |
647 | } | |
648 | ||
0617bb5a | 649 | static struct sr_dev_driver scpi_dmm_driver_info = { |
7a396ff5 GS |
650 | .name = "scpi-dmm", |
651 | .longname = "SCPI DMM", | |
652 | .api_version = 1, | |
653 | .init = std_init, | |
654 | .cleanup = std_cleanup, | |
655 | .scan = scan, | |
656 | .dev_list = std_dev_list, | |
657 | .dev_clear = std_dev_clear, | |
658 | .config_get = config_get, | |
659 | .config_set = config_set, | |
660 | .config_list = config_list, | |
661 | .dev_open = dev_open, | |
662 | .dev_close = dev_close, | |
663 | .dev_acquisition_start = dev_acquisition_start, | |
664 | .dev_acquisition_stop = dev_acquisition_stop, | |
665 | .context = NULL, | |
666 | }; | |
7a396ff5 | 667 | SR_REGISTER_DEV_DRIVER(scpi_dmm_driver_info); |