- static unsigned char seq=0;
-
-
- buff=malloc(0x40);
- seq++;
- buff[0]=1; //func
- buff[1]=seq; buff[2]=~seq; //nseq
- buff[3]=0;
- int2chars(buff+4, cmdlen);
- buff[8]=1;
- buff[9]=0x00;
- buff[10]=0x00;
- buff[11]=0x00;
- //fprintf(stderr,"Writing header len=%d\n", cmdlen);
- //printb(buff,12);
- r=usb_bulk_write(sc->usb.dev, 1, (char*)buff, 12, USB_TIMEOUT);
- //fprintf(stderr,"%i bytes written. Writing cmd\n",r);
- //printb(cmd, cmdlen);
- r=usb_bulk_write(sc->usb.dev, 1, cmd, cmdlen, USB_TIMEOUT);
- //fprintf(stderr,"%i bytes written.\n",r);
+ struct usbtmc_header *req;
+
+ sc->usb.bTag++;
+
+ len = sizeof(struct usbtmc_header) + cmdlen;
+ if (len%4)
+ len += 4 - (len%4);
+
+ req = calloc(1, len);
+ if (req == NULL) {
+ perror("calloc");
+ exit(EXIT_FAILURE);
+ }
+
+ req->MsgID = USBTMC_DEV_DEP_MSG_OUT;
+ req->bTag = sc->usb.bTag;
+ req->bTagInverse = ~sc->usb.bTag;
+ req->TransferSize = LE32(cmdlen);
+ req->bmTransferAttributes = USBTMC_TRANSFERATTRIB_EOM;
+ memcpy(req->msg, cmd, cmdlen);
+
+ if (sc->usb.brokenRigol) {
+ r=usb_bulk_write(sc->usb.dev, sc->usb.ep_bulk_out,
+ (char*)req, sizeof(struct usbtmc_header),
+ USB_TIMEOUT);
+ USB_ERROR(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);
+ } else {
+ r=usb_bulk_write(sc->usb.dev, sc->usb.ep_bulk_out,
+ (char*)req, len, USB_TIMEOUT);
+ USB_ERROR(r);
+ }
+
+ free(req);
+