+void usbtmc_reset(struct scope *sc)
+{
+ usb_reset(sc->usb.dev);
+ usbtmc_claim(sc);
+}
+
+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());
+ usbtmc_reset(sc);
+ 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;
+ }
+ }
+}
+