]> sigrok.org Git - libsigrok.git/blame - src/hardware/yokogawa-dlm/protocol_wrappers.c
cem-dt-885x: Add a missing break statement.
[libsigrok.git] / src / hardware / yokogawa-dlm / protocol_wrappers.c
CommitLineData
10763937
SA
1/*
2 * This file is part of the libsigrok project.
3 *
4 * Copyright (C) 2014 abraxa (Soeren Apel) <soeren@apelpie.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
20#include "protocol_wrappers.h"
21
8ab929d6
SA
22#define MAX_COMMAND_SIZE 64
23
24/*
25 * DLM2000 comm spec:
26 * https://www.yokogawa.com/pdf/provide/E/GW/IM/0000022842/0/IM710105-17E.pdf
27 */
28
29int dlm_timebase_get(struct sr_scpi_dev_inst *scpi,
30 gchar **response)
31{
32 return sr_scpi_get_string(scpi, ":TIMEBASE:TDIV?", response);
33}
34
35int dlm_timebase_set(struct sr_scpi_dev_inst *scpi,
36 const gchar *value)
37{
38 gchar cmd[MAX_COMMAND_SIZE];
39 g_snprintf(cmd, sizeof(cmd), ":TIMEBASE:TDIV %s", value);
40 return sr_scpi_send(scpi, cmd);
41}
42
43int dlm_horiz_trigger_pos_get(struct sr_scpi_dev_inst *scpi,
44 float *response)
45{
46 return sr_scpi_get_float(scpi, ":TRIGGER:DELAY:TIME?", response);
47}
48
49int dlm_horiz_trigger_pos_set(struct sr_scpi_dev_inst *scpi,
50 const gchar *value)
51{
52 gchar cmd[MAX_COMMAND_SIZE];
53 g_snprintf(cmd, sizeof(cmd), ":TRIGGER:DELAY:TIME %s", value);
54 return sr_scpi_send(scpi, cmd);
55}
56
57int dlm_trigger_source_get(struct sr_scpi_dev_inst *scpi,
58 gchar **response)
59{
60 return sr_scpi_get_string(scpi, ":TRIGGER:ATRIGGER:SIMPLE:SOURCE?", response);
61}
62
63int dlm_trigger_source_set(struct sr_scpi_dev_inst *scpi,
64 const gchar *value)
65{
66 gchar cmd[MAX_COMMAND_SIZE];
67 g_snprintf(cmd, sizeof(cmd), ":TRIGGER:ATRIGGER:SIMPLE:SOURCE %s", value);
68 return sr_scpi_send(scpi, cmd);
69}
70
71int dlm_trigger_slope_get(struct sr_scpi_dev_inst *scpi,
72 int *response)
73{
74 gchar *resp;
75 int result;
76
77 result = SR_ERR;
78
79 if (sr_scpi_get_string(scpi, ":TRIGGER:ATRIGGER:SIMPLE:SLOPE?", &resp) != SR_OK) {
80 g_free(resp);
81 return SR_ERR;
82 }
83
84 if (strcmp("RISE", resp) == 0) {
85 *response = SLOPE_POSITIVE;
86 result = SR_OK;
87 }
88
89 if (strcmp("FALL", resp) == 0) {
90 *response = SLOPE_NEGATIVE;
91 result = SR_OK;
92 }
93
94 g_free(resp);
95 return result;
96}
97
98int dlm_trigger_slope_set(struct sr_scpi_dev_inst *scpi,
99 const int value)
100{
101 if (value == SLOPE_POSITIVE)
102 return sr_scpi_send(scpi, ":TRIGGER:ATRIGGER:SIMPLE:SLOPE RISE");
103
104 if (value == SLOPE_NEGATIVE)
105 return sr_scpi_send(scpi, ":TRIGGER:ATRIGGER:SIMPLE:SLOPE FALL");
106
107 return SR_ERR_ARG;
108}
109
110int dlm_analog_chan_state_get(struct sr_scpi_dev_inst *scpi, int channel,
111 gboolean *response)
112{
113 gchar cmd[MAX_COMMAND_SIZE];
114 g_snprintf(cmd, sizeof(cmd), ":CHANNEL%d:DISPLAY?", channel);
115 return sr_scpi_get_bool(scpi, cmd, response);
116}
117
118int dlm_analog_chan_state_set(struct sr_scpi_dev_inst *scpi, int channel,
119 const gboolean value)
120{
121 gchar cmd[MAX_COMMAND_SIZE];
122
123 if (value)
124 g_snprintf(cmd, sizeof(cmd), ":CHANNEL%d:DISPLAY ON", channel);
125 else
126 g_snprintf(cmd, sizeof(cmd), ":CHANNEL%d:DISPLAY OFF", channel);
127
128 return sr_scpi_send(scpi, cmd);
129}
130
131int dlm_analog_chan_vdiv_get(struct sr_scpi_dev_inst *scpi, int channel,
132 gchar **response)
133{
134 gchar cmd[MAX_COMMAND_SIZE];
135 g_snprintf(cmd, sizeof(cmd), ":CHANNEL%d:VDIV?", channel);
136 return sr_scpi_get_string(scpi, cmd, response);
137}
138
139int dlm_analog_chan_vdiv_set(struct sr_scpi_dev_inst *scpi, int channel,
140 const gchar *value)
141{
142 gchar cmd[MAX_COMMAND_SIZE];
143 g_snprintf(cmd, sizeof(cmd), ":CHANNEL%d:VDIV %s", channel, value);
144 return sr_scpi_send(scpi, cmd);
145}
146
147int dlm_analog_chan_voffs_get(struct sr_scpi_dev_inst *scpi, int channel,
148 float *response)
149{
150 gchar cmd[MAX_COMMAND_SIZE];
151 g_snprintf(cmd, sizeof(cmd), ":CHANNEL%d:POSITION?", channel);
152 return sr_scpi_get_float(scpi, cmd, response);
153}
154
155int dlm_analog_chan_srate_get(struct sr_scpi_dev_inst *scpi, int channel,
156 float *response)
157{
158 gchar cmd[MAX_COMMAND_SIZE];
159 g_snprintf(cmd, sizeof(cmd), ":WAVEFORM:TRACE %d", channel);
160
161 if (sr_scpi_send(scpi, cmd) != SR_OK)
162 return SR_ERR;
163
164 g_snprintf(cmd, sizeof(cmd), ":WAVEFORM:RECORD 0");
165 if (sr_scpi_send(scpi, cmd) != SR_OK)
166 return SR_ERR;
167
168 return sr_scpi_get_float(scpi, ":WAVEFORM:SRATE?", response);
169}
170
171int dlm_analog_chan_coupl_get(struct sr_scpi_dev_inst *scpi, int channel,
172 gchar **response)
173{
174 gchar cmd[MAX_COMMAND_SIZE];
175 g_snprintf(cmd, sizeof(cmd), ":CHANNEL%d:COUPLING?", channel);
176 return sr_scpi_get_string(scpi, cmd, response);
177}
178
179int dlm_analog_chan_coupl_set(struct sr_scpi_dev_inst *scpi, int channel,
180 const gchar *value)
181{
182 gchar cmd[MAX_COMMAND_SIZE];
183 g_snprintf(cmd, sizeof(cmd), ":CHANNEL%d:COUPLING %s", channel, value);
184 return sr_scpi_send(scpi, cmd);
185}
186
187int dlm_analog_chan_wrange_get(struct sr_scpi_dev_inst *scpi, int channel,
188 float *response)
189{
190 gchar cmd[MAX_COMMAND_SIZE];
191 int result;
192
193 g_snprintf(cmd, sizeof(cmd), ":WAVEFORM:TRACE %d", channel);
194 result = sr_scpi_send(scpi, cmd);
195 result &= sr_scpi_get_float(scpi, ":WAVEFORM:RANGE?", response);
196 return result;
197}
198
199int dlm_analog_chan_woffs_get(struct sr_scpi_dev_inst *scpi, int channel,
200 float *response)
201{
202 gchar cmd[MAX_COMMAND_SIZE];
203 int result;
204
205 g_snprintf(cmd, sizeof(cmd), ":WAVEFORM:TRACE %d", channel);
206 result = sr_scpi_send(scpi, cmd);
207 result &= sr_scpi_get_float(scpi, ":WAVEFORM:OFFSET?", response);
208 return result;
209}
210
211int dlm_digital_chan_state_get(struct sr_scpi_dev_inst *scpi, int channel,
212 gboolean *response)
213{
214 gchar cmd[MAX_COMMAND_SIZE];
215 g_snprintf(cmd, sizeof(cmd), ":LOGIC:PODA:BIT%d:DISPLAY?", channel);
216 return sr_scpi_get_bool(scpi, cmd, response);
217}
218
219int dlm_digital_chan_state_set(struct sr_scpi_dev_inst *scpi, int channel,
220 const gboolean value)
221{
222 gchar cmd[MAX_COMMAND_SIZE];
223
224 if (value)
225 g_snprintf(cmd, sizeof(cmd), ":LOGIC:PODA:BIT%d:DISPLAY ON", channel);
226 else
227 g_snprintf(cmd, sizeof(cmd), ":LOGIC:PODA:BIT%d:DISPLAY OFF", channel);
228
229 return sr_scpi_send(scpi, cmd);
230}
231
232int dlm_digital_pod_state_get(struct sr_scpi_dev_inst *scpi, int pod,
233 gboolean *response)
234{
235 gchar cmd[MAX_COMMAND_SIZE];
236
237 /* TODO: pod currently ignored as DLM2000 only has pod A. */
238 (void)pod;
239
240 g_snprintf(cmd, sizeof(cmd), ":LOGIC:MODE?");
241 return sr_scpi_get_bool(scpi, cmd, response);
242}
243
244int dlm_digital_pod_state_set(struct sr_scpi_dev_inst *scpi, int pod,
245 const gboolean value)
246{
247 /* TODO: pod currently ignored as DLM2000 only has pod A. */
248 (void)pod;
249
250 if (value)
251 return sr_scpi_send(scpi, ":LOGIC:MODE ON");
252 else
253 return sr_scpi_send(scpi, ":LOGIC:MODE OFF");
254}
255
8ab929d6
SA
256int dlm_response_headers_set(struct sr_scpi_dev_inst *scpi,
257 const gboolean value)
258{
259 if (value)
260 return sr_scpi_send(scpi, ":COMMUNICATE:HEADER ON");
261 else
262 return sr_scpi_send(scpi, ":COMMUNICATE:HEADER OFF");
263}
264
265int dlm_acquisition_stop(struct sr_scpi_dev_inst *scpi)
266{
267 return sr_scpi_send(scpi, ":STOP");
268}
269
8ab929d6 270int dlm_acq_length_get(struct sr_scpi_dev_inst *scpi,
af3487ec 271 uint32_t *response)
8ab929d6 272{
af3487ec
SA
273 int ret;
274 char *s;
275 long tmp;
276
277 if (sr_scpi_get_string(scpi, ":WAVEFORM:LENGTH?", &s) != SR_OK)
278 if (!s)
279 return SR_ERR;
280
281 if (sr_atol(s, &tmp) == SR_OK)
282 ret = SR_OK;
283 else
284 ret = SR_ERR;
285
286 g_free(s);
287 *response = tmp;
288
289 return ret;
8ab929d6
SA
290}
291
292int dlm_chunks_per_acq_get(struct sr_scpi_dev_inst *scpi, int *response)
293{
294 int result, acq_len;
295
296 /* Data retrieval queries such as :WAVEFORM:SEND? will only return
297 * up to 12500 samples at a time. If the oscilloscope operates in a
298 * mode where more than 12500 samples fit on screen (i.e. in one
299 * acquisition), data needs to be retrieved multiple times.
300 */
301
302 result = sr_scpi_get_int(scpi, ":WAVEFORM:LENGTH?", &acq_len);
303 *response = MAX(acq_len / DLM_MAX_FRAME_LENGTH, 1);
304
305 return result;
306}
307
308int dlm_start_frame_set(struct sr_scpi_dev_inst *scpi, int value)
309{
310 gchar cmd[MAX_COMMAND_SIZE];
311
312 g_snprintf(cmd, sizeof(cmd), ":WAVEFORM:START %d",
313 value * DLM_MAX_FRAME_LENGTH);
314
315 return sr_scpi_send(scpi, cmd);
316}
317
318int dlm_data_get(struct sr_scpi_dev_inst *scpi, int acquisition_num)
319{
320 gchar cmd[MAX_COMMAND_SIZE];
321
322 g_snprintf(cmd, sizeof(cmd), ":WAVEFORM:ALL:SEND? %d", acquisition_num);
323 return sr_scpi_send(scpi, cmd);
324}
325
326int dlm_analog_data_get(struct sr_scpi_dev_inst *scpi, int channel)
327{
328 gchar cmd[MAX_COMMAND_SIZE];
329 int result;
330
331 result = sr_scpi_send(scpi, ":WAVEFORM:FORMAT BYTE");
332 if (result == SR_OK) result = sr_scpi_send(scpi, ":WAVEFORM:RECORD 0");
333 if (result == SR_OK) result = sr_scpi_send(scpi, ":WAVEFORM:START 0");
334 if (result == SR_OK) result = sr_scpi_send(scpi, ":WAVEFORM:END 124999999");
335
336 g_snprintf(cmd, sizeof(cmd), ":WAVEFORM:TRACE %d", channel);
337 if (result == SR_OK) result = sr_scpi_send(scpi, cmd);
338
339 if (result == SR_OK) result = sr_scpi_send(scpi, ":WAVEFORM:SEND? 1");
340
341 return result;
342}
343
344int dlm_digital_data_get(struct sr_scpi_dev_inst *scpi)
345{
346 int result;
347
348 result = sr_scpi_send(scpi, ":WAVEFORM:FORMAT BYTE");
349 if (result == SR_OK) result = sr_scpi_send(scpi, ":WAVEFORM:RECORD 0");
350 if (result == SR_OK) result = sr_scpi_send(scpi, ":WAVEFORM:START 0");
351 if (result == SR_OK) result = sr_scpi_send(scpi, ":WAVEFORM:END 124999999");
352 if (result == SR_OK) result = sr_scpi_send(scpi, ":WAVEFORM:TRACE LOGIC");
353 if (result == SR_OK) result = sr_scpi_send(scpi, ":WAVEFORM:SEND? 1");
354
355 return result;
356}