]> git.zerfleddert.de Git - rigol/blobdiff - usbtmc.c
use uint32_t for vid/pid request
[rigol] / usbtmc.c
index 4a23a4fad953da902da62f41ea6d8563e9137a53..6af5a13dc2c7a64d45e2404afd9ec18135b80551 100644 (file)
--- a/usbtmc.c
+++ b/usbtmc.c
@@ -59,6 +59,22 @@ static struct scope* usbtmc_find_scope() {
        return NULL;
 }
 
+unsigned char usbtmc_status(struct scope *sc)
+{
+       int r;
+       unsigned char status[3];
+
+       sc->usb.bTag++;
+
+       r = usb_control_msg(sc->usb.dev, 0xA1, 128, (sc->usb.bTag & 0x7f), 0, (char*)status, 3, USB_TIMEOUT);
+       if ((r != 3) || (status[0] != 0x01) || (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;
+       }
+
+       return status[2];
+}
+
 /*
  * Send a scpi-command to the scope. The response goes into the buffer
  * called resp, with a size of resplen. If resp==NULL, no response
@@ -199,7 +215,7 @@ void usbtmc_release(struct scope *sc)
 //Initialize the scope.
 struct scope* usbtmc_initscope(void) {
        int r;
-       unsigned char buff[10];
+       uint32_t vidpid;
        struct scope *sc;
 
        /* Init libusb */
@@ -213,7 +229,7 @@ struct scope* usbtmc_initscope(void) {
        usbtmc_claim(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*)buff, 4, USB_TIMEOUT);
+       r=usb_control_msg(sc->usb.dev, 0xC8, 9, 0, 0, (char*)&vidpid, 4, USB_TIMEOUT);
        usbtmc_release(sc);
        if (r < 0) {
                fprintf (stderr, "Error %d sending init message: %s\n", 
@@ -221,8 +237,8 @@ struct scope* usbtmc_initscope(void) {
                fprintf (stderr, "Do you have permission on the USB device?\n");
                exit (1);
        }
-       if (LE32((*(uint32_t*)buff))!=0x40005dc) {
-               fprintf(stderr,"Init: buff[%i]=%x\n",r,LE32((*(uint32_t*)buff)));
+       if (LE32(vidpid)!=0x40005dc) {
+               fprintf(stderr,"Init: buff[%i]=%x\n",r,LE32(vidpid));
        }
        return sc;
 }
Impressum, Datenschutz