From 7d42ad7efe4c26e33498016c9f49acd214b5428e Mon Sep 17 00:00:00 2001 From: Michael Gernoth Date: Wed, 9 Jun 2010 23:26:37 +0200 Subject: [PATCH 1/1] improve read from broken rigol scopes --- usbtmc.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/usbtmc.c b/usbtmc.c index b29f4e7..d87d9ac 100644 --- a/usbtmc.c +++ b/usbtmc.c @@ -236,7 +236,7 @@ int usbtmc_sendscpi(struct scope *sc, char* cmd, unsigned char rxbuff[USBTMC_IN_TRANSFERSIZE]; struct usbtmc_header *res; int bytes_read; - unsigned int transfer_size = USBTMC_IN_TRANSFERSIZE; + unsigned int read_size = USBTMC_IN_TRANSFERSIZE; unsigned int headerlen; req = calloc(1, sizeof(struct usbtmc_header)); @@ -246,7 +246,7 @@ int usbtmc_sendscpi(struct scope *sc, char* cmd, } if (sc->usb.brokenRigol == 1) { - transfer_size = sc->usb.wMaxPacketSize_in; + read_size = sc->usb.wMaxPacketSize_in; } bytes_read = 0; @@ -259,7 +259,7 @@ int usbtmc_sendscpi(struct scope *sc, char* cmd, req->MsgID = USBTMC_REQUEST_DEV_DEP_MSG_IN; req->bTag = sc->usb.bTag; req->bTagInverse = ~sc->usb.bTag; - req->TransferSize = LE32(transfer_size); + req->TransferSize = LE32(USBTMC_IN_TRANSFERSIZE); req->bmTransferAttributes = 0; req->TermChar = 0; @@ -272,7 +272,7 @@ int usbtmc_sendscpi(struct scope *sc, char* cmd, } r=usb_bulk_read(sc->usb.dev, sc->usb.ep_bulk_in, - (char*)rxbuff, transfer_size, USB_TIMEOUT); + (char*)rxbuff, read_size, USB_TIMEOUT); USB_ERROR("USBTMC_DEV_DEP_MSG_IN", r); if (r < headerlen) { @@ -280,7 +280,6 @@ int usbtmc_sendscpi(struct scope *sc, char* cmd, return 0; } - if (headerlen > 0) { res = (struct usbtmc_header*)rxbuff; @@ -305,13 +304,12 @@ int usbtmc_sendscpi(struct scope *sc, char* cmd, } } - if ((sc->usb.brokenRigol == 0) || (transfer_size == USBTMC_IN_TRANSFERSIZE) || - ((r - sizeof(struct usbtmc_header) >= len))) { + if ((r - headerlen) > 0) { memcpy(buff + bytes_read, rxbuff + headerlen, r - headerlen); bytes_read += r - headerlen; } - transfer_size = USBTMC_IN_TRANSFERSIZE; + read_size = USBTMC_IN_TRANSFERSIZE; } while(bytes_read < len); free(req); -- 2.39.5