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