- struct usb_dev_handle *sc;
- char *scpi;
- unsigned char *buff;
- int l;
- //Init libusb
- usb_init();
- //Locate and open the scope
- sc=find_scope();
- if (!sc) {
- printf("No scope found.\n");
- exit(1);
- } else {
- printf("Scope found.\n");
- }
- //Initialize scope
- initscope(sc);
- buff = malloc (1024*1024);
- while (1) {
- scpi = readline ("> ");
-
- if (!scpi) break;
- if (strlen (scpi) == 0) {
- free (scpi);
- continue;
- }
-
- add_history (scpi);
-
- if (strncmp (scpi, "quit", 4) == 0) break;
- if (strncmp (scpi, "plot", 4) == 0) {
- do_plot (sc);
- continue;
- }
- if (strncmp (scpi, "databuf", 4) == 0) {
- do_get_buf (sc);
- continue;
- }
-
- l = strlen (scpi);
- // printf ("got buf(%d): ", l);
- // printb (scpi, l+2);
- if (strchr (scpi, '?')) {
- // printf ("Expecting reply\n");
- l = sendscpi(sc, scpi, buff, 1024*1024);
- // printf ("Got replylen = %d.\n", l);
- buff[l] = 0; //zero-terminate
- printb (buff, l);
- } else {
- // printf ("No reply expected\n");
- l=sendscpi(sc,scpi,NULL,0);
- }
- free (scpi);
- }
- //Disable keylock, so the user doesn't have to press the 'force'-button
- l=sendscpi(sc, ":KEY:LOCK DISABLE",NULL,0);
-
- //Free up and exit
- usb_release_interface(sc,0);
- usb_close(sc);
- return 0;
+ struct usb_dev_handle *sc;
+ char *scpi;
+ unsigned char *buff;
+ int l;
+ struct sigaction act;
+
+ //Init libusb
+ usb_init();
+ //Locate and open the scope
+ sc=find_scope();
+ if (!sc) {
+ printf("No scope found.\n");
+ exit(1);
+ } else {
+ printf("Scope found.\n");
+ }
+ //Initialize scope
+ initscope(sc);
+ buff = malloc (1024*1024);
+ if (buff == NULL) {
+ perror("malloc");
+ exit(EXIT_FAILURE);
+ }
+
+ bzero(&act, sizeof(act));
+ act.sa_handler = child_reaper;
+ act.sa_flags = SA_NOCLDSTOP|SA_RESTART;
+ if (sigaction(SIGCHLD, &act, NULL) == -1) {
+ perror("sigaction");
+ exit(EXIT_FAILURE);
+ }
+
+ while (1) {
+ scpi = readline ("> ");
+
+ if (!scpi) break;
+ if (strlen (scpi) == 0) {
+ free (scpi);
+ continue;
+ }
+
+ add_history (scpi);
+
+ if (strncmp (scpi, "quit", 4) == 0) break;
+ if (strncmp (scpi, "plot", 4) == 0) {
+ do_plot (sc);
+ continue;
+ }
+ if (strncmp (scpi, "databuf", 7) == 0) {
+ do_get_buf (sc);
+ continue;
+ }
+ if (strncmp (scpi, "screen", 6) == 0) {
+ do_get_screen (sc);
+ continue;
+ }
+
+ l = strlen (scpi);
+ //printf ("got buf(%d): ", l);
+ //printb (scpi, l+2);
+ if (strchr (scpi, '?')) {
+ //printf ("Expecting reply\n");
+ l = sendscpi(sc, scpi, buff, 1024*1024);
+ //printf ("Got replylen = %d.\n", l);
+ buff[l] = 0; //zero-terminate
+ printb (buff, l);
+ } else {
+ //printf ("No reply expected\n");
+ l=sendscpi(sc,scpi,NULL,0);
+ }
+ free (scpi);
+ }
+ //Disable keylock, so the user doesn't have to press the 'force'-button
+ l=sendscpi(sc, ":KEY:LOCK DISABLE",NULL,0);
+
+ //Free up and exit
+ usb_release_interface(sc,0);
+ usb_close(sc);
+ return 0;