]> git.zerfleddert.de Git - rigol/blob - scope.c
862f32b396e1d93007ec084b6718d445dd03ad4a
[rigol] / scope.c
1 #include <usb.h>
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <unistd.h>
5 #include <stdint.h>
6
7 #include "usbtmc.h"
8 #include "scope.h"
9
10 /* Just USB for now... */
11 int sendscpi(struct scope* sc, char* cmd, unsigned char *resp, int resplen)
12 {
13 return usbtmc_sendscpi(sc->usbdev, cmd, resp, resplen);
14 }
15
16 void closescope(struct scope* sc)
17 {
18 return usbtmc_close(sc->usbdev);
19 }
20
21 void claimscope(struct scope* sc)
22 {
23 return usbtmc_claim(sc->usbdev);
24 }
25
26 void releasescope(struct scope* sc)
27 {
28 //Disable keylock, so the user doesn't have to press the 'force'-button
29 sendscpi(sc, ":KEY:LOCK DISABLE",NULL,0);
30 return usbtmc_release(sc->usbdev);
31 }
32
33 struct scope* initscope(void)
34 {
35 struct usb_dev_handle *usbdev;
36 struct scope *sc;
37
38 usbdev = usbtmc_initscope();
39
40 if (!usbdev) {
41 printf("No scope found.\n");
42 exit(EXIT_FAILURE);
43 }
44
45 sc = calloc(1, sizeof(struct scope));
46 if (sc == NULL) {
47 perror("malloc");
48 exit(EXIT_FAILURE);
49 }
50
51 sc->usbdev = usbdev;
52
53 claimscope(sc);
54 sendscpi(sc, "*IDN?", (unsigned char*)sc->idn, sizeof(sc->idn));
55 releasescope(sc);
56
57 printf("Scope found (%s)\n", sc->idn);
58
59 return sc;
60 }
61
62 char *scope_idn(struct scope *sc)
63 {
64 return sc->idn;
65 }
Impressum, Datenschutz