]>
Commit | Line | Data |
---|---|---|
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 | * | |
8 | * This program is free software: you can redistribute it and/or modify | |
9 | * it under the terms of the GNU General Public License as published by | |
10 | * the Free Software Foundation, either version 3 of the License, or | |
11 | * (at your option) any later version. | |
12 | * | |
13 | * This program is distributed in the hope that it will be useful, | |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | * GNU General Public License for more details. | |
17 | * | |
18 | * You should have received a copy of the GNU General Public License | |
19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
20 | */ | |
21 | ||
22 | #include <string.h> | |
23 | #include <strings.h> | |
24 | #include "protocol.h" | |
25 | ||
26 | #define CH_IDX(x) (1 << x) | |
27 | #define FREQ_DC_ONLY {0, 0, 0} | |
28 | ||
29 | static const char *pps_vendors[][2] = { | |
30 | { "RIGOL TECHNOLOGIES", "Rigol" }, | |
31 | { "HEWLETT-PACKARD", "HP" }, | |
32 | { "PHILIPS", "Philips" }, | |
33 | { "CHROMA", "Chroma" }, | |
34 | { "Chroma ATE", "Chroma" }, | |
35 | { "Agilent Technologies", "Agilent" }, | |
36 | }; | |
37 | ||
38 | SR_PRIV const char *get_vendor(const char *raw_vendor) | |
39 | { | |
40 | unsigned int i; | |
41 | ||
42 | for (i = 0; i < ARRAY_SIZE(pps_vendors); i++) { | |
43 | if (!strcasecmp(raw_vendor, pps_vendors[i][0])) | |
44 | return pps_vendors[i][1]; | |
45 | } | |
46 | ||
47 | return raw_vendor; | |
48 | } | |
49 | ||
50 | static const uint32_t devopts_none[] = { }; | |
51 | ||
52 | /* Agilent/Keysight N5700A series */ | |
53 | static const uint32_t agilent_n5700a_devopts[] = { | |
54 | SR_CONF_CONTINUOUS | SR_CONF_SET, | |
55 | }; | |
56 | ||
57 | static const uint32_t agilent_n5700a_devopts_cg[] = { | |
58 | SR_CONF_OVER_VOLTAGE_PROTECTION_THRESHOLD | SR_CONF_GET | SR_CONF_SET, | |
59 | SR_CONF_OVER_CURRENT_PROTECTION_ENABLED | SR_CONF_GET | SR_CONF_SET, | |
60 | SR_CONF_OVER_CURRENT_PROTECTION_THRESHOLD | SR_CONF_GET | SR_CONF_SET, | |
61 | SR_CONF_VOLTAGE | SR_CONF_GET, | |
62 | SR_CONF_VOLTAGE_TARGET | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST, | |
63 | SR_CONF_CURRENT | SR_CONF_GET, | |
64 | SR_CONF_ENABLED | SR_CONF_GET | SR_CONF_SET, | |
65 | }; | |
66 | ||
67 | static const struct channel_spec agilent_n5767a_ch[] = { | |
68 | { "1", { 0, 60, 0.0001 }, { 0, 25, 0.1 }, FREQ_DC_ONLY }, | |
69 | }; | |
70 | ||
71 | static const struct channel_group_spec agilent_n5767a_cg[] = { | |
72 | { "1", CH_IDX(0), PPS_OVP | PPS_OCP }, | |
73 | }; | |
74 | ||
75 | /* | |
76 | * TODO: OVER_CURRENT_PROTECTION_ACTIVE status can be determined by the OC bit | |
77 | * in STAT:QUES:EVEN?, but this is not implemented. | |
78 | */ | |
79 | static const struct scpi_command agilent_n5700a_cmd[] = { | |
80 | { SCPI_CMD_REMOTE, "SYST:COMM:RLST REM" }, | |
81 | { SCPI_CMD_LOCAL, "SYST:COMM:RLST LOC" }, | |
82 | { SCPI_CMD_GET_MEAS_VOLTAGE, ":MEAS:VOLT?" }, | |
83 | { SCPI_CMD_GET_MEAS_CURRENT, "MEAS:CURR?" }, | |
84 | { SCPI_CMD_GET_VOLTAGE_TARGET, ":SOUR:VOLT?" }, | |
85 | { SCPI_CMD_SET_VOLTAGE_TARGET, ":SOUR:VOLT %.6f" }, | |
86 | { SCPI_CMD_GET_CURRENT_LIMIT, ":SOUR:CURR?" }, | |
87 | { SCPI_CMD_SET_CURRENT_LIMIT, ":SOUR:CURR %.6f" }, | |
88 | { SCPI_CMD_GET_OUTPUT_ENABLED, ":OUTP:STAT?" }, | |
89 | { SCPI_CMD_SET_OUTPUT_ENABLE, ":OUTP ON" }, | |
90 | { SCPI_CMD_SET_OUTPUT_DISABLE, ":OUTP OFF" }, | |
91 | { SCPI_CMD_GET_OVER_VOLTAGE_PROTECTION_THRESHOLD, ":VOLT:PROT?" }, | |
92 | { SCPI_CMD_SET_OVER_VOLTAGE_PROTECTION_THRESHOLD, ":VOLT:PROT %.6f" }, | |
93 | { SCPI_CMD_GET_OVER_CURRENT_PROTECTION_ENABLED, ":CURR:PROT:STAT?" }, | |
94 | { SCPI_CMD_SET_OVER_CURRENT_PROTECTION_ENABLE, ":CURR:PROT:STAT ON?"}, | |
95 | { SCPI_CMD_SET_OVER_CURRENT_PROTECTION_DISABLE, ":CURR:PROT:STAT OFF?"}, | |
96 | /* Current limit (CC mode) and OCP are set using the same command. */ | |
97 | { SCPI_CMD_GET_OVER_CURRENT_PROTECTION_THRESHOLD, ":SOUR:CURR?" }, | |
98 | { SCPI_CMD_SET_OVER_CURRENT_PROTECTION_THRESHOLD, ":SOUR:CURR %.6f" }, | |
99 | }; | |
100 | ||
101 | /* Chroma 61600 series AC source */ | |
102 | static const uint32_t chroma_61604_devopts[] = { | |
103 | SR_CONF_CONTINUOUS | SR_CONF_SET, | |
104 | }; | |
105 | ||
106 | static const uint32_t chroma_61604_devopts_cg[] = { | |
107 | SR_CONF_OVER_VOLTAGE_PROTECTION_THRESHOLD | SR_CONF_GET | SR_CONF_SET, | |
108 | SR_CONF_OVER_CURRENT_PROTECTION_THRESHOLD | SR_CONF_GET | SR_CONF_SET, | |
109 | SR_CONF_VOLTAGE | SR_CONF_GET, | |
110 | SR_CONF_VOLTAGE_TARGET | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST, | |
111 | SR_CONF_OUTPUT_FREQUENCY | SR_CONF_GET, | |
112 | SR_CONF_OUTPUT_FREQUENCY_TARGET | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST, | |
113 | SR_CONF_CURRENT | SR_CONF_GET, | |
114 | SR_CONF_ENABLED | SR_CONF_GET | SR_CONF_SET, | |
115 | }; | |
116 | ||
117 | static const struct channel_spec chroma_61604_ch[] = { | |
118 | { "1", { 0, 300, 0.1 }, { 0, 16, 0.1 }, { 1.0, 1000.0, 0.01 } }, | |
119 | }; | |
120 | ||
121 | static const struct channel_group_spec chroma_61604_cg[] = { | |
122 | { "1", CH_IDX(0), PPS_OVP | PPS_OCP }, | |
123 | }; | |
124 | ||
125 | static const struct scpi_command chroma_61604_cmd[] = { | |
126 | { SCPI_CMD_REMOTE, "SYST:REM" }, | |
127 | { SCPI_CMD_LOCAL, "SYST:LOC" }, | |
128 | { SCPI_CMD_GET_MEAS_VOLTAGE, ":FETC:VOLT:ACDC?" }, | |
129 | { SCPI_CMD_GET_MEAS_FREQUENCY, ":FETC:FREQ?" }, | |
130 | { SCPI_CMD_GET_MEAS_CURRENT, ":FETC:CURR:AC?" }, | |
131 | { SCPI_CMD_GET_MEAS_POWER, ":FETC:POW:AC?" }, | |
132 | { SCPI_CMD_GET_VOLTAGE_TARGET, ":SOUR:VOLT:AC?" }, | |
133 | { SCPI_CMD_SET_VOLTAGE_TARGET, ":SOUR:VOLT:AC %.1f" }, | |
134 | { SCPI_CMD_GET_FREQUENCY_TARGET, ":SOUR:FREQ?" }, | |
135 | { SCPI_CMD_SET_FREQUENCY_TARGET, ":SOUR:FREQ %.2f" }, | |
136 | { SCPI_CMD_GET_OUTPUT_ENABLED, ":OUTP?" }, | |
137 | { SCPI_CMD_SET_OUTPUT_ENABLE, ":OUTP ON" }, | |
138 | { SCPI_CMD_SET_OUTPUT_DISABLE, ":OUTP OFF" }, | |
139 | { SCPI_CMD_GET_OVER_VOLTAGE_PROTECTION_THRESHOLD, ":SOUR:VOLT:LIM:AC?" }, | |
140 | { SCPI_CMD_SET_OVER_VOLTAGE_PROTECTION_THRESHOLD, ":SOUR:VOLT:LIM:AC %.1f" }, | |
141 | /* This is not a current limit mode. It is overcurrent protection. */ | |
142 | { SCPI_CMD_GET_OVER_CURRENT_PROTECTION_THRESHOLD, ":SOUR:CURR:LIM?" }, | |
143 | { SCPI_CMD_SET_OVER_CURRENT_PROTECTION_THRESHOLD, ":SOUR:CURR:LIM %.2f" }, | |
144 | }; | |
145 | ||
146 | /* Chroma 62000 series DC source */ | |
147 | ||
148 | static const uint32_t chroma_62000_devopts[] = { | |
149 | SR_CONF_CONTINUOUS | SR_CONF_SET, | |
150 | }; | |
151 | ||
152 | static const uint32_t chroma_62000_devopts_cg[] = { | |
153 | SR_CONF_OVER_VOLTAGE_PROTECTION_THRESHOLD | SR_CONF_GET | SR_CONF_SET, | |
154 | SR_CONF_OVER_CURRENT_PROTECTION_THRESHOLD | SR_CONF_GET | SR_CONF_SET, | |
155 | SR_CONF_VOLTAGE | SR_CONF_GET, | |
156 | SR_CONF_VOLTAGE_TARGET | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST, | |
157 | SR_CONF_CURRENT | SR_CONF_GET, | |
158 | SR_CONF_CURRENT_LIMIT | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST, | |
159 | SR_CONF_ENABLED | SR_CONF_GET | SR_CONF_SET, | |
160 | }; | |
161 | ||
162 | static const struct channel_group_spec chroma_62000_cg[] = { | |
163 | { "1", CH_IDX(0), PPS_OVP | PPS_OCP }, | |
164 | }; | |
165 | ||
166 | static const struct scpi_command chroma_62000_cmd[] = { | |
167 | { SCPI_CMD_REMOTE, ":CONF:REM ON" }, | |
168 | { SCPI_CMD_LOCAL, ":CONF:REM OFF" }, | |
169 | { SCPI_CMD_BEEPER, ":CONF:BEEP?" }, | |
170 | { SCPI_CMD_BEEPER_ENABLE, ":CONF:BEEP ON" }, | |
171 | { SCPI_CMD_BEEPER_DISABLE, ":CONF:BEEP OFF" }, | |
172 | { SCPI_CMD_GET_MEAS_VOLTAGE, ":MEAS:VOLT?" }, | |
173 | { SCPI_CMD_GET_MEAS_CURRENT, ":MEAS:CURR?" }, | |
174 | { SCPI_CMD_GET_MEAS_POWER, ":MEAS:POW?" }, | |
175 | { SCPI_CMD_GET_VOLTAGE_TARGET, ":SOUR:VOLT?" }, | |
176 | { SCPI_CMD_SET_VOLTAGE_TARGET, ":SOUR:VOLT %.2f" }, | |
177 | { SCPI_CMD_GET_CURRENT_LIMIT, ":SOUR:CURR?" }, | |
178 | { SCPI_CMD_SET_CURRENT_LIMIT, ":SOUR:CURR %.6f" }, | |
179 | { SCPI_CMD_GET_OUTPUT_ENABLED, ":CONF:OUTP?" }, | |
180 | { SCPI_CMD_SET_OUTPUT_ENABLE, ":CONF:OUTP ON" }, | |
181 | { SCPI_CMD_SET_OUTPUT_DISABLE, ":CONF:OUTP OFF" }, | |
182 | { SCPI_CMD_GET_OVER_VOLTAGE_PROTECTION_THRESHOLD, ":SOUR:VOLT:PROT:HIGH?" }, | |
183 | { SCPI_CMD_SET_OVER_VOLTAGE_PROTECTION_THRESHOLD, ":SOUR:VOLT:PROT:HIGH %.6f" }, | |
184 | { SCPI_CMD_GET_OVER_CURRENT_PROTECTION_THRESHOLD, ":SOUR:CURR:PROT:HIGH?" }, | |
185 | { SCPI_CMD_SET_OVER_CURRENT_PROTECTION_THRESHOLD, ":SOUR:CURR:PROT:HIGH %.6f" }, | |
186 | }; | |
187 | ||
188 | static int chroma_62000p_probe_channels(struct sr_dev_inst *sdi, | |
189 | struct sr_scpi_hw_info *hw_info, | |
190 | struct channel_spec **channels, unsigned int *num_channels, | |
191 | struct channel_group_spec **channel_groups, | |
192 | unsigned int *num_channel_groups) | |
193 | { | |
194 | unsigned int volts, amps; | |
195 | struct channel_spec *channel; | |
196 | ||
197 | (void)sdi; | |
198 | ||
199 | sscanf(hw_info->model, "%*[^P]P-%u-%u", &volts, &s); | |
200 | sr_dbg("Found device rated for %d V and %d A", volts, amps); | |
201 | ||
202 | if (volts > 600) { | |
203 | sr_err("Probed max voltage of %u V is out of spec.", volts); | |
204 | return SR_ERR_BUG; | |
205 | } | |
206 | ||
207 | if (volts > 120) { | |
208 | sr_err("Probed max current of %u A is out of spec.", amps); | |
209 | return SR_ERR_BUG; | |
210 | } | |
211 | ||
212 | channel = g_malloc0(sizeof(struct channel_spec)); | |
213 | channel->name = "1"; | |
214 | channel->voltage[0] = channel->current[0] = 0.0; | |
215 | channel->voltage[1] = (float)volts; | |
216 | channel->current[1] = (float)amps; | |
217 | channel->voltage[2] = channel->current[2] = 0.01; | |
218 | *channels = channel; | |
219 | *num_channels = 1; | |
220 | ||
221 | *channel_groups = g_malloc(sizeof(struct channel_group_spec)); | |
222 | **channel_groups = chroma_62000_cg[0]; | |
223 | *num_channel_groups = 1; | |
224 | ||
225 | return SR_OK; | |
226 | } | |
227 | ||
228 | /* Rigol DP800 series */ | |
229 | static const uint32_t rigol_dp800_devopts[] = { | |
230 | SR_CONF_CONTINUOUS | SR_CONF_SET, | |
231 | SR_CONF_OVER_TEMPERATURE_PROTECTION | SR_CONF_GET | SR_CONF_SET, | |
232 | }; | |
233 | ||
234 | static const uint32_t rigol_dp800_devopts_cg[] = { | |
235 | SR_CONF_REGULATION | SR_CONF_GET, | |
236 | SR_CONF_OVER_VOLTAGE_PROTECTION_ENABLED | SR_CONF_GET | SR_CONF_SET, | |
237 | SR_CONF_OVER_VOLTAGE_PROTECTION_ACTIVE | SR_CONF_GET, | |
238 | SR_CONF_OVER_VOLTAGE_PROTECTION_THRESHOLD | SR_CONF_GET | SR_CONF_SET, | |
239 | SR_CONF_OVER_CURRENT_PROTECTION_ENABLED | SR_CONF_GET | SR_CONF_SET, | |
240 | SR_CONF_OVER_CURRENT_PROTECTION_ACTIVE | SR_CONF_GET, | |
241 | SR_CONF_OVER_CURRENT_PROTECTION_THRESHOLD | SR_CONF_GET | SR_CONF_SET, | |
242 | SR_CONF_VOLTAGE | SR_CONF_GET, | |
243 | SR_CONF_VOLTAGE_TARGET | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST, | |
244 | SR_CONF_CURRENT | SR_CONF_GET, | |
245 | SR_CONF_CURRENT_LIMIT | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST, | |
246 | SR_CONF_ENABLED | SR_CONF_GET | SR_CONF_SET, | |
247 | }; | |
248 | ||
249 | static const struct channel_spec rigol_dp821a_ch[] = { | |
250 | { "1", { 0, 60, 0.001 }, { 0, 1, 0.0001 }, FREQ_DC_ONLY }, | |
251 | { "2", { 0, 8, 0.001 }, { 0, 10, 0.001 }, FREQ_DC_ONLY }, | |
252 | }; | |
253 | ||
254 | static const struct channel_spec rigol_dp831_ch[] = { | |
255 | { "1", { 0, 8, 0.001 }, { 0, 5, 0.0003 }, FREQ_DC_ONLY }, | |
256 | { "2", { 0, 30, 0.001 }, { 0, 2, 0.0001 }, FREQ_DC_ONLY }, | |
257 | { "3", { 0, -30, 0.001 }, { 0, 2, 0.0001 }, FREQ_DC_ONLY }, | |
258 | }; | |
259 | ||
260 | static const struct channel_spec rigol_dp832_ch[] = { | |
261 | { "1", { 0, 30, 0.001 }, { 0, 3, 0.001 }, FREQ_DC_ONLY }, | |
262 | { "2", { 0, 30, 0.001 }, { 0, 3, 0.001 }, FREQ_DC_ONLY }, | |
263 | { "3", { 0, 5, 0.001 }, { 0, 3, 0.001 }, FREQ_DC_ONLY }, | |
264 | }; | |
265 | ||
266 | static const struct channel_group_spec rigol_dp820_cg[] = { | |
267 | { "1", CH_IDX(0), PPS_OVP | PPS_OCP }, | |
268 | { "2", CH_IDX(1), PPS_OVP | PPS_OCP }, | |
269 | }; | |
270 | ||
271 | static const struct channel_group_spec rigol_dp830_cg[] = { | |
272 | { "1", CH_IDX(0), PPS_OVP | PPS_OCP }, | |
273 | { "2", CH_IDX(1), PPS_OVP | PPS_OCP }, | |
274 | { "3", CH_IDX(2), PPS_OVP | PPS_OCP }, | |
275 | }; | |
276 | ||
277 | static const struct scpi_command rigol_dp800_cmd[] = { | |
278 | { SCPI_CMD_REMOTE, "SYST:REMOTE" }, | |
279 | { SCPI_CMD_LOCAL, "SYST:LOCAL" }, | |
280 | { SCPI_CMD_BEEPER, "SYST:BEEP:STAT?" }, | |
281 | { SCPI_CMD_BEEPER_ENABLE, "SYST:BEEP:STAT ON" }, | |
282 | { SCPI_CMD_BEEPER_DISABLE, "SYST:BEEP:STAT OFF" }, | |
283 | { SCPI_CMD_SELECT_CHANNEL, ":INST:NSEL %s" }, | |
284 | { SCPI_CMD_GET_MEAS_VOLTAGE, ":MEAS:VOLT?" }, | |
285 | { SCPI_CMD_GET_MEAS_CURRENT, ":MEAS:CURR?" }, | |
286 | { SCPI_CMD_GET_MEAS_POWER, ":MEAS:POWE?" }, | |
287 | { SCPI_CMD_GET_VOLTAGE_TARGET, ":SOUR:VOLT?" }, | |
288 | { SCPI_CMD_SET_VOLTAGE_TARGET, ":SOUR:VOLT %.6f" }, | |
289 | { SCPI_CMD_GET_CURRENT_LIMIT, ":SOUR:CURR?" }, | |
290 | { SCPI_CMD_SET_CURRENT_LIMIT, ":SOUR:CURR %.6f" }, | |
291 | { SCPI_CMD_GET_OUTPUT_ENABLED, ":OUTP?" }, | |
292 | { SCPI_CMD_SET_OUTPUT_ENABLE, ":OUTP ON" }, | |
293 | { SCPI_CMD_SET_OUTPUT_DISABLE, ":OUTP OFF" }, | |
294 | { SCPI_CMD_GET_OUTPUT_REGULATION, ":OUTP:MODE?" }, | |
295 | { SCPI_CMD_GET_OVER_TEMPERATURE_PROTECTION, ":SYST:OTP?" }, | |
296 | { SCPI_CMD_SET_OVER_TEMPERATURE_PROTECTION_ENABLE, ":SYST:OTP ON" }, | |
297 | { SCPI_CMD_SET_OVER_TEMPERATURE_PROTECTION_DISABLE, ":SYST:OTP OFF" }, | |
298 | { SCPI_CMD_GET_OVER_VOLTAGE_PROTECTION_ENABLED, ":OUTP:OVP?" }, | |
299 | { SCPI_CMD_SET_OVER_VOLTAGE_PROTECTION_ENABLE, ":OUTP:OVP ON" }, | |
300 | { SCPI_CMD_SET_OVER_VOLTAGE_PROTECTION_DISABLE, ":OUTP:OVP OFF" }, | |
301 | { SCPI_CMD_GET_OVER_VOLTAGE_PROTECTION_ACTIVE, ":OUTP:OVP:QUES?" }, | |
302 | { SCPI_CMD_GET_OVER_VOLTAGE_PROTECTION_THRESHOLD, ":OUTP:OVP:VAL?" }, | |
303 | { SCPI_CMD_SET_OVER_VOLTAGE_PROTECTION_THRESHOLD, ":OUTP:OVP:VAL %.6f" }, | |
304 | { SCPI_CMD_GET_OVER_CURRENT_PROTECTION_ENABLED, ":OUTP:OCP?" }, | |
305 | { SCPI_CMD_SET_OVER_CURRENT_PROTECTION_ENABLE, ":OUTP:OCP:STAT ON" }, | |
306 | { SCPI_CMD_SET_OVER_CURRENT_PROTECTION_DISABLE, ":OUTP:OCP:STAT OFF" }, | |
307 | { SCPI_CMD_GET_OVER_CURRENT_PROTECTION_ACTIVE, ":OUTP:OCP:QUES?" }, | |
308 | { SCPI_CMD_GET_OVER_CURRENT_PROTECTION_THRESHOLD, ":OUTP:OCP:VAL?" }, | |
309 | { SCPI_CMD_SET_OVER_CURRENT_PROTECTION_THRESHOLD, ":OUTP:OCP:VAL %.6f" }, | |
310 | }; | |
311 | ||
312 | /* HP 663xx series */ | |
313 | static const uint32_t hp_6632b_devopts[] = { | |
314 | SR_CONF_CONTINUOUS | SR_CONF_SET, | |
315 | SR_CONF_ENABLED | SR_CONF_GET | SR_CONF_SET, | |
316 | SR_CONF_VOLTAGE | SR_CONF_GET, | |
317 | SR_CONF_CURRENT | SR_CONF_GET, | |
318 | SR_CONF_VOLTAGE_TARGET | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST, | |
319 | SR_CONF_CURRENT_LIMIT | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST, | |
320 | }; | |
321 | ||
322 | static const struct channel_spec hp_6632b_ch[] = { | |
323 | { "1", { 0, 20.475, 0.005 }, { 0, 5.1188, 0.00132 }, FREQ_DC_ONLY }, | |
324 | }; | |
325 | ||
326 | static const struct channel_group_spec hp_6632b_cg[] = { | |
327 | { "1", CH_IDX(0), 0 }, | |
328 | }; | |
329 | ||
330 | static const struct scpi_command hp_6632b_cmd[] = { | |
331 | { SCPI_CMD_GET_OUTPUT_ENABLED, "OUTP:STAT?" }, | |
332 | { SCPI_CMD_SET_OUTPUT_ENABLE, "OUTP:STAT ON" }, | |
333 | { SCPI_CMD_SET_OUTPUT_DISABLE, "OUTP:STAT OFF" }, | |
334 | { SCPI_CMD_GET_MEAS_VOLTAGE, ":MEAS:VOLT?" }, | |
335 | { SCPI_CMD_GET_MEAS_CURRENT, ":MEAS:CURR?" }, | |
336 | { SCPI_CMD_GET_VOLTAGE_TARGET, ":SOUR:VOLT?" }, | |
337 | { SCPI_CMD_SET_VOLTAGE_TARGET, ":SOUR:VOLT %.6f" }, | |
338 | { SCPI_CMD_GET_CURRENT_LIMIT, ":SOUR:CURR?" }, | |
339 | { SCPI_CMD_SET_CURRENT_LIMIT, ":SOUR:CURR %.6f" }, | |
340 | }; | |
341 | ||
342 | /* Philips/Fluke PM2800 series */ | |
343 | static const uint32_t philips_pm2800_devopts[] = { | |
344 | SR_CONF_CONTINUOUS | SR_CONF_SET, | |
345 | }; | |
346 | ||
347 | static const uint32_t philips_pm2800_devopts_cg[] = { | |
348 | SR_CONF_ENABLED | SR_CONF_GET | SR_CONF_SET, | |
349 | SR_CONF_VOLTAGE | SR_CONF_GET, | |
350 | SR_CONF_VOLTAGE_TARGET | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST, | |
351 | SR_CONF_CURRENT | SR_CONF_GET, | |
352 | SR_CONF_CURRENT_LIMIT | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST, | |
353 | SR_CONF_OVER_VOLTAGE_PROTECTION_ACTIVE | SR_CONF_GET, | |
354 | SR_CONF_OVER_VOLTAGE_PROTECTION_THRESHOLD | SR_CONF_GET | SR_CONF_SET, | |
355 | SR_CONF_OVER_CURRENT_PROTECTION_ENABLED | SR_CONF_GET | SR_CONF_SET, | |
356 | SR_CONF_OVER_CURRENT_PROTECTION_ACTIVE | SR_CONF_GET, | |
357 | SR_CONF_REGULATION | SR_CONF_GET, | |
358 | }; | |
359 | ||
360 | enum philips_pm2800_modules { | |
361 | PM2800_MOD_30V_10A = 1, | |
362 | PM2800_MOD_60V_5A, | |
363 | PM2800_MOD_60V_10A, | |
364 | PM2800_MOD_8V_15A, | |
365 | PM2800_MOD_60V_2A, | |
366 | PM2800_MOD_120V_1A, | |
367 | }; | |
368 | ||
369 | static const struct philips_pm2800_module_spec { | |
370 | /* Min, max, programming resolution. */ | |
371 | float voltage[3]; | |
372 | float current[3]; | |
373 | } philips_pm2800_module_specs[] = { | |
374 | /* Autoranging modules. */ | |
375 | [PM2800_MOD_30V_10A] = { { 0, 30, 0.0075 }, { 0, 10, 0.0025 } }, | |
376 | [PM2800_MOD_60V_5A] = { { 0, 60, 0.015 }, { 0, 5, 0.00125 } }, | |
377 | [PM2800_MOD_60V_10A] = { { 0, 60, 0.015 }, { 0, 10, 0.0025 } }, | |
378 | /* Linear modules. */ | |
379 | [PM2800_MOD_8V_15A] = { { 0, 8, 0.002 }, { -15, 15, 0.00375 } }, | |
380 | [PM2800_MOD_60V_2A] = { { 0, 60, 0.015 }, { -2, 2, 0.0005 } }, | |
381 | [PM2800_MOD_120V_1A] = { { 0, 120, 0.030 }, { -1, 1, 0.00025 } }, | |
382 | }; | |
383 | ||
384 | static const struct philips_pm2800_model { | |
385 | unsigned int chassis; | |
386 | unsigned int num_modules; | |
387 | unsigned int set; | |
388 | unsigned int modules[3]; | |
389 | } philips_pm2800_matrix[] = { | |
390 | /* Autoranging chassis. */ | |
391 | { 1, 1, 0, { PM2800_MOD_30V_10A, 0, 0 } }, | |
392 | { 1, 1, 1, { PM2800_MOD_60V_5A, 0, 0 } }, | |
393 | { 1, 2, 0, { PM2800_MOD_30V_10A, PM2800_MOD_30V_10A, 0 } }, | |
394 | { 1, 2, 1, { PM2800_MOD_60V_5A, PM2800_MOD_60V_5A, 0 } }, | |
395 | { 1, 2, 2, { PM2800_MOD_30V_10A, PM2800_MOD_60V_5A, 0 } }, | |
396 | { 1, 2, 3, { PM2800_MOD_30V_10A, PM2800_MOD_60V_10A, 0 } }, | |
397 | { 1, 2, 4, { PM2800_MOD_60V_5A, PM2800_MOD_60V_10A, 0 } }, | |
398 | { 1, 3, 0, { PM2800_MOD_30V_10A, PM2800_MOD_30V_10A, PM2800_MOD_30V_10A } }, | |
399 | { 1, 3, 1, { PM2800_MOD_60V_5A, PM2800_MOD_60V_5A, PM2800_MOD_60V_5A } }, | |
400 | { 1, 3, 2, { PM2800_MOD_30V_10A, PM2800_MOD_30V_10A, PM2800_MOD_60V_5A } }, | |
401 | { 1, 3, 3, { PM2800_MOD_30V_10A, PM2800_MOD_60V_5A, PM2800_MOD_60V_5A } }, | |
402 | /* Linear chassis. */ | |
403 | { 3, 1, 0, { PM2800_MOD_60V_2A, 0, 0 } }, | |
404 | { 3, 1, 1, { PM2800_MOD_120V_1A, 0, 0 } }, | |
405 | { 3, 1, 2, { PM2800_MOD_8V_15A, 0, 0 } }, | |
406 | { 3, 2, 0, { PM2800_MOD_60V_2A, 0, 0 } }, | |
407 | { 3, 2, 1, { PM2800_MOD_120V_1A, 0, 0 } }, | |
408 | { 3, 2, 2, { PM2800_MOD_60V_2A, PM2800_MOD_120V_1A, 0 } }, | |
409 | { 3, 2, 3, { PM2800_MOD_8V_15A, PM2800_MOD_8V_15A, 0 } }, | |
410 | }; | |
411 | ||
412 | static const char *philips_pm2800_names[] = { "1", "2", "3" }; | |
413 | ||
414 | static int philips_pm2800_probe_channels(struct sr_dev_inst *sdi, | |
415 | struct sr_scpi_hw_info *hw_info, | |
416 | struct channel_spec **channels, unsigned int *num_channels, | |
417 | struct channel_group_spec **channel_groups, unsigned int *num_channel_groups) | |
418 | { | |
419 | const struct philips_pm2800_model *model; | |
420 | const struct philips_pm2800_module_spec *spec; | |
421 | unsigned int chassis, num_modules, set, module, m, i; | |
422 | ||
423 | (void)sdi; | |
424 | ||
425 | /* | |
426 | * The model number as reported by *IDN? looks like e.g. PM2813/11, | |
427 | * Where "PM28" is fixed, followed by the chassis code (1 = autoranging, | |
428 | * 3 = linear series) and the number of modules: 1-3 for autoranging, | |
429 | * 1-2 for linear. | |
430 | * After the slash, the first digit denotes the module set. The | |
431 | * digit after that denotes front (5) or rear (1) binding posts. | |
432 | */ | |
433 | chassis = hw_info->model[4] - 0x30; | |
434 | num_modules = hw_info->model[5] - 0x30; | |
435 | set = hw_info->model[7] - 0x30; | |
436 | for (m = 0; m < ARRAY_SIZE(philips_pm2800_matrix); m++) { | |
437 | model = &philips_pm2800_matrix[m]; | |
438 | if (model->chassis == chassis && model->num_modules == num_modules | |
439 | && model->set == set) | |
440 | break; | |
441 | } | |
442 | if (m == ARRAY_SIZE(philips_pm2800_matrix)) { | |
443 | sr_dbg("Model %s not found in matrix.", hw_info->model); | |
444 | return SR_ERR; | |
445 | } | |
446 | ||
447 | sr_dbg("Found %d output channel%s:", num_modules, num_modules > 1 ? "s" : ""); | |
448 | *channels = g_malloc0(sizeof(struct channel_spec) * num_modules); | |
449 | *channel_groups = g_malloc0(sizeof(struct channel_group_spec) * num_modules); | |
450 | for (i = 0; i < num_modules; i++) { | |
451 | module = model->modules[i]; | |
452 | spec = &philips_pm2800_module_specs[module]; | |
453 | sr_dbg("output %d: %.0f - %.0fV, %.0f - %.0fA", i + 1, | |
454 | spec->voltage[0], spec->voltage[1], | |
455 | spec->current[0], spec->current[1]); | |
456 | (*channels)[i].name = (char *)philips_pm2800_names[i]; | |
457 | memcpy(&((*channels)[i].voltage), spec, sizeof(float) * 6); | |
458 | (*channel_groups)[i].name = (char *)philips_pm2800_names[i]; | |
459 | (*channel_groups)[i].channel_index_mask = 1 << i; | |
460 | (*channel_groups)[i].features = PPS_OTP | PPS_OVP | PPS_OCP; | |
461 | } | |
462 | *num_channels = *num_channel_groups = num_modules; | |
463 | ||
464 | return SR_OK; | |
465 | } | |
466 | ||
467 | static const struct scpi_command philips_pm2800_cmd[] = { | |
468 | { SCPI_CMD_SELECT_CHANNEL, ":INST:NSEL %s" }, | |
469 | { SCPI_CMD_GET_MEAS_VOLTAGE, ":MEAS:VOLT?" }, | |
470 | { SCPI_CMD_GET_MEAS_CURRENT, ":MEAS:CURR?" }, | |
471 | { SCPI_CMD_GET_VOLTAGE_TARGET, ":SOUR:VOLT?" }, | |
472 | { SCPI_CMD_SET_VOLTAGE_TARGET, ":SOUR:VOLT %.6f" }, | |
473 | { SCPI_CMD_GET_CURRENT_LIMIT, ":SOUR:CURR?" }, | |
474 | { SCPI_CMD_SET_CURRENT_LIMIT, ":SOUR:CURR %.6f" }, | |
475 | { SCPI_CMD_GET_OUTPUT_ENABLED, ":OUTP?" }, | |
476 | { SCPI_CMD_SET_OUTPUT_ENABLE, ":OUTP ON" }, | |
477 | { SCPI_CMD_SET_OUTPUT_DISABLE, ":OUTP OFF" }, | |
478 | { SCPI_CMD_GET_OUTPUT_REGULATION, ":SOUR:FUNC:MODE?" }, | |
479 | { SCPI_CMD_GET_OVER_VOLTAGE_PROTECTION_ACTIVE, ":SOUR:VOLT:PROT:TRIP?" }, | |
480 | { SCPI_CMD_GET_OVER_VOLTAGE_PROTECTION_THRESHOLD, ":SOUR:VOLT:PROT:LEV?" }, | |
481 | { SCPI_CMD_SET_OVER_VOLTAGE_PROTECTION_THRESHOLD, ":SOUR:VOLT:PROT:LEV %.6f" }, | |
482 | { SCPI_CMD_GET_OVER_CURRENT_PROTECTION_ENABLED, ":SOUR:CURR:PROT:STAT?" }, | |
483 | { SCPI_CMD_SET_OVER_CURRENT_PROTECTION_ENABLE, ":SOUR:CURR:PROT:STAT ON" }, | |
484 | { SCPI_CMD_SET_OVER_CURRENT_PROTECTION_DISABLE, ":SOUR:CURR:PROT:STAT OFF" }, | |
485 | { SCPI_CMD_GET_OVER_CURRENT_PROTECTION_ACTIVE, ":SOUR:CURR:PROT:TRIP?" }, | |
486 | }; | |
487 | ||
488 | SR_PRIV const struct scpi_pps pps_profiles[] = { | |
489 | /* Agilent N5767A */ | |
490 | { "Agilent", "N5767A", 0, | |
491 | ARRAY_AND_SIZE(agilent_n5700a_devopts), | |
492 | ARRAY_AND_SIZE(agilent_n5700a_devopts_cg), | |
493 | ARRAY_AND_SIZE(agilent_n5767a_ch), | |
494 | ARRAY_AND_SIZE(agilent_n5767a_cg), | |
495 | ARRAY_AND_SIZE(agilent_n5700a_cmd), | |
496 | .probe_channels = NULL, | |
497 | }, | |
498 | /* Chroma 61604 */ | |
499 | { "Chroma", "61604", 0, | |
500 | ARRAY_AND_SIZE(chroma_61604_devopts), | |
501 | ARRAY_AND_SIZE(chroma_61604_devopts_cg), | |
502 | ARRAY_AND_SIZE(chroma_61604_ch), | |
503 | ARRAY_AND_SIZE(chroma_61604_cg), | |
504 | ARRAY_AND_SIZE(chroma_61604_cmd), | |
505 | .probe_channels = NULL, | |
506 | }, | |
507 | /* Chroma 62000 series */ | |
508 | { "Chroma", "620[0-9]{2}P-[0-9]{2,3}-[0-9]{1,3}", 0, | |
509 | ARRAY_AND_SIZE(chroma_62000_devopts), | |
510 | ARRAY_AND_SIZE(chroma_62000_devopts_cg), | |
511 | NULL, 0, | |
512 | NULL, 0, | |
513 | ARRAY_AND_SIZE(chroma_62000_cmd), | |
514 | .probe_channels = chroma_62000p_probe_channels, | |
515 | }, | |
516 | /* HP 6632B */ | |
517 | { "HP", "6632B", 0, | |
518 | ARRAY_AND_SIZE(hp_6632b_devopts), | |
519 | ARRAY_AND_SIZE(devopts_none), | |
520 | ARRAY_AND_SIZE(hp_6632b_ch), | |
521 | ARRAY_AND_SIZE(hp_6632b_cg), | |
522 | ARRAY_AND_SIZE(hp_6632b_cmd), | |
523 | .probe_channels = NULL, | |
524 | }, | |
525 | ||
526 | /* Rigol DP800 series */ | |
527 | { "Rigol", "^DP821A$", PPS_OTP, | |
528 | ARRAY_AND_SIZE(rigol_dp800_devopts), | |
529 | ARRAY_AND_SIZE(rigol_dp800_devopts_cg), | |
530 | ARRAY_AND_SIZE(rigol_dp821a_ch), | |
531 | ARRAY_AND_SIZE(rigol_dp820_cg), | |
532 | ARRAY_AND_SIZE(rigol_dp800_cmd), | |
533 | .probe_channels = NULL, | |
534 | }, | |
535 | { "Rigol", "^DP831A$", PPS_OTP, | |
536 | ARRAY_AND_SIZE(rigol_dp800_devopts), | |
537 | ARRAY_AND_SIZE(rigol_dp800_devopts_cg), | |
538 | ARRAY_AND_SIZE(rigol_dp831_ch), | |
539 | ARRAY_AND_SIZE(rigol_dp830_cg), | |
540 | ARRAY_AND_SIZE(rigol_dp800_cmd), | |
541 | .probe_channels = NULL, | |
542 | }, | |
543 | { "Rigol", "^(DP832|DP832A)$", PPS_OTP, | |
544 | ARRAY_AND_SIZE(rigol_dp800_devopts), | |
545 | ARRAY_AND_SIZE(rigol_dp800_devopts_cg), | |
546 | ARRAY_AND_SIZE(rigol_dp832_ch), | |
547 | ARRAY_AND_SIZE(rigol_dp830_cg), | |
548 | ARRAY_AND_SIZE(rigol_dp800_cmd), | |
549 | .probe_channels = NULL, | |
550 | }, | |
551 | ||
552 | /* Philips/Fluke PM2800 series */ | |
553 | { "Philips", "^PM28[13][123]/[01234]{1,2}$", 0, | |
554 | ARRAY_AND_SIZE(philips_pm2800_devopts), | |
555 | ARRAY_AND_SIZE(philips_pm2800_devopts_cg), | |
556 | NULL, 0, | |
557 | NULL, 0, | |
558 | ARRAY_AND_SIZE(philips_pm2800_cmd), | |
559 | philips_pm2800_probe_channels, | |
560 | }, | |
561 | }; | |
562 | ||
563 | SR_PRIV unsigned int num_pps_profiles = ARRAY_SIZE(pps_profiles); |