+static unsigned char usb488_status(struct scope *sc)
+{
+ int r;
+ unsigned char status[3];
+
+ sc->usb.bTag++;
+
+ r = usb_control_msg(sc->usb.dev, 0xA1,
+ USB488_CTL_READ_STATUS_BYTE,
+ (sc->usb.bTag & 0x7f), 0, (char*)status, 3,
+ USB_TIMEOUT);
+
+ 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;
+ }
+
+ return status[2];
+}
+
+static struct usbtmc_capabilities* usbtmc_get_capabilities(struct scope *sc)
+{
+ int r;
+ static struct usbtmc_capabilities res;
+
+ r = usb_control_msg(sc->usb.dev, 0xA1,
+ USBTMC_CTL_GET_CAPABILITIES,
+ 0, 0, (char*)&res, sizeof(struct usbtmc_capabilities),
+ USB_TIMEOUT);
+ if (r != sizeof(struct usbtmc_capabilities)) {
+ printf("GET_CAPABILITIES failed: %s\n", usb_strerror());
+ return NULL;
+ }
+
+ printf("USBTMC Version %x.%x Capabilities:\n", res.bcdUSBTMC[0], res.bcdUSBTMC[1]);
+ if (res.USBTMCIFcapabilities & USBTMC_CAP_IF_INDICATOR_PULSE)
+ printf("\tInterface supports indicator pulse\n");
+
+ if (res.USBTMCIFcapabilities & USBTMC_CAP_IF_TALKONLY)
+ printf("\tInterface is talk only\n");
+
+ if (res.USBTMCIFcapabilities & USBTMC_CAP_IF_LISTENONLY)
+ printf("\tInterface is listen only\n");
+
+ if (res.USBTMCDEVcapabilities & USBTMC_CAP_DEV_TERMCHAR_SUPP)
+ printf("\tDevice supports Termchar\n");
+
+ printf("USB488 Version %x.%x Capabilities:\n", res.bcdUSB488[0], res.bcdUSB488[1]);
+
+ if (res.USB488IFcapabilities & USB488_CAP_IF_4882)
+ printf("\tInterface is 488.2 compliant\n");
+
+ if (res.USB488IFcapabilities & USB488_CAP_IF_LOCKOUT)
+ printf("\tInterface supports local lockout\n");
+
+ if (res.USB488IFcapabilities & USB488_CAP_IF_TRIGGER)
+ printf("\tInterface supports TRIGGER\n");
+
+ if (res.USB488DEVcapabilities & USB488_CAP_DEV_SCPI)
+ printf("\tDevice is SCPI compliant\n");
+
+ if (res.USB488DEVcapabilities & USB488_CAP_DEV_SR1)
+ printf("\tDevice is SR1 capable\n");
+
+ if (res.USB488DEVcapabilities & USB488_CAP_DEV_RL1)
+ printf("\tDevice is RL1 capable\n");
+
+ if (res.USB488DEVcapabilities & USB488_CAP_DEV_DT1)
+ printf("\tDevice is DT1 capable\n");
+
+ return &res;
+}
+
+static void usbtmc_clear(struct scope *sc)
+{
+ int r;
+ unsigned char status[2];
+
+ printf("Initiating clear...\n");
+ r = usb_control_msg(sc->usb.dev, 0xA1,
+ USBTMC_CTL_INITIATE_CLEAR,
+ 0, 0, (char*)status, 1,
+ USB_TIMEOUT);
+
+ if ((r != 1) || status[0] != USBTMC_STATUS_SUCCESS) {
+ printf("INITIATE_CLEAR failed (0x%x): %s\n", status[0], usb_strerror());
+ return;
+ }
+
+ while(1) {
+ usleep(100000);
+ printf("Waiting for clear to complete...\n");
+
+ r = usb_control_msg(sc->usb.dev, 0xA1,
+ USBTMC_CTL_CHECK_CLEAR_STAT,
+ 0, 0, (char*)status, 2,
+ USB_TIMEOUT);
+
+ if (r != 2) {
+ printf("CHECK_CLEAR failed: %s\n", usb_strerror());
+ return;
+ }
+
+ 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;
+ }
+ }
+}
+
+/*
+ * 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
+ * is requested.
+ */