#include #include #include #include #include #include #include "pcigpib.h" int adrstbl[2] = { 1, -1 }; // Addres Table for Machines char *qiginit = "K2,D2"; // Initial. (modeset, start meas) char *qigqstat = "H2"; // Query status cmd char *qigsdata = "H0"; // send data cmd char recbuf[200]; // Buffer char *pErr; void intHandler (int signum) { PciGpibExFinishBoard (0); exit (0); } void errHandler (const char *errstr, const int ret){ if (ret == -100) perror (pErr); else printf ("%s: %d\n", errstr, ret); PciGpibExFinishBoard (0); exit (EXIT_FAILURE); } int main (int argc, char *argv[]) { int i, ret; unsigned long len; struct sigaction sa; struct timeval tv; struct timezone tz; // set sigaction handler memset (&sa, 0, sizeof (sa)); sa.sa_handler = intHandler; if (sigaction (SIGINT, &sa, NULL)) perror ("sigaction"); // Initialize Board Number 0 ret = PciGpibExInitBoard (0, 0); if (ret) errHandler("INIT ERROR", ret); // Set Delimiter ret = PciGpibExSetConfig (0, "/SDELIM=CRLF /RDELIM=CRLF"); if (ret) errHandler("CONFIG ERROR", ret); // Send IFC(InterFace Clear) ret = PciGpibExSetIfc (0, 1); if (ret) errHandler("IFC ERROR", ret); // Available REN(Remote Enable) ret = PciGpibExSetRen (0); if (ret) errHandler("REN ERROR", ret); fprintf(stderr, "# GPIB INIT done\n"); sleep(1); ret = PciGpibExSendData (0, adrstbl, strlen(qiginit), qiginit, NULL); if (ret) errHandler("QIG066 INIT ERROR", ret); fprintf(stderr, "# QIG Initializing"); for(i=0;i<4;i++){ sleep(2); fprintf(stderr, "."); } ret = PciGpibExSendData (0, adrstbl, strlen(qigqstat), qigqstat, 0); if (ret) errHandler("QIG066 QUERRY ERROR", ret); // Rcv data len = sizeof(recbuf); ret = PciGpibExRecvData(0, adrstbl, &len, recbuf, 0); if (ret) errHandler("RECV ERROR", ret); fprintf(stderr, "done, status: %s\n", recbuf); while(1) { sleep(10); ret = PciGpibExSendData(0, adrstbl, strlen (qigsdata), qigsdata, 0); if (ret) errHandler("SDATA ERROR", ret); // Rcv data len = sizeof (recbuf); ret = PciGpibExRecvData (0, adrstbl, &len, recbuf, 0); if (ret) errHandler("RECV ERROR", ret); gettimeofday(&tv, &tz); printf("%ld.%06ld %s\n", tv.tv_sec, tv.tv_usec, recbuf); fflush(stdout); } }