]> git.zerfleddert.de Git - rigol/commitdiff
defines for STATUS bytes
authorMichael Gernoth <michael@gernoth.net>
Tue, 8 Jun 2010 10:01:14 +0000 (12:01 +0200)
committerMichael Gernoth <michael@gernoth.net>
Tue, 8 Jun 2010 10:01:14 +0000 (12:01 +0200)
usbtmc.c
usbtmc.h

index ffebcbff952b82dc2a4b358f6d8cf1e6166b9fee..732b8f6d19691fccabdeffc60f9086c4e25eb94e 100644 (file)
--- a/usbtmc.c
+++ b/usbtmc.c
@@ -60,7 +60,7 @@ static struct scope* usbtmc_find_scope() {
        return NULL;
 }
 
-static unsigned char usbtmc_status(struct scope *sc)
+static unsigned char usb488_status(struct scope *sc)
 {
        int r;
        unsigned char status[3];
@@ -72,7 +72,7 @@ static unsigned char usbtmc_status(struct scope *sc)
                (sc->usb.bTag & 0x7f), 0, (char*)status, 3,
                USB_TIMEOUT);
 
-       if ((r != 3) || (status[0] != 0x01) || (status[1] != (sc->usb.bTag & 0x7f))) {
+       if ((r != 3) || (status[0] != USBTMC_STATUS_SUCCESS) || (status[1] != (sc->usb.bTag & 0x7f))) {
                printf("READ_STATUS_BYTE failed: %d 0x%x 0x%x 0x%x\n", r, status[0], status[1], status[2]);
                return 0xff;
        }
@@ -144,8 +144,8 @@ static void usbtmc_clear(struct scope *sc)
                0, 0, (char*)status, 1,
                USB_TIMEOUT);
        
-       if ((r != 1) || status[0] != 0x01) {
-               printf("INITIATE_CLEAR failed: %s\n", usb_strerror());
+       if ((r != 1) || status[0] != USBTMC_STATUS_SUCCESS) {
+               printf("INITIATE_CLEAR failed (0x%x): %s\n", status[0], usb_strerror());
                return;
        }
 
@@ -158,12 +158,17 @@ static void usbtmc_clear(struct scope *sc)
                        0, 0, (char*)status, 2,
                        USB_TIMEOUT);
 
-               if ((r != 2) || status[0] != 0x01) {
+               if (r != 2) {
                        printf("CHECK_CLEAR failed: %s\n", usb_strerror());
                        return;
                }
 
-               if (status[1] & (1<<0)) {
+               if (USBTMC_STATUS_FAIL(status[0])) {
+                       printf("CHECK_CLEAR failed: 0x%x\n", status[0]);
+                       return;
+               }
+
+               if ((status[0] == USBTMC_STATUS_SUCCESS) && (status[1] == 0)) {
                        printf("Success!\n");
                        break;
                }
@@ -323,7 +328,7 @@ struct scope* usbtmc_initscope(void) {
 
        usbtmc_claim(sc);
        sc->usb.cap = usbtmc_get_capabilities(sc);
-       printf("Device status: 0x%x\n", usbtmc_status(sc));
+       printf("Device status: 0x%x\n", usb488_status(sc));
        /* The following code isn't really necessary, the program works
           OK without it too. */
        r=usb_control_msg(sc->usb.dev, 0xC8, 9, 0, 0, (char*)&vidpid, 4, USB_TIMEOUT);
index 1fa1046009aa2f791e6019983b6e339a9d001966..3734ff5d3aa0a4d11517f39d9e31c422e8cdbcbf 100644 (file)
--- a/usbtmc.h
+++ b/usbtmc.h
@@ -56,6 +56,17 @@ struct usbtmc_capabilities {
 #define USB488_CAP_DEV_RL1             (1<<1)
 #define USB488_CAP_DEV_DT1             (1<<0)
 
+#define USBTMC_STATUS_SUCCESS          0x01
+#define USBTMC_STATUS_PENDING          0x02
+#define USBTMC_STATUS_FAILED           0x80
+#define USBTMC_STATUS_TRANS_NIP                0x81
+#define USBTMC_STATUS_SPLIT_NIP                0x82
+#define USBTMC_STATUS_SPLIT_IP         0x83
+
+#define USBTMC_STATUS_SUCC(x)  (x == USBTMC_STATUS_SUCCESS)
+#define USBTMC_STATUS_WARN(x)  ((x > USBTMC_STATUS_SUCCESS) && (x < USBTMC_STATUS_FAILED))
+#define USBTMC_STATUS_FAIL(x)  (x >= USBTMC_STATUS_FAILED)
+
 int usbtmc_sendscpi(struct scope *sc, char* cmd, unsigned char *resp, int resplen);
 struct scope * usbtmc_initscope(void);
 void usbtmc_close(struct scope *sc);
Impressum, Datenschutz