]> sigrok.org Git - libsigrok.git/blob - src/hardware/scpi-pps/profiles.c
Consistently use the "Sysclk" spelling everywhere.
[libsigrok.git] / src / hardware / scpi-pps / profiles.c
1 /*
2  * This file is part of the libsigrok project.
3  *
4  * Copyright (C) 2014 Bert Vermeulen <bert@biot.com>
5  * Copyright (C) 2015 Google, Inc.
6  * (Written by Alexandru Gagniuc <mrnuke@google.com> for Google, Inc.)
7  * Copyright (C) 2017,2019 Frank Stettner <frank-stettner@gmx.net>
8  *
9  * This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21  */
22
23 #include <config.h>
24 #include <string.h>
25 #include <strings.h>
26 #include "protocol.h"
27
28 #define CH_IDX(x) (1 << x)
29 #define FREQ_DC_ONLY {0, 0, 0, 0, 0}
30 #define NO_OVP_LIMITS {0, 0, 0, 0, 0}
31 #define NO_OCP_LIMITS {0, 0, 0, 0, 0}
32
33 /* Agilent/Keysight N5700A series */
34 static const uint32_t agilent_n5700a_devopts[] = {
35         SR_CONF_CONTINUOUS,
36         SR_CONF_LIMIT_SAMPLES | SR_CONF_GET | SR_CONF_SET,
37         SR_CONF_LIMIT_MSEC | SR_CONF_GET | SR_CONF_SET,
38 };
39
40 static const uint32_t agilent_n5700a_devopts_cg[] = {
41         SR_CONF_OVER_VOLTAGE_PROTECTION_THRESHOLD | SR_CONF_GET | SR_CONF_SET,
42         SR_CONF_OVER_CURRENT_PROTECTION_ENABLED | SR_CONF_GET | SR_CONF_SET,
43         SR_CONF_OVER_CURRENT_PROTECTION_THRESHOLD | SR_CONF_GET | SR_CONF_SET,
44         SR_CONF_VOLTAGE | SR_CONF_GET,
45         SR_CONF_VOLTAGE_TARGET | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
46         SR_CONF_CURRENT | SR_CONF_GET,
47         SR_CONF_ENABLED | SR_CONF_GET | SR_CONF_SET,
48 };
49
50 static const struct channel_group_spec agilent_n5700a_cg[] = {
51         { "1", CH_IDX(0), PPS_OVP | PPS_OCP, SR_MQFLAG_DC },
52 };
53
54 static const struct channel_spec agilent_n5767a_ch[] = {
55         { "1", { 0, 60, 0.0072, 3, 4 }, { 0, 25, 0.003, 3, 4 }, { 0, 1500 }, FREQ_DC_ONLY, NO_OVP_LIMITS, NO_OCP_LIMITS },
56 };
57
58 static const struct channel_spec agilent_n5763a_ch[] = {
59         { "1", { 0, 12.5, 0.0015, 3, 4 }, { 0, 120, 0.0144, 3, 4 }, { 0, 1500 }, FREQ_DC_ONLY, NO_OVP_LIMITS, NO_OCP_LIMITS },
60 };
61
62 /*
63  * TODO: OVER_CURRENT_PROTECTION_ACTIVE status can be determined by the OC bit
64  * in STAT:QUES:EVEN?, but this is not implemented.
65  */
66 static const struct scpi_command agilent_n5700a_cmd[] = {
67         { SCPI_CMD_REMOTE, "SYST:COMM:RLST REM" },
68         { SCPI_CMD_LOCAL, "SYST:COMM:RLST LOC" },
69         { SCPI_CMD_GET_MEAS_VOLTAGE, ":MEAS:VOLT?" },
70         { SCPI_CMD_GET_MEAS_CURRENT, "MEAS:CURR?" },
71         { SCPI_CMD_GET_VOLTAGE_TARGET, ":SOUR:VOLT?" },
72         { SCPI_CMD_SET_VOLTAGE_TARGET, ":SOUR:VOLT %.6f" },
73         { SCPI_CMD_GET_CURRENT_LIMIT, ":SOUR:CURR?" },
74         { SCPI_CMD_SET_CURRENT_LIMIT, ":SOUR:CURR %.6f" },
75         { SCPI_CMD_GET_OUTPUT_ENABLED, ":OUTP:STAT?" },
76         { SCPI_CMD_SET_OUTPUT_ENABLE, ":OUTP ON" },
77         { SCPI_CMD_SET_OUTPUT_DISABLE, ":OUTP OFF" },
78         { SCPI_CMD_GET_OVER_VOLTAGE_PROTECTION_THRESHOLD, ":VOLT:PROT?" },
79         { SCPI_CMD_SET_OVER_VOLTAGE_PROTECTION_THRESHOLD, ":VOLT:PROT %.6f" },
80         { SCPI_CMD_GET_OVER_CURRENT_PROTECTION_ENABLED, ":CURR:PROT:STAT?" },
81         { SCPI_CMD_SET_OVER_CURRENT_PROTECTION_ENABLE, ":CURR:PROT:STAT ON?"},
82         { SCPI_CMD_SET_OVER_CURRENT_PROTECTION_DISABLE, ":CURR:PROT:STAT OFF?"},
83         /* Current limit (CC mode) and OCP are set using the same command. */
84         { SCPI_CMD_GET_OVER_CURRENT_PROTECTION_THRESHOLD, ":SOUR:CURR?" },
85         { SCPI_CMD_SET_OVER_CURRENT_PROTECTION_THRESHOLD, ":SOUR:CURR %.6f" },
86         ALL_ZERO
87 };
88
89 /* BK Precision 9130 series */
90 static const uint32_t bk_9130_devopts[] = {
91         SR_CONF_CONTINUOUS,
92         SR_CONF_LIMIT_SAMPLES | SR_CONF_GET | SR_CONF_SET,
93         SR_CONF_LIMIT_MSEC | SR_CONF_GET | SR_CONF_SET,
94 };
95
96 static const uint32_t bk_9130_devopts_cg[] = {
97         SR_CONF_OVER_VOLTAGE_PROTECTION_THRESHOLD | SR_CONF_GET | SR_CONF_SET,
98         SR_CONF_VOLTAGE | SR_CONF_GET,
99         SR_CONF_VOLTAGE_TARGET | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
100         SR_CONF_CURRENT | SR_CONF_GET,
101         SR_CONF_CURRENT_LIMIT | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
102         SR_CONF_ENABLED | SR_CONF_GET | SR_CONF_SET,
103 };
104
105 static const struct channel_spec bk_9130_ch[] = {
106         { "1", { 0, 30, 0.001, 3, 3 }, { 0, 3, 0.001, 3, 3 }, { 0, 90, 0, 3, 3 }, FREQ_DC_ONLY, NO_OVP_LIMITS, NO_OCP_LIMITS },
107         { "2", { 0, 30, 0.001, 3, 3 }, { 0, 3, 0.001, 3, 3 }, { 0, 90, 0, 3, 3 }, FREQ_DC_ONLY, NO_OVP_LIMITS, NO_OCP_LIMITS },
108         { "3", { 0,  5, 0.001, 3, 3 }, { 0, 3, 0.001, 3, 3 }, { 0, 15, 0, 3, 3 }, FREQ_DC_ONLY, NO_OVP_LIMITS, NO_OCP_LIMITS },
109 };
110
111 static const struct channel_group_spec bk_9130_cg[] = {
112         { "1", CH_IDX(0), PPS_OVP, SR_MQFLAG_DC },
113         { "2", CH_IDX(1), PPS_OVP, SR_MQFLAG_DC },
114         { "3", CH_IDX(2), PPS_OVP, SR_MQFLAG_DC },
115 };
116
117 static const struct scpi_command bk_9130_cmd[] = {
118         { SCPI_CMD_REMOTE, "SYST:REMOTE" },
119         { SCPI_CMD_LOCAL, "SYST:LOCAL" },
120         { SCPI_CMD_SELECT_CHANNEL, ":INST:NSEL %s" },
121         { SCPI_CMD_GET_MEAS_VOLTAGE, ":MEAS:VOLT?" },
122         { SCPI_CMD_GET_MEAS_CURRENT, ":MEAS:CURR?" },
123         { SCPI_CMD_GET_MEAS_POWER, ":MEAS:POWER?" },
124         { SCPI_CMD_GET_VOLTAGE_TARGET, ":SOUR:VOLT?" },
125         { SCPI_CMD_SET_VOLTAGE_TARGET, ":SOUR:VOLT %.6f" },
126         { SCPI_CMD_GET_CURRENT_LIMIT, ":SOUR:CURR?" },
127         { SCPI_CMD_SET_CURRENT_LIMIT, ":SOUR:CURR %.6f" },
128         { SCPI_CMD_GET_OUTPUT_ENABLED, ":OUTP?" },
129         { SCPI_CMD_SET_OUTPUT_ENABLE, ":OUTP 1" },
130         { SCPI_CMD_SET_OUTPUT_DISABLE, ":OUTP 0" },
131         { SCPI_CMD_GET_OVER_VOLTAGE_PROTECTION_THRESHOLD, ":SOUR:VOLT:PROT?" },
132         { SCPI_CMD_SET_OVER_VOLTAGE_PROTECTION_THRESHOLD, ":SOUR:VOLT:PROT %.6f" },
133         ALL_ZERO
134 };
135
136 /* Chroma 61600 series AC source */
137 static const uint32_t chroma_61604_devopts[] = {
138         SR_CONF_CONTINUOUS,
139         SR_CONF_LIMIT_SAMPLES | SR_CONF_GET | SR_CONF_SET,
140         SR_CONF_LIMIT_MSEC | SR_CONF_GET | SR_CONF_SET,
141 };
142
143 static const uint32_t chroma_61604_devopts_cg[] = {
144         SR_CONF_OVER_VOLTAGE_PROTECTION_THRESHOLD | SR_CONF_GET | SR_CONF_SET,
145         SR_CONF_OVER_CURRENT_PROTECTION_THRESHOLD | SR_CONF_GET | SR_CONF_SET,
146         SR_CONF_VOLTAGE | SR_CONF_GET,
147         SR_CONF_VOLTAGE_TARGET | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
148         SR_CONF_OUTPUT_FREQUENCY | SR_CONF_GET,
149         SR_CONF_OUTPUT_FREQUENCY_TARGET | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
150         SR_CONF_CURRENT | SR_CONF_GET,
151         SR_CONF_ENABLED | SR_CONF_GET | SR_CONF_SET,
152 };
153
154 static const struct channel_spec chroma_61604_ch[] = {
155         { "1", { 0, 300, 0.1, 1, 1 }, { 0, 16, 0.1, 2, 2 }, { 0, 2000, 0, 1, 1 }, { 1.0, 1000.0, 0.01 }, NO_OVP_LIMITS, NO_OCP_LIMITS },
156 };
157
158 static const struct channel_group_spec chroma_61604_cg[] = {
159         { "1", CH_IDX(0), PPS_OVP | PPS_OCP, SR_MQFLAG_AC },
160 };
161
162 static const struct scpi_command chroma_61604_cmd[] = {
163         { SCPI_CMD_REMOTE, "SYST:REM" },
164         { SCPI_CMD_LOCAL, "SYST:LOC" },
165         { SCPI_CMD_GET_MEAS_VOLTAGE, ":FETC:VOLT:ACDC?" },
166         { SCPI_CMD_GET_MEAS_FREQUENCY, ":FETC:FREQ?" },
167         { SCPI_CMD_GET_MEAS_CURRENT, ":FETC:CURR:AC?" },
168         { SCPI_CMD_GET_MEAS_POWER, ":FETC:POW:AC?" },
169         { SCPI_CMD_GET_VOLTAGE_TARGET, ":SOUR:VOLT:AC?" },
170         { SCPI_CMD_SET_VOLTAGE_TARGET, ":SOUR:VOLT:AC %.1f" },
171         { SCPI_CMD_GET_FREQUENCY_TARGET, ":SOUR:FREQ?" },
172         { SCPI_CMD_SET_FREQUENCY_TARGET, ":SOUR:FREQ %.2f" },
173         { SCPI_CMD_GET_OUTPUT_ENABLED, ":OUTP?" },
174         { SCPI_CMD_SET_OUTPUT_ENABLE, ":OUTP ON" },
175         { SCPI_CMD_SET_OUTPUT_DISABLE, ":OUTP OFF" },
176         { SCPI_CMD_GET_OVER_VOLTAGE_PROTECTION_THRESHOLD, ":SOUR:VOLT:LIM:AC?" },
177         { SCPI_CMD_SET_OVER_VOLTAGE_PROTECTION_THRESHOLD, ":SOUR:VOLT:LIM:AC %.1f" },
178         /* This is not a current limit mode. It is overcurrent protection. */
179         { SCPI_CMD_GET_OVER_CURRENT_PROTECTION_THRESHOLD, ":SOUR:CURR:LIM?" },
180         { SCPI_CMD_SET_OVER_CURRENT_PROTECTION_THRESHOLD, ":SOUR:CURR:LIM %.2f" },
181         ALL_ZERO
182 };
183
184 /* Chroma 62000 series DC source */
185 static const uint32_t chroma_62000_devopts[] = {
186         SR_CONF_CONTINUOUS,
187         SR_CONF_LIMIT_SAMPLES | SR_CONF_GET | SR_CONF_SET,
188         SR_CONF_LIMIT_MSEC | SR_CONF_GET | SR_CONF_SET,
189 };
190
191 static const uint32_t chroma_62000_devopts_cg[] = {
192         SR_CONF_OVER_VOLTAGE_PROTECTION_THRESHOLD | SR_CONF_GET | SR_CONF_SET,
193         SR_CONF_OVER_CURRENT_PROTECTION_THRESHOLD | SR_CONF_GET | SR_CONF_SET,
194         SR_CONF_VOLTAGE | SR_CONF_GET,
195         SR_CONF_VOLTAGE_TARGET | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
196         SR_CONF_CURRENT | SR_CONF_GET,
197         SR_CONF_CURRENT_LIMIT | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
198         SR_CONF_ENABLED | SR_CONF_GET | SR_CONF_SET,
199 };
200
201 static const struct channel_group_spec chroma_62000_cg[] = {
202         { "1", CH_IDX(0), PPS_OVP | PPS_OCP, SR_MQFLAG_DC },
203 };
204
205 static const struct scpi_command chroma_62000_cmd[] = {
206         { SCPI_CMD_REMOTE, ":CONF:REM ON" },
207         { SCPI_CMD_LOCAL, ":CONF:REM OFF" },
208         { SCPI_CMD_BEEPER, ":CONF:BEEP?" },
209         { SCPI_CMD_BEEPER_ENABLE, ":CONF:BEEP ON" },
210         { SCPI_CMD_BEEPER_DISABLE, ":CONF:BEEP OFF" },
211         { SCPI_CMD_GET_MEAS_VOLTAGE, ":MEAS:VOLT?" },
212         { SCPI_CMD_GET_MEAS_CURRENT, ":MEAS:CURR?" },
213         { SCPI_CMD_GET_MEAS_POWER, ":MEAS:POW?" },
214         { SCPI_CMD_GET_VOLTAGE_TARGET, ":SOUR:VOLT?" },
215         { SCPI_CMD_SET_VOLTAGE_TARGET, ":SOUR:VOLT %.2f" },
216         { SCPI_CMD_GET_CURRENT_LIMIT, ":SOUR:CURR?" },
217         { SCPI_CMD_SET_CURRENT_LIMIT, ":SOUR:CURR %.6f" },
218         { SCPI_CMD_GET_OUTPUT_ENABLED, ":CONF:OUTP?" },
219         { SCPI_CMD_SET_OUTPUT_ENABLE, ":CONF:OUTP ON" },
220         { SCPI_CMD_SET_OUTPUT_DISABLE, ":CONF:OUTP OFF" },
221         { SCPI_CMD_GET_OVER_VOLTAGE_PROTECTION_THRESHOLD, ":SOUR:VOLT:PROT:HIGH?" },
222         { SCPI_CMD_SET_OVER_VOLTAGE_PROTECTION_THRESHOLD, ":SOUR:VOLT:PROT:HIGH %.6f" },
223         { SCPI_CMD_GET_OVER_CURRENT_PROTECTION_THRESHOLD, ":SOUR:CURR:PROT:HIGH?" },
224         { SCPI_CMD_SET_OVER_CURRENT_PROTECTION_THRESHOLD, ":SOUR:CURR:PROT:HIGH %.6f" },
225         ALL_ZERO
226 };
227
228 static int chroma_62000p_probe_channels(struct sr_dev_inst *sdi,
229                 struct sr_scpi_hw_info *hw_info,
230                 struct channel_spec **channels, unsigned int *num_channels,
231                 struct channel_group_spec **channel_groups,
232                 unsigned int *num_channel_groups)
233 {
234         unsigned int volts, amps, watts;
235         struct channel_spec *channel;
236
237         (void)sdi;
238
239         sscanf(hw_info->model, "620%uP-%u-%u", &watts, &volts, &amps);
240         watts *= 100;
241         sr_dbg("Found device rated for %d V, %d A and %d W", volts, amps, watts);
242
243         if (volts > 600) {
244                 sr_err("Probed max voltage of %u V is out of spec.", volts);
245                 return SR_ERR_BUG;
246         }
247
248         if (amps > 120) {
249                 sr_err("Probed max current of %u A is out of spec.", amps);
250                 return SR_ERR_BUG;
251         }
252
253         if (watts > 5000) {
254                 sr_err("Probed max power of %u W is out of spec.", watts);
255                 return SR_ERR_BUG;
256         }
257
258         channel = g_malloc0(sizeof(struct channel_spec));
259         channel->name = "1";
260         channel->voltage[0] = channel->current[0] = channel->power[0] = 0.0;
261         channel->voltage[1] = volts;
262         channel->current[1] = amps;
263         channel->power[1]   = watts;
264         channel->voltage[2] = channel->current[2] = 0.01;
265         channel->voltage[3] = channel->voltage[4] = 3;
266         channel->current[3] = channel->current[4] = 4;
267         *channels = channel;
268         *num_channels = 1;
269
270         *channel_groups = g_malloc(sizeof(struct channel_group_spec));
271         **channel_groups = chroma_62000_cg[0];
272         *num_channel_groups = 1;
273
274         return SR_OK;
275 }
276
277 /* Rigol DP700 series */
278 static const uint32_t rigol_dp700_devopts[] = {
279         SR_CONF_CONTINUOUS,
280         SR_CONF_LIMIT_SAMPLES | SR_CONF_GET | SR_CONF_SET,
281         SR_CONF_LIMIT_MSEC | SR_CONF_GET | SR_CONF_SET,
282 };
283
284 static const uint32_t rigol_dp700_devopts_cg[] = {
285         SR_CONF_REGULATION | SR_CONF_GET,
286         SR_CONF_OVER_VOLTAGE_PROTECTION_ENABLED | SR_CONF_GET | SR_CONF_SET,
287         SR_CONF_OVER_VOLTAGE_PROTECTION_ACTIVE | SR_CONF_GET,
288         SR_CONF_OVER_VOLTAGE_PROTECTION_THRESHOLD | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
289         SR_CONF_OVER_CURRENT_PROTECTION_ENABLED | SR_CONF_GET | SR_CONF_SET,
290         SR_CONF_OVER_CURRENT_PROTECTION_ACTIVE | SR_CONF_GET,
291         SR_CONF_OVER_CURRENT_PROTECTION_THRESHOLD | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
292         SR_CONF_VOLTAGE | SR_CONF_GET,
293         SR_CONF_VOLTAGE_TARGET | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
294         SR_CONF_CURRENT | SR_CONF_GET,
295         SR_CONF_CURRENT_LIMIT | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
296         SR_CONF_ENABLED | SR_CONF_GET | SR_CONF_SET,
297 };
298
299 static const struct channel_spec rigol_dp711_ch[] = {
300         { "1", { 0, 30, 0.01, 3, 3 }, { 0, 5, 0.01, 3, 3 }, { 0, 150, 0, 3, 3 }, FREQ_DC_ONLY, { 0.01, 33, 0.01}, { 0.01, 5.5, 0.01 } },
301 };
302
303 static const struct channel_spec rigol_dp712_ch[] = {
304         { "1", { 0, 50, 0.01, 3, 3 }, { 0, 3, 0.01, 3, 3 }, { 0, 150, 0, 3, 3 }, FREQ_DC_ONLY, { 0.01, 55, 0.01}, { 0.01, 3.3, 0.01 } },
305 };
306
307 static const struct channel_group_spec rigol_dp700_cg[] = {
308         { "1", CH_IDX(0), PPS_OVP | PPS_OCP, SR_MQFLAG_DC },
309 };
310
311 /* Same as the DP800 series, except for the missing :SYST:OTP* commands. */
312 static const struct scpi_command rigol_dp700_cmd[] = {
313         { SCPI_CMD_REMOTE, "SYST:REMOTE" },
314         { SCPI_CMD_LOCAL, "SYST:LOCAL" },
315         { SCPI_CMD_BEEPER, "SYST:BEEP:STAT?" },
316         { SCPI_CMD_BEEPER_ENABLE, "SYST:BEEP:STAT ON" },
317         { SCPI_CMD_BEEPER_DISABLE, "SYST:BEEP:STAT OFF" },
318         { SCPI_CMD_SELECT_CHANNEL, ":INST:NSEL %s" },
319         { SCPI_CMD_GET_MEAS_VOLTAGE, ":MEAS:VOLT?" },
320         { SCPI_CMD_GET_MEAS_CURRENT, ":MEAS:CURR?" },
321         { SCPI_CMD_GET_MEAS_POWER, ":MEAS:POWE?" },
322         { SCPI_CMD_GET_VOLTAGE_TARGET, ":SOUR:VOLT?" },
323         { SCPI_CMD_SET_VOLTAGE_TARGET, ":SOUR:VOLT %.6f" },
324         { SCPI_CMD_GET_CURRENT_LIMIT, ":SOUR:CURR?" },
325         { SCPI_CMD_SET_CURRENT_LIMIT, ":SOUR:CURR %.6f" },
326         { SCPI_CMD_GET_OUTPUT_ENABLED, ":OUTP?" },
327         { SCPI_CMD_SET_OUTPUT_ENABLE, ":OUTP ON" },
328         { SCPI_CMD_SET_OUTPUT_DISABLE, ":OUTP OFF" },
329         { SCPI_CMD_GET_OUTPUT_REGULATION, ":OUTP:MODE?" },
330         { SCPI_CMD_GET_OVER_VOLTAGE_PROTECTION_ENABLED, ":OUTP:OVP?" },
331         { SCPI_CMD_SET_OVER_VOLTAGE_PROTECTION_ENABLE, ":OUTP:OVP ON" },
332         { SCPI_CMD_SET_OVER_VOLTAGE_PROTECTION_DISABLE, ":OUTP:OVP OFF" },
333         { SCPI_CMD_GET_OVER_VOLTAGE_PROTECTION_ACTIVE, ":OUTP:OVP:QUES?" },
334         { SCPI_CMD_GET_OVER_VOLTAGE_PROTECTION_THRESHOLD, ":OUTP:OVP:VAL?" },
335         { SCPI_CMD_SET_OVER_VOLTAGE_PROTECTION_THRESHOLD, ":OUTP:OVP:VAL %.6f" },
336         { SCPI_CMD_GET_OVER_CURRENT_PROTECTION_ENABLED, ":OUTP:OCP?" },
337         { SCPI_CMD_SET_OVER_CURRENT_PROTECTION_ENABLE, ":OUTP:OCP:STAT ON" },
338         { SCPI_CMD_SET_OVER_CURRENT_PROTECTION_DISABLE, ":OUTP:OCP:STAT OFF" },
339         { SCPI_CMD_GET_OVER_CURRENT_PROTECTION_ACTIVE, ":OUTP:OCP:QUES?" },
340         { SCPI_CMD_GET_OVER_CURRENT_PROTECTION_THRESHOLD, ":OUTP:OCP:VAL?" },
341         { SCPI_CMD_SET_OVER_CURRENT_PROTECTION_THRESHOLD, ":OUTP:OCP:VAL %.6f" },
342         ALL_ZERO
343 };
344
345 /* Rigol DP800 series */
346 static const uint32_t rigol_dp800_devopts[] = {
347         SR_CONF_CONTINUOUS,
348         SR_CONF_OVER_TEMPERATURE_PROTECTION | SR_CONF_GET | SR_CONF_SET,
349         SR_CONF_LIMIT_SAMPLES | SR_CONF_GET | SR_CONF_SET,
350         SR_CONF_LIMIT_MSEC | SR_CONF_GET | SR_CONF_SET,
351 };
352
353 static const uint32_t rigol_dp800_devopts_cg[] = {
354         SR_CONF_REGULATION | SR_CONF_GET,
355         SR_CONF_OVER_VOLTAGE_PROTECTION_ENABLED | SR_CONF_GET | SR_CONF_SET,
356         SR_CONF_OVER_VOLTAGE_PROTECTION_ACTIVE | SR_CONF_GET,
357         SR_CONF_OVER_VOLTAGE_PROTECTION_THRESHOLD | SR_CONF_GET | SR_CONF_SET,
358         SR_CONF_OVER_CURRENT_PROTECTION_ENABLED | SR_CONF_GET | SR_CONF_SET,
359         SR_CONF_OVER_CURRENT_PROTECTION_ACTIVE | SR_CONF_GET,
360         SR_CONF_OVER_CURRENT_PROTECTION_THRESHOLD | SR_CONF_GET | SR_CONF_SET,
361         SR_CONF_VOLTAGE | SR_CONF_GET,
362         SR_CONF_VOLTAGE_TARGET | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
363         SR_CONF_CURRENT | SR_CONF_GET,
364         SR_CONF_CURRENT_LIMIT | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
365         SR_CONF_ENABLED | SR_CONF_GET | SR_CONF_SET,
366 };
367
368 static const struct channel_spec rigol_dp821a_ch[] = {
369         { "1", { 0, 60, 0.001, 3, 3 }, { 0, 1, 0.0001, 4, 4 }, { 0, 60, 0, 3, 4 }, FREQ_DC_ONLY, NO_OVP_LIMITS, NO_OCP_LIMITS },
370         { "2", { 0,  8, 0.001, 3, 3 }, { 0, 10, 0.001, 3, 3 }, { 0, 80, 0, 3, 3 }, FREQ_DC_ONLY, NO_OVP_LIMITS, NO_OCP_LIMITS },
371 };
372
373 static const struct channel_spec rigol_dp831_ch[] = {
374         { "1", { 0,   8, 0.001, 3, 4 }, { 0, 5, 0.0003, 3, 4 }, { 0, 40, 0, 3, 4 }, FREQ_DC_ONLY, NO_OVP_LIMITS, NO_OCP_LIMITS },
375         { "2", { 0,  30, 0.001, 3, 4 }, { 0, 2, 0.0001, 3, 4 }, { 0, 60, 0, 3, 4 }, FREQ_DC_ONLY, NO_OVP_LIMITS, NO_OCP_LIMITS },
376         { "3", { 0, -30, 0.001, 3, 4 }, { 0, 2, 0.0001, 3, 4 }, { 0, 60, 0, 3, 4 }, FREQ_DC_ONLY, NO_OVP_LIMITS, NO_OCP_LIMITS },
377 };
378
379 static const struct channel_spec rigol_dp832_ch[] = {
380         { "1", { 0, 30, 0.001, 3, 4 }, { 0, 3, 0.001, 3, 4 }, { 0, 90, 0, 3, 4 }, FREQ_DC_ONLY, NO_OVP_LIMITS, NO_OCP_LIMITS },
381         { "2", { 0, 30, 0.001, 3, 4 }, { 0, 3, 0.001, 3, 4 }, { 0, 90, 0, 3, 4 }, FREQ_DC_ONLY, NO_OVP_LIMITS, NO_OCP_LIMITS },
382         { "3", { 0,  5, 0.001, 3, 4 }, { 0, 3, 0.001, 3, 4 }, { 0, 90, 0, 3, 4 }, FREQ_DC_ONLY, NO_OVP_LIMITS, NO_OCP_LIMITS },
383 };
384
385 static const struct channel_group_spec rigol_dp820_cg[] = {
386         { "1", CH_IDX(0), PPS_OVP | PPS_OCP, SR_MQFLAG_DC },
387         { "2", CH_IDX(1), PPS_OVP | PPS_OCP, SR_MQFLAG_DC },
388 };
389
390 static const struct channel_group_spec rigol_dp830_cg[] = {
391         { "1", CH_IDX(0), PPS_OVP | PPS_OCP, SR_MQFLAG_DC },
392         { "2", CH_IDX(1), PPS_OVP | PPS_OCP, SR_MQFLAG_DC },
393         { "3", CH_IDX(2), PPS_OVP | PPS_OCP, SR_MQFLAG_DC },
394 };
395
396 static const struct scpi_command rigol_dp800_cmd[] = {
397         { SCPI_CMD_REMOTE, "SYST:REMOTE" },
398         { SCPI_CMD_LOCAL, "SYST:LOCAL" },
399         { SCPI_CMD_BEEPER, "SYST:BEEP:STAT?" },
400         { SCPI_CMD_BEEPER_ENABLE, "SYST:BEEP:STAT ON" },
401         { SCPI_CMD_BEEPER_DISABLE, "SYST:BEEP:STAT OFF" },
402         { SCPI_CMD_SELECT_CHANNEL, ":INST:NSEL %s" },
403         { SCPI_CMD_GET_MEAS_VOLTAGE, ":MEAS:VOLT?" },
404         { SCPI_CMD_GET_MEAS_CURRENT, ":MEAS:CURR?" },
405         { SCPI_CMD_GET_MEAS_POWER, ":MEAS:POWE?" },
406         { SCPI_CMD_GET_VOLTAGE_TARGET, ":SOUR:VOLT?" },
407         { SCPI_CMD_SET_VOLTAGE_TARGET, ":SOUR:VOLT %.6f" },
408         { SCPI_CMD_GET_CURRENT_LIMIT, ":SOUR:CURR?" },
409         { SCPI_CMD_SET_CURRENT_LIMIT, ":SOUR:CURR %.6f" },
410         { SCPI_CMD_GET_OUTPUT_ENABLED, ":OUTP?" },
411         { SCPI_CMD_SET_OUTPUT_ENABLE, ":OUTP ON" },
412         { SCPI_CMD_SET_OUTPUT_DISABLE, ":OUTP OFF" },
413         { SCPI_CMD_GET_OUTPUT_REGULATION, ":OUTP:MODE?" },
414         { SCPI_CMD_GET_OVER_TEMPERATURE_PROTECTION, ":SYST:OTP?" },
415         { SCPI_CMD_SET_OVER_TEMPERATURE_PROTECTION_ENABLE, ":SYST:OTP ON" },
416         { SCPI_CMD_SET_OVER_TEMPERATURE_PROTECTION_DISABLE, ":SYST:OTP OFF" },
417         { SCPI_CMD_GET_OVER_VOLTAGE_PROTECTION_ENABLED, ":OUTP:OVP?" },
418         { SCPI_CMD_SET_OVER_VOLTAGE_PROTECTION_ENABLE, ":OUTP:OVP ON" },
419         { SCPI_CMD_SET_OVER_VOLTAGE_PROTECTION_DISABLE, ":OUTP:OVP OFF" },
420         { SCPI_CMD_GET_OVER_VOLTAGE_PROTECTION_ACTIVE, ":OUTP:OVP:QUES?" },
421         { SCPI_CMD_GET_OVER_VOLTAGE_PROTECTION_THRESHOLD, ":OUTP:OVP:VAL?" },
422         { SCPI_CMD_SET_OVER_VOLTAGE_PROTECTION_THRESHOLD, ":OUTP:OVP:VAL %.6f" },
423         { SCPI_CMD_GET_OVER_CURRENT_PROTECTION_ENABLED, ":OUTP:OCP?" },
424         { SCPI_CMD_SET_OVER_CURRENT_PROTECTION_ENABLE, ":OUTP:OCP:STAT ON" },
425         { SCPI_CMD_SET_OVER_CURRENT_PROTECTION_DISABLE, ":OUTP:OCP:STAT OFF" },
426         { SCPI_CMD_GET_OVER_CURRENT_PROTECTION_ACTIVE, ":OUTP:OCP:QUES?" },
427         { SCPI_CMD_GET_OVER_CURRENT_PROTECTION_THRESHOLD, ":OUTP:OCP:VAL?" },
428         { SCPI_CMD_SET_OVER_CURRENT_PROTECTION_THRESHOLD, ":OUTP:OCP:VAL %.6f" },
429         ALL_ZERO
430 };
431
432 /* HP 663xA series */
433 static const uint32_t hp_6630a_devopts[] = {
434         SR_CONF_CONTINUOUS,
435         SR_CONF_LIMIT_SAMPLES | SR_CONF_GET | SR_CONF_SET,
436         SR_CONF_LIMIT_MSEC | SR_CONF_GET | SR_CONF_SET,
437 };
438
439 static const uint32_t hp_6630a_devopts_cg[] = {
440         SR_CONF_ENABLED | SR_CONF_SET,
441         SR_CONF_VOLTAGE | SR_CONF_GET,
442         SR_CONF_CURRENT | SR_CONF_GET,
443         SR_CONF_VOLTAGE_TARGET | SR_CONF_SET | SR_CONF_LIST,
444         SR_CONF_CURRENT_LIMIT | SR_CONF_SET | SR_CONF_LIST,
445         SR_CONF_OVER_VOLTAGE_PROTECTION_ACTIVE | SR_CONF_GET,
446         SR_CONF_OVER_VOLTAGE_PROTECTION_THRESHOLD | SR_CONF_SET | SR_CONF_LIST,
447         SR_CONF_OVER_CURRENT_PROTECTION_ENABLED | SR_CONF_SET,
448         SR_CONF_OVER_CURRENT_PROTECTION_ACTIVE | SR_CONF_GET,
449         SR_CONF_OVER_TEMPERATURE_PROTECTION_ACTIVE | SR_CONF_GET,
450         SR_CONF_REGULATION | SR_CONF_GET,
451 };
452
453 static const struct channel_spec hp_6632a_ch[] = {
454         { "1", { 0, 20.475, 0.005, 3, 4 }, { 0, 5.1188, 0.00125, 4, 5 }, { 0, 104.80743 }, FREQ_DC_ONLY, { 0, 22, 0.1 }, NO_OCP_LIMITS },
455 };
456
457 static const struct channel_spec hp_6633a_ch[] = {
458         { "1", { 0, 51.188, 0.0125, 3, 4 }, { 0, 2.0475, 0.0005, 4, 5 }, { 0, 104.80743 }, FREQ_DC_ONLY, { 0, 55, 0.25 }, NO_OCP_LIMITS },
459 };
460
461 static const struct channel_spec hp_6634a_ch[] = {
462         { "1", { 0, 102.38, 0.025, 3, 4 }, { 0, 1.0238, 0.00025, 4, 5 }, { 0, 104.81664 }, FREQ_DC_ONLY, { 0, 110, 0.5 }, NO_OCP_LIMITS },
463 };
464
465 static const struct channel_group_spec hp_6630a_cg[] = {
466         { "1", CH_IDX(0), PPS_OVP | PPS_OCP, SR_MQFLAG_DC },
467 };
468
469 static const struct scpi_command hp_6630a_cmd[] = {
470         { SCPI_CMD_SET_OUTPUT_ENABLE, "OUT 1" },
471         { SCPI_CMD_SET_OUTPUT_DISABLE, "OUT 0" },
472         { SCPI_CMD_GET_MEAS_VOLTAGE, "VOUT?" },
473         { SCPI_CMD_GET_MEAS_CURRENT, "IOUT?" },
474         { SCPI_CMD_SET_VOLTAGE_TARGET, "VSET %.4f" },
475         { SCPI_CMD_SET_CURRENT_LIMIT, "ISET %.4f" },
476         { SCPI_CMD_GET_OVER_VOLTAGE_PROTECTION_ACTIVE, "STS?" },
477         { SCPI_CMD_SET_OVER_VOLTAGE_PROTECTION_THRESHOLD, "OVSET %.4f" },
478         { SCPI_CMD_SET_OVER_CURRENT_PROTECTION_ENABLE, "OCP 1" },
479         { SCPI_CMD_SET_OVER_CURRENT_PROTECTION_DISABLE, "OCP 0" },
480         { SCPI_CMD_GET_OVER_CURRENT_PROTECTION_ACTIVE, "STS?" },
481         { SCPI_CMD_GET_OVER_TEMPERATURE_PROTECTION_ACTIVE, "STS?" },
482         { SCPI_CMD_GET_OUTPUT_REGULATION, "STS?" },
483         ALL_ZERO
484 };
485
486 static int hp_6630a_init_acquisition(const struct sr_dev_inst *sdi)
487 {
488         struct sr_scpi_dev_inst *scpi;
489
490         scpi = sdi->conn;
491
492         /*
493          * Monitor CV (1), CC+ (2), UR (4), OVP (8), OTP (16), OCP (64) and
494          * CC- (256) bits of the Status Register for the FAULT? query.
495          */
496         return sr_scpi_send(scpi, "UNMASK 607");
497 }
498
499 static int hp_6630a_update_status(const struct sr_dev_inst *sdi)
500 {
501         struct sr_scpi_dev_inst *scpi;
502         int ret;
503         int fault;
504         gboolean cv, cc_pos, unreg, cc_neg;
505         gboolean regulation_changed;
506         char *regulation;
507
508         scpi = sdi->conn;
509
510         /*
511          * Use the FAULT register (only 0->1 transitions), this way multiple set
512          * regulation bits in the STS/ASTS registers are ignored. In rare cases
513          * we will miss some changes (1->0 transitions, e.g. no regulation at all),
514          * but SPS/ASPS doesn't work either, unless all states are stored and
515          * compared to the states in STS/ASTS.
516          * TODO: Use SPoll or SRQ when SCPI over GPIB is used.
517          */
518         ret = sr_scpi_get_int(scpi, "FAULT?", &fault);
519         if (ret != SR_OK)
520                 return ret;
521
522         /* OVP */
523         if (fault & (1 << 3))
524                 sr_session_send_meta(sdi, SR_CONF_OVER_VOLTAGE_PROTECTION_ACTIVE,
525                         g_variant_new_boolean(fault & (1 << 3)));
526
527         /* OCP */
528         if (fault & (1 << 6))
529                 sr_session_send_meta(sdi, SR_CONF_OVER_CURRENT_PROTECTION_ACTIVE,
530                         g_variant_new_boolean(fault & (1 << 6)));
531
532         /* OTP */
533         if (fault & (1 << 4))
534                 sr_session_send_meta(sdi, SR_CONF_OVER_TEMPERATURE_PROTECTION_ACTIVE,
535                         g_variant_new_boolean(fault & (1 << 4)));
536
537         /* CV */
538         cv = (fault & (1 << 0));
539         regulation_changed = (fault & (1 << 0));
540         /* CC+ */
541         cc_pos = (fault & (1 << 1));
542         regulation_changed = (fault & (1 << 1)) | regulation_changed;
543         /* UNREG */
544         unreg = (fault & (1 << 2));
545         regulation_changed = (fault & (1 << 2)) | regulation_changed;
546         /* CC- */
547         cc_neg = (fault & (1 << 9));
548         regulation_changed = (fault & (1 << 9)) | regulation_changed;
549
550         if (regulation_changed) {
551                 if (cv && !cc_pos && !cc_neg && !unreg)
552                         regulation = "CV";
553                 else if (cc_pos && !cv && !cc_neg && !unreg)
554                         regulation = "CC";
555                 else if (cc_neg && !cv && !cc_pos && !unreg)
556                         regulation = "CC-";
557                 else if (unreg && !cv && !cc_pos && !cc_neg)
558                         regulation = "UR";
559                 else if (!cv && !cc_pos && !cc_neg && !unreg)
560                         regulation = "";
561                 else {
562                         sr_dbg("Undefined regulation for HP 66xxA "
563                                 "(CV=%i, CC+=%i, CC-=%i, UR=%i).",
564                                 cv, cc_pos, cc_neg, unreg);
565                         return FALSE;
566                 }
567                 sr_session_send_meta(sdi, SR_CONF_REGULATION,
568                         g_variant_new_string(regulation));
569         }
570
571         return SR_OK;
572 }
573
574 /* HP 663xB series */
575 static const uint32_t hp_6630b_devopts[] = {
576         SR_CONF_CONTINUOUS,
577         SR_CONF_LIMIT_SAMPLES | SR_CONF_GET | SR_CONF_SET,
578         SR_CONF_LIMIT_MSEC | SR_CONF_GET | SR_CONF_SET,
579 };
580
581 static const uint32_t hp_6630b_devopts_cg[] = {
582         SR_CONF_ENABLED | SR_CONF_GET | SR_CONF_SET,
583         SR_CONF_VOLTAGE | SR_CONF_GET,
584         SR_CONF_CURRENT | SR_CONF_GET,
585         SR_CONF_VOLTAGE_TARGET | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
586         SR_CONF_CURRENT_LIMIT | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
587         SR_CONF_OVER_VOLTAGE_PROTECTION_ACTIVE | SR_CONF_GET,
588         SR_CONF_OVER_VOLTAGE_PROTECTION_THRESHOLD | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
589         SR_CONF_OVER_CURRENT_PROTECTION_ENABLED | SR_CONF_GET | SR_CONF_SET,
590         SR_CONF_OVER_CURRENT_PROTECTION_ACTIVE | SR_CONF_GET,
591         SR_CONF_OVER_TEMPERATURE_PROTECTION_ACTIVE | SR_CONF_GET,
592         SR_CONF_REGULATION | SR_CONF_GET,
593 };
594
595 static const struct channel_spec hp_6611c_ch[] = {
596         { "1", { 0, 8.19, 0.002, 3, 4 }, { 0, 5.1188, 0.00125, 4, 5 }, { 0, 41.92297 }, FREQ_DC_ONLY, { 0, 12, 0.06 }, NO_OCP_LIMITS },
597 };
598
599 static const struct channel_spec hp_6612c_ch[] = {
600         { "1", { 0, 20.475, 0.005, 3, 4 }, { 0, 2.0475, 0.0005, 4, 5 }, { 0, 41.92256 }, FREQ_DC_ONLY, { 0, 22, 0.1 }, NO_OCP_LIMITS },
601 };
602
603 static const struct channel_spec hp_6613c_ch[] = {
604         { "1", { 0, 51.188, 0.0125, 3, 4 }, { 0, 1.0238, 0.00025, 4, 5 }, { 0, 52.40627 }, FREQ_DC_ONLY, { 0, 55, 0.25 }, NO_OCP_LIMITS },
605 };
606
607 static const struct channel_spec hp_6614c_ch[] = {
608         { "1", { 0, 102.38, 0.025, 3, 4 }, { 0, 0.5118, 0.000125, 4, 5 }, { 0, 52.39808 }, FREQ_DC_ONLY, { 0, 110, 0.5 }, NO_OCP_LIMITS },
609 };
610
611 static const struct channel_spec hp_6631b_ch[] = {
612         { "1", { 0, 8.19, 0.002, 3, 4 }, { 0, 10.237, 0.00263, 4, 5 }, { 0, 83.84103 }, FREQ_DC_ONLY, { 0, 12, 0.06 }, NO_OCP_LIMITS },
613 };
614
615 static const struct channel_spec hp_6632b_ch[] = {
616         { "1", { 0, 20.475, 0.005, 3, 4 }, { 0, 5.1188, 0.00132, 4, 5 }, { 0, 104.80743 }, FREQ_DC_ONLY, { 0, 22, 0.1 }, NO_OCP_LIMITS },
617 };
618
619 static const struct channel_spec hp_66332a_ch[] = {
620         { "1", { 0, 20.475, 0.005, 3, 4 }, { 0, 5.1188, 0.00132, 4, 5 }, { 0, 104.80743 }, FREQ_DC_ONLY, { 0, 22, 0.1 }, NO_OCP_LIMITS },
621 };
622
623 static const struct channel_spec hp_6633b_ch[] = {
624         { "1", { 0, 51.188, 0.0125, 3, 4 }, { 0, 2.0475, 0.000526, 4, 5 }, { 0, 104.80743 }, FREQ_DC_ONLY, { 0, 55, 0.25 }, NO_OCP_LIMITS },
625 };
626
627 static const struct channel_spec hp_6634b_ch[] = {
628         { "1", { 0, 102.38, 0.025, 3, 4 }, { 0, 1.0238, 0.000263, 4, 5 }, { 0, 104.81664 }, FREQ_DC_ONLY, { 0, 110, 0.5 }, NO_OCP_LIMITS },
629 };
630
631 static const struct channel_group_spec hp_6630b_cg[] = {
632         { "1", CH_IDX(0), PPS_OVP | PPS_OCP, SR_MQFLAG_DC },
633 };
634
635 static const struct scpi_command hp_6630b_cmd[] = {
636         /*
637          * SCPI_CMD_REMOTE and SCPI_CMD_LOCAL are not used when GPIB is used,
638          * otherwise the device will report (non critical) error 602.
639          */
640         { SCPI_CMD_REMOTE, "SYST:REM" },
641         { SCPI_CMD_LOCAL, "SYST:LOC" },
642         { SCPI_CMD_GET_OUTPUT_ENABLED, "OUTP:STAT?" },
643         { SCPI_CMD_SET_OUTPUT_ENABLE, "OUTP:STAT ON" },
644         { SCPI_CMD_SET_OUTPUT_DISABLE, "OUTP:STAT OFF" },
645         { SCPI_CMD_GET_MEAS_VOLTAGE, ":MEAS:VOLT?" },
646         { SCPI_CMD_GET_MEAS_CURRENT, ":MEAS:CURR?" },
647         { SCPI_CMD_GET_VOLTAGE_TARGET, ":SOUR:VOLT?" },
648         { SCPI_CMD_SET_VOLTAGE_TARGET, ":SOUR:VOLT %.6f" },
649         { SCPI_CMD_GET_CURRENT_LIMIT, ":SOUR:CURR?" },
650         { SCPI_CMD_SET_CURRENT_LIMIT, ":SOUR:CURR %.6f" },
651         { SCPI_CMD_GET_OVER_CURRENT_PROTECTION_ENABLED, ":CURR:PROT:STAT?" },
652         { SCPI_CMD_SET_OVER_CURRENT_PROTECTION_ENABLE, ":CURR:PROT:STAT 1" },
653         { SCPI_CMD_SET_OVER_CURRENT_PROTECTION_DISABLE, ":CURR:PROT:STAT 0" },
654         { SCPI_CMD_GET_OVER_CURRENT_PROTECTION_ACTIVE, "STAT:QUES:COND?" },
655         { SCPI_CMD_GET_OVER_VOLTAGE_PROTECTION_ACTIVE, "STAT:QUES:COND?" },
656         { SCPI_CMD_GET_OVER_VOLTAGE_PROTECTION_THRESHOLD, ":VOLT:PROT?" },
657         { SCPI_CMD_SET_OVER_VOLTAGE_PROTECTION_THRESHOLD, ":VOLT:PROT %.6f" },
658         { SCPI_CMD_GET_OVER_TEMPERATURE_PROTECTION_ACTIVE, "STAT:QUES:COND?" },
659         { SCPI_CMD_GET_OUTPUT_REGULATION, "STAT:OPER:COND?" },
660         ALL_ZERO
661 };
662
663 static int hp_6630b_init_acquisition(const struct sr_dev_inst *sdi)
664 {
665         struct sr_scpi_dev_inst *scpi;
666         int ret;
667
668         scpi = sdi->conn;
669
670         /*
671          * Monitor CV (256), CC+ (1024) and CC- (2048) bits of the
672          * Operational Status Register.
673          * Use both positive and negative transitions of the status bits.
674          */
675         ret = sr_scpi_send(scpi, "STAT:OPER:PTR 3328;NTR 3328;ENAB 3328");
676         if (ret != SR_OK)
677                 return ret;
678
679         /*
680          * Monitor OVP (1), OCP (2), OTP (16) and Unreg (1024) bits of the
681          * Questionable Status Register.
682          * Use both positive and negative transitions of the status bits.
683          */
684         ret = sr_scpi_send(scpi, "STAT:QUES:PTR 1043;NTR 1043;ENAB 1043");
685         if (ret != SR_OK)
686                 return ret;
687
688         /*
689          * Service Request Enable Register set for Operational Status Register
690          * bits (128) and Questionable Status Register bits (8).
691          * This masks the Status Register generating a SRQ/RQS. Not implemented yet!
692          */
693         /*
694         ret = sr_scpi_send(scpi, "*SRE 136");
695         if (ret != SR_OK)
696                 return ret;
697         */
698
699         return SR_OK;
700 }
701
702 static int hp_6630b_update_status(const struct sr_dev_inst *sdi)
703 {
704         struct sr_scpi_dev_inst *scpi;
705         int ret;
706         int stb;
707         int ques_even, ques_cond;
708         int oper_even, oper_cond;
709         gboolean output_enabled;
710         gboolean unreg, cv, cc_pos, cc_neg;
711         gboolean regulation_changed;
712         char *regulation;
713
714         scpi = sdi->conn;
715
716         unreg = FALSE;
717         cv = FALSE;
718         cc_pos = FALSE;
719         cc_neg = FALSE;
720         regulation_changed = FALSE;
721
722         /*
723          * Use SPoll when SCPI uses GPIB as transport layer.
724          * SPoll is approx. twice as fast as a normal GPIB write + read would be!
725          */
726 #ifdef HAVE_LIBGPIB
727         char spoll_buf;
728
729         if (scpi->transport == SCPI_TRANSPORT_LIBGPIB) {
730                 ret = sr_scpi_gpib_spoll(scpi, &spoll_buf);
731                 if (ret != SR_OK)
732                         return ret;
733                 stb = (uint8_t)spoll_buf;
734         }
735         else {
736 #endif
737                 ret = sr_scpi_get_int(scpi, "*STB?", &stb);
738                 if (ret != SR_OK)
739                         return ret;
740 #ifdef HAVE_LIBGPIB
741         }
742 #endif
743
744         /* Questionable status summary bit */
745         if (stb & (1 << 3)) {
746                 /* Read the event register to clear it! */
747                 ret = sr_scpi_get_int(scpi, "STAT:QUES:EVEN?", &ques_even);
748                 if (ret != SR_OK)
749                         return ret;
750                 /* Now get the values. */
751                 ret = sr_scpi_get_int(scpi, "STAT:QUES:COND?", &ques_cond);
752                 if (ret != SR_OK)
753                         return ret;
754
755                 /* OVP */
756                 if (ques_even & (1 << 0))
757                         sr_session_send_meta(sdi, SR_CONF_OVER_VOLTAGE_PROTECTION_ACTIVE,
758                                 g_variant_new_boolean(ques_cond & (1 << 0)));
759
760                 /* OCP */
761                 if (ques_even & (1 << 1))
762                         sr_session_send_meta(sdi, SR_CONF_OVER_CURRENT_PROTECTION_ACTIVE,
763                                 g_variant_new_boolean(ques_cond & (1 << 1)));
764
765                 /* OTP */
766                 if (ques_even & (1 << 4))
767                         sr_session_send_meta(sdi, SR_CONF_OVER_TEMPERATURE_PROTECTION_ACTIVE,
768                                 g_variant_new_boolean(ques_cond & (1 << 4)));
769
770                 /* UNREG */
771                 unreg = (ques_cond & (1 << 10));
772                 regulation_changed = (ques_even & (1 << 10)) | regulation_changed;
773
774                 /*
775                  * Check if output state has changed, due to one of the
776                  * questionable states changed.
777                  * NOTE: The output state is sent even if it hasn't changed,
778                  * but that only happens rarely.
779                  */
780                 ret = sr_scpi_get_bool(scpi, "OUTP:STAT?", &output_enabled);
781                 if (ret != SR_OK)
782                         return ret;
783                 sr_session_send_meta(sdi, SR_CONF_ENABLED,
784                         g_variant_new_boolean(output_enabled));
785         }
786
787         /* Operation status summary bit */
788         if (stb & (1 << 7)) {
789                 /* Read the event register to clear it! */
790                 ret = sr_scpi_get_int(scpi, "STAT:OPER:EVEN?", &oper_even);
791                 if (ret != SR_OK)
792                         return ret;
793                 /* Now get the values. */
794                 ret = sr_scpi_get_int(scpi, "STAT:OPER:COND?", &oper_cond);
795                 if (ret != SR_OK)
796                         return ret;
797
798                 /* CV */
799                 cv = (oper_cond & (1 << 8));
800                 regulation_changed = (oper_even & (1 << 8)) | regulation_changed;
801                 /* CC+ */
802                 cc_pos = (oper_cond & (1 << 10));
803                 regulation_changed = (oper_even & (1 << 10)) | regulation_changed;
804                 /* CC- */
805                 cc_neg = (oper_cond & (1 << 11));
806                 regulation_changed = (oper_even & (1 << 11)) | regulation_changed;
807         }
808
809         if (regulation_changed) {
810                 if (cv && !cc_pos && !cc_neg && !unreg)
811                         regulation = "CV";
812                 else if (cc_pos && !cv && !cc_neg && !unreg)
813                         regulation = "CC";
814                 else if (cc_neg && !cv && !cc_pos && !unreg)
815                         regulation = "CC-";
816                 else if (unreg && !cv && !cc_pos && !cc_neg)
817                         regulation = "UR";
818                 else if (!cv && !cc_pos && !cc_neg && !unreg)
819                         /* This happens in case of OCP active. */
820                         regulation = "";
821                 else {
822                         /* This happens from time to time (CV and CC+ active). */
823                         sr_dbg("Undefined regulation for HP 66xxB "
824                                 "(CV=%i, CC+=%i, CC-=%i, UR=%i).",
825                                 cv, cc_pos, cc_neg, unreg);
826                         return FALSE;
827                 }
828                 sr_session_send_meta(sdi, SR_CONF_REGULATION,
829                         g_variant_new_string(regulation));
830         }
831
832         return SR_OK;
833 }
834
835 /* Philips/Fluke PM2800 series */
836 static const uint32_t philips_pm2800_devopts[] = {
837         SR_CONF_CONTINUOUS,
838         SR_CONF_LIMIT_SAMPLES | SR_CONF_GET | SR_CONF_SET,
839         SR_CONF_LIMIT_MSEC | SR_CONF_GET | SR_CONF_SET,
840 };
841
842 static const uint32_t philips_pm2800_devopts_cg[] = {
843         SR_CONF_ENABLED | SR_CONF_GET | SR_CONF_SET,
844         SR_CONF_VOLTAGE | SR_CONF_GET,
845         SR_CONF_VOLTAGE_TARGET | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
846         SR_CONF_CURRENT | SR_CONF_GET,
847         SR_CONF_CURRENT_LIMIT | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
848         SR_CONF_OVER_VOLTAGE_PROTECTION_ACTIVE | SR_CONF_GET,
849         SR_CONF_OVER_VOLTAGE_PROTECTION_THRESHOLD | SR_CONF_GET | SR_CONF_SET,
850         SR_CONF_OVER_CURRENT_PROTECTION_ENABLED | SR_CONF_GET | SR_CONF_SET,
851         SR_CONF_OVER_CURRENT_PROTECTION_ACTIVE | SR_CONF_GET,
852         SR_CONF_REGULATION | SR_CONF_GET,
853 };
854
855 enum philips_pm2800_modules {
856         PM2800_MOD_30V_10A = 1,
857         PM2800_MOD_60V_5A,
858         PM2800_MOD_60V_10A,
859         PM2800_MOD_8V_15A,
860         PM2800_MOD_60V_2A,
861         PM2800_MOD_120V_1A,
862 };
863
864 static const struct philips_pm2800_module_spec {
865         /* Min, max, programming resolution. */
866         double voltage[5];
867         double current[5];
868         double power[5];
869 } philips_pm2800_module_specs[] = {
870         /* Autoranging modules. */
871         [PM2800_MOD_30V_10A] = { { 0, 30, 0.0075, 2, 4 }, { 0, 10, 0.0025, 2, 4 }, { 0, 60 } },
872         [PM2800_MOD_60V_5A] = { { 0, 60, 0.015, 2, 3 }, { 0, 5, 0.00125, 2, 5 }, { 0, 60 } },
873         [PM2800_MOD_60V_10A] = { { 0, 60, 0.015, 2, 3 }, { 0, 10, 0.0025, 2, 5 }, { 0, 120 } },
874         /* Linear modules. */
875         [PM2800_MOD_8V_15A] = { { 0, 8, 0.002, 3, 3 }, { -15, 15, 0.00375, 3, 5 }, { 0, 120 } },
876         [PM2800_MOD_60V_2A] = { { 0, 60, 0.015, 2, 3 }, { -2, 2, 0.0005, 3, 4 }, { 0, 120 } },
877         [PM2800_MOD_120V_1A] = { { 0, 120, 0.030, 2, 2 }, { -1, 1, 0.00025, 3, 5 }, { 0, 120 } },
878 };
879
880 static const struct philips_pm2800_model {
881         unsigned int chassis;
882         unsigned int num_modules;
883         unsigned int set;
884         unsigned int modules[3];
885 } philips_pm2800_matrix[] = {
886         /* Autoranging chassis. */
887         { 1, 1, 0, { PM2800_MOD_30V_10A, 0, 0 } },
888         { 1, 1, 1, { PM2800_MOD_60V_5A, 0, 0 } },
889         { 1, 2, 0, { PM2800_MOD_30V_10A, PM2800_MOD_30V_10A, 0 } },
890         { 1, 2, 1, { PM2800_MOD_60V_5A, PM2800_MOD_60V_5A, 0 } },
891         { 1, 2, 2, { PM2800_MOD_30V_10A, PM2800_MOD_60V_5A, 0 } },
892         { 1, 2, 3, { PM2800_MOD_30V_10A, PM2800_MOD_60V_10A, 0 } },
893         { 1, 2, 4, { PM2800_MOD_60V_5A, PM2800_MOD_60V_10A, 0 } },
894         { 1, 3, 0, { PM2800_MOD_30V_10A, PM2800_MOD_30V_10A, PM2800_MOD_30V_10A } },
895         { 1, 3, 1, { PM2800_MOD_60V_5A, PM2800_MOD_60V_5A, PM2800_MOD_60V_5A } },
896         { 1, 3, 2, { PM2800_MOD_30V_10A, PM2800_MOD_30V_10A, PM2800_MOD_60V_5A } },
897         { 1, 3, 3, { PM2800_MOD_30V_10A, PM2800_MOD_60V_5A, PM2800_MOD_60V_5A } },
898         /* Linear chassis. */
899         { 3, 1, 0, { PM2800_MOD_60V_2A, 0, 0 } },
900         { 3, 1, 1, { PM2800_MOD_120V_1A, 0, 0 } },
901         { 3, 1, 2, { PM2800_MOD_8V_15A, 0, 0 } },
902         { 3, 2, 0, { PM2800_MOD_60V_2A, 0, 0 } },
903         { 3, 2, 1, { PM2800_MOD_120V_1A, 0, 0 } },
904         { 3, 2, 2, { PM2800_MOD_60V_2A, PM2800_MOD_120V_1A, 0 } },
905         { 3, 2, 3, { PM2800_MOD_8V_15A, PM2800_MOD_8V_15A, 0 } },
906 };
907
908 static const char *philips_pm2800_names[] = { "1", "2", "3" };
909
910 static int philips_pm2800_probe_channels(struct sr_dev_inst *sdi,
911                 struct sr_scpi_hw_info *hw_info,
912                 struct channel_spec **channels, unsigned int *num_channels,
913                 struct channel_group_spec **channel_groups, unsigned int *num_channel_groups)
914 {
915         const struct philips_pm2800_model *model;
916         const struct philips_pm2800_module_spec *spec;
917         unsigned int chassis, num_modules, set, module, m, i;
918
919         (void)sdi;
920
921         /*
922          * The model number as reported by *IDN? looks like e.g. PM2813/11,
923          * Where "PM28" is fixed, followed by the chassis code (1 = autoranging,
924          * 3 = linear series) and the number of modules: 1-3 for autoranging,
925          * 1-2 for linear.
926          * After the slash, the first digit denotes the module set. The
927          * digit after that denotes front (5) or rear (1) binding posts.
928          */
929         chassis = hw_info->model[4] - 0x30;
930         num_modules = hw_info->model[5] - 0x30;
931         set = hw_info->model[7] - 0x30;
932         for (m = 0; m < ARRAY_SIZE(philips_pm2800_matrix); m++) {
933                 model = &philips_pm2800_matrix[m];
934                 if (model->chassis == chassis && model->num_modules == num_modules
935                                 && model->set == set)
936                         break;
937         }
938         if (m == ARRAY_SIZE(philips_pm2800_matrix)) {
939                 sr_dbg("Model %s not found in matrix.", hw_info->model);
940                 return SR_ERR;
941         }
942
943         sr_dbg("Found %d output channel%s:", num_modules, num_modules > 1 ? "s" : "");
944         *channels = g_malloc0(sizeof(struct channel_spec) * num_modules);
945         *channel_groups = g_malloc0(sizeof(struct channel_group_spec) * num_modules);
946         for (i = 0; i < num_modules; i++) {
947                 module = model->modules[i];
948                 spec = &philips_pm2800_module_specs[module];
949                 sr_dbg("output %d: %.0f - %.0fV, %.0f - %.0fA, %.0f - %.0fW", i + 1,
950                                 spec->voltage[0], spec->voltage[1],
951                                 spec->current[0], spec->current[1],
952                                 spec->power[0], spec->power[1]);
953                 (*channels)[i].name = (char *)philips_pm2800_names[i];
954                 memcpy(&((*channels)[i].voltage), spec, sizeof(double) * 15);
955                 (*channel_groups)[i].name = (char *)philips_pm2800_names[i];
956                 (*channel_groups)[i].channel_index_mask = 1 << i;
957                 (*channel_groups)[i].features = PPS_OTP | PPS_OVP | PPS_OCP;
958                 (*channel_groups)[i].mqflags = SR_MQFLAG_DC;
959         }
960         *num_channels = *num_channel_groups = num_modules;
961
962         return SR_OK;
963 }
964
965 static const struct scpi_command philips_pm2800_cmd[] = {
966         { SCPI_CMD_SELECT_CHANNEL, ":INST:NSEL %s" },
967         { SCPI_CMD_GET_MEAS_VOLTAGE, ":MEAS:VOLT?" },
968         { SCPI_CMD_GET_MEAS_CURRENT, ":MEAS:CURR?" },
969         { SCPI_CMD_GET_VOLTAGE_TARGET, ":SOUR:VOLT?" },
970         { SCPI_CMD_SET_VOLTAGE_TARGET, ":SOUR:VOLT %.6f" },
971         { SCPI_CMD_GET_CURRENT_LIMIT, ":SOUR:CURR?" },
972         { SCPI_CMD_SET_CURRENT_LIMIT, ":SOUR:CURR %.6f" },
973         { SCPI_CMD_GET_OUTPUT_ENABLED, ":OUTP?" },
974         { SCPI_CMD_SET_OUTPUT_ENABLE, ":OUTP ON" },
975         { SCPI_CMD_SET_OUTPUT_DISABLE, ":OUTP OFF" },
976         { SCPI_CMD_GET_OUTPUT_REGULATION, ":SOUR:FUNC:MODE?" },
977         { SCPI_CMD_GET_OVER_VOLTAGE_PROTECTION_ACTIVE, ":SOUR:VOLT:PROT:TRIP?" },
978         { SCPI_CMD_GET_OVER_VOLTAGE_PROTECTION_THRESHOLD, ":SOUR:VOLT:PROT:LEV?" },
979         { SCPI_CMD_SET_OVER_VOLTAGE_PROTECTION_THRESHOLD, ":SOUR:VOLT:PROT:LEV %.6f" },
980         { SCPI_CMD_GET_OVER_CURRENT_PROTECTION_ENABLED, ":SOUR:CURR:PROT:STAT?" },
981         { SCPI_CMD_SET_OVER_CURRENT_PROTECTION_ENABLE, ":SOUR:CURR:PROT:STAT ON" },
982         { SCPI_CMD_SET_OVER_CURRENT_PROTECTION_DISABLE, ":SOUR:CURR:PROT:STAT OFF" },
983         { SCPI_CMD_GET_OVER_CURRENT_PROTECTION_ACTIVE, ":SOUR:CURR:PROT:TRIP?" },
984         ALL_ZERO
985 };
986
987 static const uint32_t rs_hmc8043_devopts[] = {
988         SR_CONF_CONTINUOUS,
989         SR_CONF_LIMIT_SAMPLES | SR_CONF_GET | SR_CONF_SET,
990         SR_CONF_LIMIT_MSEC | SR_CONF_GET | SR_CONF_SET,
991 };
992
993 static const uint32_t rs_hmc8043_devopts_cg[] = {
994         SR_CONF_OVER_VOLTAGE_PROTECTION_ENABLED | SR_CONF_GET | SR_CONF_SET,
995         SR_CONF_OVER_VOLTAGE_PROTECTION_ACTIVE | SR_CONF_GET,
996         SR_CONF_OVER_VOLTAGE_PROTECTION_THRESHOLD | SR_CONF_GET | SR_CONF_SET,
997         SR_CONF_VOLTAGE | SR_CONF_GET,
998         SR_CONF_VOLTAGE_TARGET | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
999         SR_CONF_CURRENT | SR_CONF_GET,
1000         SR_CONF_CURRENT_LIMIT | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
1001         SR_CONF_ENABLED | SR_CONF_GET | SR_CONF_SET,
1002 };
1003
1004 static const struct channel_spec rs_hmc8043_ch[] = {
1005         { "1", { 0, 32.050, 0.001, 3, 4 }, { 0.001, 3, 0.001, 3, 4 }, { 0, 0, 0, 0, 4 }, FREQ_DC_ONLY, NO_OVP_LIMITS, NO_OCP_LIMITS },
1006         { "2", { 0, 32.050, 0.001, 3, 4 }, { 0.001, 3, 0.001, 3, 4 }, { 0, 0, 0, 0, 4 }, FREQ_DC_ONLY, NO_OVP_LIMITS, NO_OCP_LIMITS },
1007         { "3", { 0, 32.050, 0.001, 3, 4 }, { 0.001, 3, 0.001, 3, 4 }, { 0, 0, 0, 0, 4 }, FREQ_DC_ONLY, NO_OVP_LIMITS, NO_OCP_LIMITS },
1008 };
1009
1010 static const struct channel_group_spec rs_hmc8043_cg[] = {
1011         { "1", CH_IDX(0), PPS_OVP, SR_MQFLAG_DC },
1012         { "2", CH_IDX(1), PPS_OVP, SR_MQFLAG_DC },
1013         { "3", CH_IDX(2), PPS_OVP, SR_MQFLAG_DC },
1014 };
1015
1016 static const struct scpi_command rs_hmc8043_cmd[] = {
1017         { SCPI_CMD_SELECT_CHANNEL, "INST:NSEL %s" },
1018         { SCPI_CMD_GET_MEAS_VOLTAGE, "MEAS:VOLT?" },
1019         { SCPI_CMD_GET_MEAS_CURRENT, "MEAS:CURR?" },
1020         { SCPI_CMD_GET_VOLTAGE_TARGET, "VOLT?" },
1021         { SCPI_CMD_SET_VOLTAGE_TARGET, "VOLT %.6f" },
1022         { SCPI_CMD_GET_CURRENT_LIMIT, "CURR?" },
1023         { SCPI_CMD_SET_CURRENT_LIMIT, "CURR %.6f" },
1024         { SCPI_CMD_GET_OUTPUT_ENABLED, "OUTP?" },
1025         { SCPI_CMD_SET_OUTPUT_ENABLE, "OUTP ON" },
1026         { SCPI_CMD_SET_OUTPUT_DISABLE, "OUTP OFF" },
1027         { SCPI_CMD_GET_OVER_VOLTAGE_PROTECTION_ACTIVE, "VOLT:PROT:TRIP?" },
1028         { SCPI_CMD_GET_OVER_VOLTAGE_PROTECTION_THRESHOLD, "VOLT:PROT:LEV?" },
1029         { SCPI_CMD_SET_OVER_VOLTAGE_PROTECTION_THRESHOLD, "VOLT:PROT:LEV %.6f" },
1030         { SCPI_CMD_GET_OVER_VOLTAGE_PROTECTION_ENABLED, "VOLT:PROT:STAT?" },
1031         { SCPI_CMD_SET_OVER_VOLTAGE_PROTECTION_ENABLE, "VOLT:PROT:STAT ON" },
1032         { SCPI_CMD_SET_OVER_VOLTAGE_PROTECTION_DISABLE, "VOLT:PROT:STAT OFF" },
1033         ALL_ZERO
1034 };
1035
1036 SR_PRIV const struct scpi_pps pps_profiles[] = {
1037         /* Agilent N5763A */
1038         { "Agilent", "N5763A", SCPI_DIALECT_UNKNOWN, 0,
1039                 ARRAY_AND_SIZE(agilent_n5700a_devopts),
1040                 ARRAY_AND_SIZE(agilent_n5700a_devopts_cg),
1041                 ARRAY_AND_SIZE(agilent_n5763a_ch),
1042                 ARRAY_AND_SIZE(agilent_n5700a_cg),
1043                 agilent_n5700a_cmd,
1044                 .probe_channels = NULL,
1045                 .init_acquisition = NULL,
1046                 .update_status = NULL,
1047         },
1048
1049         /* Agilent N5767A */
1050         { "Agilent", "N5767A", SCPI_DIALECT_UNKNOWN, 0,
1051                 ARRAY_AND_SIZE(agilent_n5700a_devopts),
1052                 ARRAY_AND_SIZE(agilent_n5700a_devopts_cg),
1053                 ARRAY_AND_SIZE(agilent_n5767a_ch),
1054                 ARRAY_AND_SIZE(agilent_n5700a_cg),
1055                 agilent_n5700a_cmd,
1056                 .probe_channels = NULL,
1057                 .init_acquisition = NULL,
1058                 .update_status = NULL,
1059         },
1060
1061         /* BK Precision 9310 */
1062         { "BK", "^9130$", SCPI_DIALECT_UNKNOWN, 0,
1063                 ARRAY_AND_SIZE(bk_9130_devopts),
1064                 ARRAY_AND_SIZE(bk_9130_devopts_cg),
1065                 ARRAY_AND_SIZE(bk_9130_ch),
1066                 ARRAY_AND_SIZE(bk_9130_cg),
1067                 bk_9130_cmd,
1068                 .probe_channels = NULL,
1069                 .init_acquisition = NULL,
1070                 .update_status = NULL,
1071         },
1072
1073         /* Chroma 61604 */
1074         { "Chroma", "61604", SCPI_DIALECT_UNKNOWN, 0,
1075                 ARRAY_AND_SIZE(chroma_61604_devopts),
1076                 ARRAY_AND_SIZE(chroma_61604_devopts_cg),
1077                 ARRAY_AND_SIZE(chroma_61604_ch),
1078                 ARRAY_AND_SIZE(chroma_61604_cg),
1079                 chroma_61604_cmd,
1080                 .probe_channels = NULL,
1081                 .init_acquisition = NULL,
1082                 .update_status = NULL,
1083         },
1084
1085         /* Chroma 62000 series */
1086         { "Chroma", "620[0-9]{2}P-[0-9]{2,3}-[0-9]{1,3}", SCPI_DIALECT_UNKNOWN, 0,
1087                 ARRAY_AND_SIZE(chroma_62000_devopts),
1088                 ARRAY_AND_SIZE(chroma_62000_devopts_cg),
1089                 NULL, 0,
1090                 NULL, 0,
1091                 chroma_62000_cmd,
1092                 .probe_channels = chroma_62000p_probe_channels,
1093                 .init_acquisition = NULL,
1094                 .update_status = NULL,
1095         },
1096
1097         /*
1098          * This entry is for testing the HP COMP language with a HP 6632B power
1099          * supply switched to the COMP language ("SYST:LANG COMP"). When used,
1100          * disable the entry for the HP 6632B below!
1101          */
1102         /*
1103         { "HP", "6632B", SCPI_DIALECT_HP_COMP, 0,
1104                 ARRAY_AND_SIZE(hp_6630a_devopts),
1105                 ARRAY_AND_SIZE(hp_6630a_devopts_cg),
1106                 ARRAY_AND_SIZE(hp_6632a_ch),
1107                 ARRAY_AND_SIZE(hp_6630a_cg),
1108                 hp_6630a_cmd,
1109                 .probe_channels = NULL,
1110                 hp_6630a_init_acquisition,
1111                 hp_6630a_update_status,
1112         },
1113         */
1114
1115         /* HP 6632A */
1116         { "HP", "6632A", SCPI_DIALECT_HP_COMP, 0,
1117                 ARRAY_AND_SIZE(hp_6630a_devopts),
1118                 ARRAY_AND_SIZE(hp_6630a_devopts_cg),
1119                 ARRAY_AND_SIZE(hp_6632a_ch),
1120                 ARRAY_AND_SIZE(hp_6630a_cg),
1121                 hp_6630a_cmd,
1122                 .probe_channels = NULL,
1123                 hp_6630a_init_acquisition,
1124                 hp_6630a_update_status,
1125         },
1126
1127         /* HP 6633A */
1128         { "HP", "6633A", SCPI_DIALECT_HP_COMP, 0,
1129                 ARRAY_AND_SIZE(hp_6630a_devopts),
1130                 ARRAY_AND_SIZE(hp_6630a_devopts_cg),
1131                 ARRAY_AND_SIZE(hp_6633a_ch),
1132                 ARRAY_AND_SIZE(hp_6630a_cg),
1133                 hp_6630a_cmd,
1134                 .probe_channels = NULL,
1135                 hp_6630a_init_acquisition,
1136                 hp_6630a_update_status,
1137         },
1138
1139         /* HP 6634A */
1140         { "HP", "6634A", SCPI_DIALECT_HP_COMP, 0,
1141                 ARRAY_AND_SIZE(hp_6630a_devopts),
1142                 ARRAY_AND_SIZE(hp_6630a_devopts_cg),
1143                 ARRAY_AND_SIZE(hp_6634a_ch),
1144                 ARRAY_AND_SIZE(hp_6630a_cg),
1145                 hp_6630a_cmd,
1146                 .probe_channels = NULL,
1147                 hp_6630a_init_acquisition,
1148                 hp_6630a_update_status,
1149         },
1150
1151         /* HP 6611C */
1152         { "HP", "6611C", SCPI_DIALECT_HP_66XXB, PPS_OTP,
1153                 ARRAY_AND_SIZE(hp_6630b_devopts),
1154                 ARRAY_AND_SIZE(hp_6630b_devopts_cg),
1155                 ARRAY_AND_SIZE(hp_6611c_ch),
1156                 ARRAY_AND_SIZE(hp_6630b_cg),
1157                 hp_6630b_cmd,
1158                 .probe_channels = NULL,
1159                 hp_6630b_init_acquisition,
1160                 hp_6630b_update_status,
1161         },
1162
1163         /* HP 6612C */
1164         { "HP", "6612C", SCPI_DIALECT_HP_66XXB, PPS_OTP,
1165                 ARRAY_AND_SIZE(hp_6630b_devopts),
1166                 ARRAY_AND_SIZE(hp_6630b_devopts_cg),
1167                 ARRAY_AND_SIZE(hp_6612c_ch),
1168                 ARRAY_AND_SIZE(hp_6630b_cg),
1169                 hp_6630b_cmd,
1170                 .probe_channels = NULL,
1171                 hp_6630b_init_acquisition,
1172                 hp_6630b_update_status,
1173         },
1174
1175         /* HP 6613C */
1176         { "HP", "6613C", SCPI_DIALECT_HP_66XXB, PPS_OTP,
1177                 ARRAY_AND_SIZE(hp_6630b_devopts),
1178                 ARRAY_AND_SIZE(hp_6630b_devopts_cg),
1179                 ARRAY_AND_SIZE(hp_6613c_ch),
1180                 ARRAY_AND_SIZE(hp_6630b_cg),
1181                 hp_6630b_cmd,
1182                 .probe_channels = NULL,
1183                 hp_6630b_init_acquisition,
1184                 hp_6630b_update_status,
1185         },
1186
1187         /* HP 6614C */
1188         { "HP", "6614C", SCPI_DIALECT_HP_66XXB, PPS_OTP,
1189                 ARRAY_AND_SIZE(hp_6630b_devopts),
1190                 ARRAY_AND_SIZE(hp_6630b_devopts_cg),
1191                 ARRAY_AND_SIZE(hp_6614c_ch),
1192                 ARRAY_AND_SIZE(hp_6630b_cg),
1193                 hp_6630b_cmd,
1194                 .probe_channels = NULL,
1195                 hp_6630b_init_acquisition,
1196                 hp_6630b_update_status,
1197         },
1198
1199         /* HP 6631B */
1200         { "HP", "6631B", SCPI_DIALECT_HP_66XXB, PPS_OTP,
1201                 ARRAY_AND_SIZE(hp_6630b_devopts),
1202                 ARRAY_AND_SIZE(hp_6630b_devopts_cg),
1203                 ARRAY_AND_SIZE(hp_6631b_ch),
1204                 ARRAY_AND_SIZE(hp_6630b_cg),
1205                 hp_6630b_cmd,
1206                 .probe_channels = NULL,
1207                 hp_6630b_init_acquisition,
1208                 hp_6630b_update_status,
1209         },
1210
1211         /* HP 6632B */
1212         { "HP", "6632B", SCPI_DIALECT_HP_66XXB, PPS_OTP,
1213                 ARRAY_AND_SIZE(hp_6630b_devopts),
1214                 ARRAY_AND_SIZE(hp_6630b_devopts_cg),
1215                 ARRAY_AND_SIZE(hp_6632b_ch),
1216                 ARRAY_AND_SIZE(hp_6630b_cg),
1217                 hp_6630b_cmd,
1218                 .probe_channels = NULL,
1219                 hp_6630b_init_acquisition,
1220                 hp_6630b_update_status,
1221         },
1222
1223         /* HP 66332A */
1224         { "HP", "66332A", SCPI_DIALECT_HP_66XXB, PPS_OTP,
1225                 ARRAY_AND_SIZE(hp_6630b_devopts),
1226                 ARRAY_AND_SIZE(hp_6630b_devopts_cg),
1227                 ARRAY_AND_SIZE(hp_66332a_ch),
1228                 ARRAY_AND_SIZE(hp_6630b_cg),
1229                 hp_6630b_cmd,
1230                 .probe_channels = NULL,
1231                 hp_6630b_init_acquisition,
1232                 hp_6630b_update_status,
1233         },
1234
1235         /* HP 6633B */
1236         { "HP", "6633B", SCPI_DIALECT_HP_66XXB, PPS_OTP,
1237                 ARRAY_AND_SIZE(hp_6630b_devopts),
1238                 ARRAY_AND_SIZE(hp_6630b_devopts_cg),
1239                 ARRAY_AND_SIZE(hp_6633b_ch),
1240                 ARRAY_AND_SIZE(hp_6630b_cg),
1241                 hp_6630b_cmd,
1242                 .probe_channels = NULL,
1243                 hp_6630b_init_acquisition,
1244                 hp_6630b_update_status,
1245         },
1246
1247         /* HP 6634B */
1248         { "HP", "6634B", SCPI_DIALECT_HP_66XXB, PPS_OTP,
1249                 ARRAY_AND_SIZE(hp_6630b_devopts),
1250                 ARRAY_AND_SIZE(hp_6630b_devopts_cg),
1251                 ARRAY_AND_SIZE(hp_6634b_ch),
1252                 ARRAY_AND_SIZE(hp_6630b_cg),
1253                 hp_6630b_cmd,
1254                 .probe_channels = NULL,
1255                 hp_6630b_init_acquisition,
1256                 hp_6630b_update_status,
1257         },
1258
1259         /* Rigol DP700 series */
1260         { "Rigol", "^DP711$", SCPI_DIALECT_UNKNOWN, 0,
1261                 ARRAY_AND_SIZE(rigol_dp700_devopts),
1262                 ARRAY_AND_SIZE(rigol_dp700_devopts_cg),
1263                 ARRAY_AND_SIZE(rigol_dp711_ch),
1264                 ARRAY_AND_SIZE(rigol_dp700_cg),
1265                 rigol_dp700_cmd,
1266                 .probe_channels = NULL,
1267                 .init_acquisition = NULL,
1268                 .update_status = NULL,
1269         },
1270         { "Rigol", "^DP712$", SCPI_DIALECT_UNKNOWN, 0,
1271                 ARRAY_AND_SIZE(rigol_dp700_devopts),
1272                 ARRAY_AND_SIZE(rigol_dp700_devopts_cg),
1273                 ARRAY_AND_SIZE(rigol_dp712_ch),
1274                 ARRAY_AND_SIZE(rigol_dp700_cg),
1275                 rigol_dp700_cmd,
1276                 .probe_channels = NULL,
1277                 .init_acquisition = NULL,
1278                 .update_status = NULL,
1279         },
1280
1281         /* Rigol DP800 series */
1282         { "Rigol", "^DP821A$", SCPI_DIALECT_UNKNOWN, PPS_OTP,
1283                 ARRAY_AND_SIZE(rigol_dp800_devopts),
1284                 ARRAY_AND_SIZE(rigol_dp800_devopts_cg),
1285                 ARRAY_AND_SIZE(rigol_dp821a_ch),
1286                 ARRAY_AND_SIZE(rigol_dp820_cg),
1287                 rigol_dp800_cmd,
1288                 .probe_channels = NULL,
1289                 .init_acquisition = NULL,
1290                 .update_status = NULL,
1291         },
1292         { "Rigol", "^DP831A$", SCPI_DIALECT_UNKNOWN, PPS_OTP,
1293                 ARRAY_AND_SIZE(rigol_dp800_devopts),
1294                 ARRAY_AND_SIZE(rigol_dp800_devopts_cg),
1295                 ARRAY_AND_SIZE(rigol_dp831_ch),
1296                 ARRAY_AND_SIZE(rigol_dp830_cg),
1297                 rigol_dp800_cmd,
1298                 .probe_channels = NULL,
1299                 .init_acquisition = NULL,
1300                 .update_status = NULL,
1301         },
1302         { "Rigol", "^(DP832|DP832A)$", SCPI_DIALECT_UNKNOWN, PPS_OTP,
1303                 ARRAY_AND_SIZE(rigol_dp800_devopts),
1304                 ARRAY_AND_SIZE(rigol_dp800_devopts_cg),
1305                 ARRAY_AND_SIZE(rigol_dp832_ch),
1306                 ARRAY_AND_SIZE(rigol_dp830_cg),
1307                 rigol_dp800_cmd,
1308                 .probe_channels = NULL,
1309                 .init_acquisition = NULL,
1310                 .update_status = NULL,
1311         },
1312
1313         /* Philips/Fluke PM2800 series */
1314         { "Philips", "^PM28[13][123]/[01234]{1,2}$", SCPI_DIALECT_PHILIPS, 0,
1315                 ARRAY_AND_SIZE(philips_pm2800_devopts),
1316                 ARRAY_AND_SIZE(philips_pm2800_devopts_cg),
1317                 NULL, 0,
1318                 NULL, 0,
1319                 philips_pm2800_cmd,
1320                 philips_pm2800_probe_channels,
1321                 .init_acquisition = NULL,
1322                 .update_status = NULL,
1323         },
1324
1325         /* Rohde & Schwarz HMC8043 */
1326         { "Rohde&Schwarz", "HMC8043", SCPI_DIALECT_UNKNOWN, 0,
1327                 ARRAY_AND_SIZE(rs_hmc8043_devopts),
1328                 ARRAY_AND_SIZE(rs_hmc8043_devopts_cg),
1329                 ARRAY_AND_SIZE(rs_hmc8043_ch),
1330                 ARRAY_AND_SIZE(rs_hmc8043_cg),
1331                 rs_hmc8043_cmd,
1332                 .probe_channels = NULL,
1333                 .init_acquisition = NULL,
1334                 .update_status = NULL,
1335         },
1336 };
1337
1338 SR_PRIV unsigned int num_pps_profiles = ARRAY_SIZE(pps_profiles);