#include "scope.h"
#include "usbtmc.h"
+#define DATASIZE 10240
+
+#define COPY_SCOPE_STRING(sc, cmd, dst) { \
+ char *buf; \
+ buf = scope_get_string(sc, cmd, sizeof(dst)); \
+ if (buf) { \
+ strcpy(dst, buf); \
+ free(buf); \
+ }\
+ }
+
/* Just USB for now... */
int sendscpi(struct scope* sc, char* cmd, unsigned char *resp, int resplen)
{
}
claimscope(sc);
- sendscpi(sc, "*IDN?", (unsigned char*)sc->idn, sizeof(sc->idn));
+ COPY_SCOPE_STRING(sc, "*IDN?", sc->idn);
releasescope(sc);
printf("Scope found (%s)\n", sc->idn);
return sc->idn;
}
-#define COPY_SCOPE_STRING(sc, cmd, dst) { \
- char *buf; \
- buf = scope_get_string(sc, cmd, sizeof(dst)); \
- if (buf) { \
- strcpy(dst, buf); \
- free(buf); \
- }\
- }
-
char *scope_get_string(struct scope *sc, char *cmd, int maxlen)
{
unsigned char *buf;
return 0;
}
- printf("%s %s\n", cmd, buf);
-
if (strcasecmp(buf, "on") == 0) {
return 1;
} else if (strcasecmp(buf, "enable") == 0) {
return ret;
}
+char *scope_get_data(struct scope *sc, char *source, int *len)
+{
+ char *data = NULL;
+ char cmd[128];
+
+ if ((data = malloc(DATASIZE)) == NULL) {
+ perror("malloc");
+ return NULL;
+ }
+
+ snprintf(cmd, sizeof(cmd), ":WAV:DATA? %s", source);
+ *len = sendscpi(sc, cmd, (unsigned char*)data, DATASIZE);
+
+ return data;
+}
+
void update_scope_measurements(struct scope *sc)
{
sc->status.measure.ch1.vpp = scope_get_double(sc, ":MEAS:VPP? CHAN1");
}
+void update_scope_channel(struct scope *sc, int channel)
+{
+ struct channel_s *ch;
+ char cmd[128];
+ int offs;
+
+ if (channel == 1) {
+ ch = &(sc->status.channel.ch1);
+ strcpy(cmd, ":CHAN1:");
+ } else if (channel == 2) {
+ ch = &(sc->status.channel.ch2);
+ strcpy(cmd, ":CHAN2:");
+ } else {
+ fprintf(stderr, "Unknown channel %d!\n", channel);
+ return;
+ }
+
+ offs=strlen(cmd);
+
+ strcpy(cmd + offs, "BWL?"); ch->bwlimit_enabled = scope_get_truth_value(sc, cmd);
+ strcpy(cmd + offs, "COUP?"); COPY_SCOPE_STRING(sc, cmd, ch->coupling);
+ strcpy(cmd + offs, "DISP?"); ch->displayed = scope_get_truth_value(sc, cmd);
+ strcpy(cmd + offs, "INV?"); ch->inverted = scope_get_truth_value(sc, cmd);
+ strcpy(cmd + offs, "OFFS?"); ch->offset = scope_get_double(sc, cmd);
+ strcpy(cmd + offs, "PROB?"); ch->probe = scope_get_double(sc, cmd);
+ strcpy(cmd + offs, "SCAL?"); ch->scale = scope_get_double(sc, cmd);
+ strcpy(cmd + offs, "FILT?"); ch->filter_enabled = scope_get_truth_value(sc, cmd);
+ strcpy(cmd + offs, "MEMD?"); ch->memory_depth = scope_get_int(sc, cmd);
+ strcpy(cmd + offs, "VERN?"); COPY_SCOPE_STRING(sc, cmd, ch->vernier);
+}
+
int update_scope_status(struct scope *sc)
{
bzero(&(sc->status), sizeof(sc->status));
sc->status.display.brightness = scope_get_int(sc, ":DISP:BRIG?");
sc->status.display.intensity = scope_get_int(sc, ":DISP:INT?");
+ update_scope_channel(sc, 1);
+ update_scope_channel(sc, 2);
+
COPY_SCOPE_STRING(sc, ":ACQ:TYPE?", sc->status.acquire.type);
COPY_SCOPE_STRING(sc, ":ACQ:MODE?", sc->status.acquire.mode);
sc->status.timebase.scale = scope_get_double(sc, ":TIM:SCAL?");
COPY_SCOPE_STRING(sc, ":TIM:FORM?", sc->status.timebase.format);
+ sc->status.math.displayed = scope_get_truth_value(sc, ":MATH:DISP?");
+ sc->status.fft.displayed = scope_get_truth_value(sc, ":FFT:DISP?");
+
return 0;
}