]>
git.zerfleddert.de Git - rigol/blob - scope.c
6013893107b34b609c2d3a87351a1fd3096bc197
11 /* Just USB for now... */
12 int sendscpi(struct scope
* sc
, char* cmd
, unsigned char *resp
, int resplen
)
14 return usbtmc_sendscpi(sc
, cmd
, resp
, resplen
);
17 void closescope(struct scope
* sc
)
19 return usbtmc_close(sc
);
22 void claimscope(struct scope
* sc
)
24 return usbtmc_claim(sc
);
27 void releasescope(struct scope
* sc
)
29 /* Disable keylock, so the user doesn't have to press the 'force'-button */
30 sendscpi(sc
, ":KEY:LOCK DISABLE",NULL
,0);
31 return usbtmc_release(sc
);
34 void resetscope(struct scope
* sc
)
36 return usbtmc_reset(sc
);
39 struct scope
* initscope(void)
43 sc
= usbtmc_initscope();
46 printf("No scope found.\n");
51 sendscpi(sc
, "*IDN?", (unsigned char*)sc
->idn
, sizeof(sc
->idn
));
54 printf("Scope found (%s)\n", sc
->idn
);
59 char *scope_idn(struct scope
*sc
)
64 #define COPY_SCOPE_STRING(sc, cmd, dst) { \
66 buf = scope_get_string(sc, cmd, sizeof(dst)); \
73 char *scope_get_string(struct scope
*sc
, char *cmd
, int maxlen
)
78 buf
= malloc(maxlen
+1);
80 perror("malloc(scope_get_strings)");
84 res
= sendscpi(sc
, cmd
, buf
, maxlen
);
86 fprintf(stderr
, "Command %s failed with %d\n", cmd
, res
);
96 int scope_get_truth_value(struct scope
*sc
, char *cmd
)
101 bzero(buf
, sizeof(buf
));
102 res
= sendscpi(sc
, cmd
, (unsigned char*)buf
, sizeof(buf
)-1);
104 fprintf(stderr
, "Command %s failed with %d\n", cmd
, res
);
108 printf("%s %s\n", cmd
, buf
);
110 if (strcasecmp(buf
, "on") == 0) {
112 } else if (strcasecmp(buf
, "enable") == 0) {
119 int scope_get_int(struct scope
*sc
, char *cmd
)
124 bzero(buf
, sizeof(buf
));
125 res
= sendscpi(sc
, cmd
, (unsigned char*)buf
, sizeof(buf
)-1);
127 fprintf(stderr
, "Command %s failed with %d\n", cmd
, res
);
134 double scope_get_double(struct scope
*sc
, char*cmd
)
140 bzero(buf
, sizeof(buf
));
141 res
= sendscpi(sc
, cmd
, (unsigned char*)buf
, sizeof(buf
)-1);
143 fprintf(stderr
, "Command %s failed with %d\n", cmd
, res
);
147 ret
= strtod(buf
, NULL
);
152 void update_scope_measurements(struct scope
*sc
)
154 sc
->status
.measure
.ch1
.vpp
= scope_get_double(sc
, ":MEAS:VPP? CHAN1");
155 sc
->status
.measure
.ch1
.vmax
= scope_get_double(sc
, ":MEAS:VMAX? CHAN1");
156 sc
->status
.measure
.ch1
.vmin
= scope_get_double(sc
, ":MEAS:VMIN? CHAN1");
157 sc
->status
.measure
.ch1
.vamplitude
= scope_get_double(sc
, ":MEAS:VAMP? CHAN1");
158 sc
->status
.measure
.ch1
.vtop
= scope_get_double(sc
, ":MEAS:VTOP? CHAN1");
159 sc
->status
.measure
.ch1
.vbase
= scope_get_double(sc
, ":MEAS:VBAS? CHAN1");
160 sc
->status
.measure
.ch1
.vaverage
= scope_get_double(sc
, ":MEAS:VAV? CHAN1");
161 sc
->status
.measure
.ch1
.vrms
= scope_get_double(sc
, ":MEAS:VRMS? CHAN1");
162 sc
->status
.measure
.ch1
.overshoot
= scope_get_double(sc
, ":MEAS:OVER? CHAN1");
163 sc
->status
.measure
.ch1
.preshoot
= scope_get_double(sc
, ":MEAS:PRES? CHAN1");
164 sc
->status
.measure
.ch1
.frequency
= scope_get_double(sc
, ":MEAS:FREQ? CHAN1");
165 sc
->status
.measure
.ch1
.risetime
= scope_get_double(sc
, ":MEAS:RIS? CHAN1");
166 sc
->status
.measure
.ch1
.falltime
= scope_get_double(sc
, ":MEAS:FALL? CHAN1");
167 sc
->status
.measure
.ch1
.period
= scope_get_double(sc
, ":MEAS:PER? CHAN1");
168 sc
->status
.measure
.ch1
.pwidth
= scope_get_double(sc
, ":MEAS:PWID? CHAN1");
169 sc
->status
.measure
.ch1
.nwidth
= scope_get_double(sc
, ":MEAS:NWID? CHAN1");
170 sc
->status
.measure
.ch1
.pdutycycle
= scope_get_double(sc
, ":MEAS:PDUT? CHAN1");
171 sc
->status
.measure
.ch1
.ndutycycle
= scope_get_double(sc
, ":MEAS:NDUT? CHAN1");
172 sc
->status
.measure
.ch1
.pdelay
= scope_get_double(sc
, ":MEAS:PDEL? CHAN1");
173 sc
->status
.measure
.ch1
.ndelay
= scope_get_double(sc
, ":MEAS:NDEL? CHAN1");
175 sc
->status
.measure
.ch2
.vpp
= scope_get_double(sc
, ":MEAS:VPP? CHAN2");
176 sc
->status
.measure
.ch2
.vmax
= scope_get_double(sc
, ":MEAS:VMAX? CHAN2");
177 sc
->status
.measure
.ch2
.vmin
= scope_get_double(sc
, ":MEAS:VMIN? CHAN2");
178 sc
->status
.measure
.ch2
.vamplitude
= scope_get_double(sc
, ":MEAS:VAMP? CHAN2");
179 sc
->status
.measure
.ch2
.vtop
= scope_get_double(sc
, ":MEAS:VTOP? CHAN2");
180 sc
->status
.measure
.ch2
.vbase
= scope_get_double(sc
, ":MEAS:VBAS? CHAN2");
181 sc
->status
.measure
.ch2
.vaverage
= scope_get_double(sc
, ":MEAS:VAV? CHAN2");
182 sc
->status
.measure
.ch2
.vrms
= scope_get_double(sc
, ":MEAS:VRMS? CHAN2");
183 sc
->status
.measure
.ch2
.overshoot
= scope_get_double(sc
, ":MEAS:OVER? CHAN2");
184 sc
->status
.measure
.ch2
.preshoot
= scope_get_double(sc
, ":MEAS:PRES? CHAN2");
185 sc
->status
.measure
.ch2
.frequency
= scope_get_double(sc
, ":MEAS:FREQ? CHAN2");
186 sc
->status
.measure
.ch2
.risetime
= scope_get_double(sc
, ":MEAS:RIS? CHAN2");
187 sc
->status
.measure
.ch2
.falltime
= scope_get_double(sc
, ":MEAS:FALL? CHAN2");
188 sc
->status
.measure
.ch2
.period
= scope_get_double(sc
, ":MEAS:PER? CHAN2");
189 sc
->status
.measure
.ch2
.pwidth
= scope_get_double(sc
, ":MEAS:PWID? CHAN2");
190 sc
->status
.measure
.ch2
.nwidth
= scope_get_double(sc
, ":MEAS:NWID? CHAN2");
191 sc
->status
.measure
.ch2
.pdutycycle
= scope_get_double(sc
, ":MEAS:PDUT? CHAN2");
192 sc
->status
.measure
.ch2
.ndutycycle
= scope_get_double(sc
, ":MEAS:NDUT? CHAN2");
193 sc
->status
.measure
.ch2
.pdelay
= scope_get_double(sc
, ":MEAS:PDEL? CHAN2");
194 sc
->status
.measure
.ch2
.ndelay
= scope_get_double(sc
, ":MEAS:NDEL? CHAN2");
196 sc
->status
.measure
.total
= scope_get_truth_value(sc
, ":MEAS:TOT?");
197 COPY_SCOPE_STRING(sc
, ":MEAS:SOUR?", sc
->status
.measure
.source
);
201 int update_scope_status(struct scope
*sc
)
203 bzero(&(sc
->status
), sizeof(sc
->status
));
205 COPY_SCOPE_STRING(sc
, ":INFO:LANG?", sc
->status
.system
.lang
);
207 sc
->status
.system
.counter_enabled
= scope_get_truth_value(sc
, ":COUN:ENAB?");
208 sc
->status
.system
.beep_enabled
= scope_get_truth_value(sc
, ":BEEP:ENAB?");
210 sc
->status
.keyboard
.key_lock
= scope_get_truth_value(sc
, ":KEY:LOCK?");
212 update_scope_measurements(sc
);
214 COPY_SCOPE_STRING(sc
, ":DISP:TYPE?", sc
->status
.display
.type
);
215 COPY_SCOPE_STRING(sc
, ":DISP:GRID?", sc
->status
.display
.grid
);
216 sc
->status
.display
.persist
= scope_get_truth_value(sc
, ":DISP:PERS?");
217 COPY_SCOPE_STRING(sc
, ":DISP:MNUD?", sc
->status
.display
.mnudisplay
);
218 sc
->status
.display
.mnustatus
= scope_get_truth_value(sc
, ":DISP:MNUS?");
219 COPY_SCOPE_STRING(sc
, ":DISP:SCR?", sc
->status
.display
.screen
);
220 sc
->status
.display
.brightness
= scope_get_int(sc
, ":DISP:BRIG?");
221 sc
->status
.display
.intensity
= scope_get_int(sc
, ":DISP:INT?");
223 COPY_SCOPE_STRING(sc
, ":ACQ:TYPE?", sc
->status
.acquire
.type
);
224 COPY_SCOPE_STRING(sc
, ":ACQ:MODE?", sc
->status
.acquire
.mode
);
226 sc
->status
.acquire
.averages
= scope_get_int(sc
, ":ACQ:AVER?");
227 sc
->status
.acquire
.srate_ch1
= scope_get_double(sc
, ":ACQ:SAMP? CHAN1");
228 sc
->status
.acquire
.srate_ch2
= scope_get_double(sc
, ":ACQ:SAMP? CHAN2");
229 sc
->status
.acquire
.srate_digital
= scope_get_double(sc
, ":ACQ:SAMP? DIGITAL");
231 COPY_SCOPE_STRING(sc
, ":TIM:MODE?", sc
->status
.timebase
.mode
);
232 sc
->status
.timebase
.offset
= scope_get_double(sc
, ":TIM:OFFS?");
233 sc
->status
.timebase
.delayed_offset
= scope_get_double(sc
, ":TIM:DEL:OFFS?");
234 sc
->status
.timebase
.scale
= scope_get_double(sc
, ":TIM:SCAL?");
235 COPY_SCOPE_STRING(sc
, ":TIM:FORM?", sc
->status
.timebase
.format
);