add struct for usbtmc header
[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 printf("No scope found.\n");
41 exit(EXIT_FAILURE);
42 }
43
44 sc = calloc(1, sizeof(struct scope));
45 if (sc == NULL) {
46 perror("malloc");
47 exit(EXIT_FAILURE);
48 }
49
50 sc->usbdev = usbdev;
51
52 claimscope(sc);
53 sendscpi(sc, "*IDN?", (unsigned char*)sc->idn, sizeof(sc->idn));
54 releasescope(sc);
55
56 printf("Scope found (%s)\n", sc->idn);
57
58 return sc;
59 }
60
61 char *scope_idn(struct scope *sc)
62 {
63 return sc->idn;
64 }
Impressum, Datenschutz