]> git.zerfleddert.de Git - rigol/blobdiff - scope.c
add abstraction for scope-access
[rigol] / scope.c
diff --git a/scope.c b/scope.c
new file mode 100644 (file)
index 0000000..3152243
--- /dev/null
+++ b/scope.c
@@ -0,0 +1,62 @@
+#include <usb.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include "usbtmc.h"
+#include "scope.h"
+
+/* Just USB for now... */
+int sendscpi(struct scope* sc, char* cmd, unsigned char *resp, int resplen)
+{
+       return usbtmc_sendscpi(sc->usbdev, cmd, resp, resplen);
+}
+
+void closescope(struct scope* sc)
+{
+       return usbtmc_close(sc->usbdev);
+}
+
+void claimscope(struct scope* sc)
+{
+       return usbtmc_claim(sc->usbdev);
+}
+
+void releasescope(struct scope* sc)
+{
+       //Disable keylock, so the user doesn't have to press the 'force'-button
+       sendscpi(sc, ":KEY:LOCK DISABLE",NULL,0); 
+       return usbtmc_release(sc->usbdev);
+}
+
+struct scope* initscope(void)
+{
+       struct usb_dev_handle *usbdev;
+       struct scope *sc;
+
+       usbdev = usbtmc_initscope();
+
+       if (!usbdev)
+               return NULL;
+
+       sc = calloc(1, sizeof(struct scope));
+       if (sc == NULL) {
+               perror("malloc");
+               exit(EXIT_FAILURE);
+       }
+
+       sc->usbdev = usbdev;
+
+       claimscope(sc);
+       sendscpi(sc, "*IDN?", (unsigned char*)sc->idn, sizeof(sc->idn)); 
+       releasescope(sc);
+
+       printf("Scope found (%s)\n", sc->idn);
+
+       return sc;
+}
+
+char *scope_idn(struct scope *sc)
+{
+       return sc->idn;
+}
Impressum, Datenschutz