X-Git-Url: http://git.zerfleddert.de/cgi-bin/gitweb.cgi/rigol/blobdiff_plain/b131d433f9b984b50266298be6f0cf7f9a13b6fb..713be7a43ed11947c358fc67c11b9df7b0be204c:/scope.c diff --git a/scope.c b/scope.c new file mode 100644 index 0000000..3152243 --- /dev/null +++ b/scope.c @@ -0,0 +1,62 @@ +#include +#include +#include +#include + +#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; +}