]>
git.zerfleddert.de Git - rigol/blob - rigol.c
6ae9d73dac9a3eb3f0d73b74f965e5ef7923a9dc
2 Sprite_tms hack to communicate with a Rigol DS1000-series scope using Linux.
3 This code is licensed under the GPL V3.
5 Warning: This code can in theory fubar the communications with the scope to a
6 point where the Linux USB-stack seems to get confused. Do a
7 rmmod uhci_hcd; modprobe uhci_hcd
8 (or alternately: use ohci_hcd) if that happens and you should be fine.
16 #include <sys/types.h>
23 #include <readline/readline.h>
24 #include <readline/history.h>
29 #define MIN(a,b) (((a)<(b))?(a):(b))
31 inline char printable (char ch
)
33 if (ch
< ' ') return '.';
34 if (ch
> '~') return '.';
38 //Debugging: Print a buffers contents in hex
39 void printb (unsigned char *pkt
, int len
)
43 for (i
=0;i
<len
;i
+= 16) {
45 for (j
=0;j
< MIN(len
-i
, 16);j
++) {
46 printf (" %02x", pkt
[i
+j
]);
47 if (j
== 7) printf (" ");
49 if (j
< 7) printf (" ");
53 for (j
=0;j
< MIN(len
-i
, 16);j
++) {
54 printf ("%c", printable (pkt
[i
+j
]));
63 char *readline (prompt
)
71 if (fgets (buf
, 1023, stdin
) == NULL
) {
76 if (buf
[l
-1] == '\n') {
82 void add_history (char *buf
)
87 void child_reaper(int sig
)
92 child
= waitpid(-1, NULL
, WNOHANG
);
97 int main(int argc
, char **argv
)
99 struct usb_dev_handle
*sc
;
103 struct sigaction act
;
106 sc
= usbtmc_initscope();
107 buff
= malloc (1024*1024);
113 bzero(&act
, sizeof(act
));
114 act
.sa_handler
= child_reaper
;
115 act
.sa_flags
= SA_NOCLDSTOP
|SA_RESTART
;
116 if (sigaction(SIGCHLD
, &act
, NULL
) == -1) {
122 scpi
= readline ("> ");
125 if (strlen (scpi
) == 0) {
132 if (strncmp (scpi
, "quit", 4) == 0) break;
133 if (strncmp (scpi
, "plot", 4) == 0) {
137 if (strncmp (scpi
, "databuf", 7) == 0) {
141 if (strncmp (scpi
, "screen", 6) == 0) {
145 if (strncmp (scpi
, "display", 7) == 0) {
146 do_display_screen(sc
);
151 //printf ("got buf(%d): ", l);
152 //printb (scpi, l+2);
153 if (strchr (scpi
, '?')) {
154 //printf ("Expecting reply\n");
155 l
= usbtmc_sendscpi(sc
, scpi
, buff
, 1024*1024);
156 //printf ("Got replylen = %d.\n", l);
157 buff
[l
] = 0; //zero-terminate
160 //printf ("No reply expected\n");
161 l
=usbtmc_sendscpi(sc
,scpi
,NULL
,0);
165 //Disable keylock, so the user doesn't have to press the 'force'-button
166 l
=usbtmc_sendscpi(sc
, ":KEY:LOCK DISABLE",NULL
,0);