]>
git.zerfleddert.de Git - rigol/blob - scope.c
eab7750c64c76fa8dd3dbb76354f2a8d03e74d64
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 int update_scope_status(struct scope
*sc
)
154 bzero(&(sc
->status
), sizeof(sc
->status
));
156 COPY_SCOPE_STRING(sc
, ":INFO:LANG?", sc
->status
.system
.lang
);
158 sc
->status
.system
.counter_enabled
= scope_get_truth_value(sc
, ":COUN:ENAB?");
159 sc
->status
.system
.beep_enabled
= scope_get_truth_value(sc
, ":BEEP:ENAB?");
161 sc
->status
.keyboard
.key_lock
= scope_get_truth_value(sc
, ":KEY:LOCK?");
163 COPY_SCOPE_STRING(sc
, ":ACQ:TYPE?", sc
->status
.acquire
.type
);
164 COPY_SCOPE_STRING(sc
, ":ACQ:MODE?", sc
->status
.acquire
.mode
);
166 sc
->status
.acquire
.averages
= scope_get_int(sc
, ":ACQ:AVER?");
167 sc
->status
.acquire
.srate_chan1
= scope_get_double(sc
, ":ACQ:SAMP? CHAN1");
168 sc
->status
.acquire
.srate_chan2
= scope_get_double(sc
, ":ACQ:SAMP? CHAN2");
169 sc
->status
.acquire
.srate_digital
= scope_get_double(sc
, ":ACQ:SAMP? DIGITAL");
171 COPY_SCOPE_STRING(sc
, ":TIM:MODE?", sc
->status
.timebase
.mode
);
172 sc
->status
.timebase
.offset
= scope_get_double(sc
, ":TIM:OFFS?");
173 sc
->status
.timebase
.delayed_offset
= scope_get_double(sc
, ":TIM:DEL:OFFS?");
174 sc
->status
.timebase
.scale
= scope_get_double(sc
, ":TIM:SCAL?");
175 COPY_SCOPE_STRING(sc
, ":TIM:FORM?", sc
->status
.timebase
.format
);