]> git.zerfleddert.de Git - rigol/commitdiff
better error recovery
authorMichael Gernoth <michael@gernoth.net>
Mon, 7 Jun 2010 22:35:52 +0000 (00:35 +0200)
committerMichael Gernoth <michael@gernoth.net>
Mon, 7 Jun 2010 22:35:52 +0000 (00:35 +0200)
usbtmc.c

index 5b07ade655dc14a32ae28c8686acbcb31599bfd6..4a23a4fad953da902da62f41ea6d8563e9137a53 100644 (file)
--- a/usbtmc.c
+++ b/usbtmc.c
@@ -17,7 +17,7 @@
 #error BYTE_ORDER not defined/known!
 #endif
 
-#define USB_ERROR(x) do { if (x < 0) { fprintf(stderr, "usb: %s\n", usb_strerror()); exit(EXIT_FAILURE); } } while(0)
+#define USB_ERROR(s, x) do { if (x < 0) { fprintf(stderr, "usb %s: %s\n", s, usb_strerror()); usb_reset(sc->usb.dev); return 0; } } while(0)
 
 /* This routine locates a scope by VID/PID and returns a struct scope* for it */
 static struct scope* usbtmc_find_scope() {
@@ -93,16 +93,16 @@ int usbtmc_sendscpi(struct scope *sc, char* cmd,
                r=usb_bulk_write(sc->usb.dev, sc->usb.ep_bulk_out,
                        (char*)req, sizeof(struct usbtmc_header),
                        USB_TIMEOUT);
-               USB_ERROR(r);
+               USB_ERROR("USBTMC_DEV_DEP_MSG_OUT1", r);
 
                r=usb_bulk_write(sc->usb.dev, sc->usb.ep_bulk_out,
                        (char*)&(req->msg), len - sizeof(struct usbtmc_header),
                        USB_TIMEOUT);
-               USB_ERROR(r);
+               USB_ERROR("USBTMC_DEV_DEP_MSG_OUT2", r);
        } else {
                r=usb_bulk_write(sc->usb.dev, sc->usb.ep_bulk_out,
                        (char*)req, len, USB_TIMEOUT);
-               USB_ERROR(r);
+               USB_ERROR("USBTMC_DEV_DEP_MSG_OUT", r);
        }
 
        free(req);
@@ -124,13 +124,13 @@ int usbtmc_sendscpi(struct scope *sc, char* cmd,
                req->bTag = sc->usb.bTag;
                req->bTagInverse = ~sc->usb.bTag;
                req->TransferSize = LE32(sc->usb.wMaxPacketSize_in);
-               req->bmTransferAttributes = 0;
+               req->bmTransferAttributes = USBTMC_TRANSFERATTRIB_EOM;
                req->TermChar = 0;
 
                /* send read command */
                r=usb_bulk_write(sc->usb.dev, sc->usb.ep_bulk_out,
                        (char*)req, sizeof(struct usbtmc_header), USB_TIMEOUT);
-               USB_ERROR(r);
+               USB_ERROR("USBTMC_REQUEST_DEV_DEP_MSG_IN", r);
 
                free(req);
 
@@ -142,7 +142,7 @@ int usbtmc_sendscpi(struct scope *sc, char* cmd,
 
                r=usb_bulk_read(sc->usb.dev, sc->usb.ep_bulk_in,
                        (char*)buff, sc->usb.wMaxPacketSize_in, USB_TIMEOUT);
-               USB_ERROR(r);
+               USB_ERROR("USBTMC_DEV_DEP_MSG_IN1", r);
 
                if (r < sizeof(struct usbtmc_header)) {
                        fprintf(stderr, "Short read!\n");
@@ -166,7 +166,7 @@ int usbtmc_sendscpi(struct scope *sc, char* cmd,
                        r=usb_bulk_read(sc->usb.dev, sc->usb.ep_bulk_in,
                                (char*)buff + bytes_read, len - bytes_read,
                                USB_TIMEOUT);
-                       USB_ERROR(r);
+                       USB_ERROR("USBTMC_DEV_DEP_MSG_INx", r);
 
                        bytes_read += r;
                }
Impressum, Datenschutz