]>
cvs.zerfleddert.de Git - rigol/blob - rigol.c
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.
15 #include <sys/types.h>
22 #include <readline/readline.h>
23 #include <readline/history.h>
28 #define MIN(a,b) (((a)<(b))?(a):(b))
30 inline char printable (char ch
)
32 if (ch
< ' ') return '.';
33 if (ch
> '~') return '.';
37 //Debugging: Print a buffers contents in hex
38 void printb (unsigned char *pkt
, int len
)
42 for (i
=0;i
<len
;i
+= 16) {
44 for (j
=0;j
< MIN(len
-i
, 16);j
++) {
45 printf (" %02x", pkt
[i
+j
]);
46 if (j
== 7) printf (" ");
48 if (j
< 7) printf (" ");
52 for (j
=0;j
< MIN(len
-i
, 16);j
++) {
53 printf ("%c", printable (pkt
[i
+j
]));
62 char *readline (prompt
)
70 if (fgets (buf
, 1023, stdin
) == NULL
) {
75 if (buf
[l
-1] == '\n') {
81 void add_history (char *buf
)
86 void child_reaper(int sig
)
91 child
= waitpid(-1, NULL
, WNOHANG
);
96 int main(int argc
, char **argv
)
102 struct sigaction act
;
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
= 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
=sendscpi(sc
,scpi
,NULL
,0);