/*Predelava vmesnika vxi11 za lastne potrebe IJS F9*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "vxi11_user.h"
#define BUF_LEN 100000
CLINK *clink;
FILE *test,*test1;
int query(char *mycmd){
char buf[BUF_LEN];
memset(buf, 0, BUF_LEN);
vxi11_send(clink, mycmd);
int bytes_returned = vxi11_receive(clink, buf, BUF_LEN);
if (bytes_returned > 0) {
printf("%s\n",buf);
} else if (bytes_returned == -15) printf("*** [ NOTHING RECEIVED ] ***\n");
return 0;
}
int command(char *mycmd){
char buf[BUF_LEN];
memset(buf, 0, BUF_LEN);
vxi11_send(clink, mycmd);
return 0;
}
int queryrep(char *mycmd,char *mycmp,int i){
char buf[BUF_LEN];
memset(buf, 0, BUF_LEN);
vxi11_send(clink, mycmd);
int bytes_returned = vxi11_receive(clink, buf, BUF_LEN);
if(strcmp(buf,mycmp)!=0){
if (bytes_returned > 0) fprintf(test1,"%d %s",i,buf);
else if (bytes_returned == -15) printf("*** [ NOTHING RECEIVED ] ***\n");
}
strcpy(mycmp,buf);
return 0;
}
/*float *fbuf;
fbuf= (float *) buf;
if (bytes_returned > 0){
for (int j=1;j<3;j++) printf("%f\n",fbuf[j]);
}
*/
int main(void) {
static char *device_ip;
static char *device_name;
char cmd[256],ukaz[256],end[256];
char buf[BUF_LEN],pr1[BUF_LEN],pr2[BUF_LEN];
int ret;
long bytes_returned;
int i,m,vnos;
clink = new CLINK;
time_t t1,t2;
/*
fread(buf,1,size,fp);
float *fbuf=(float *) buf;
fbuf[0]
*/
memset(ukaz, 0, 256);
printf("\nIJS F9 - September 2010 - Pripravil: Jaka Mur - Beta verzija\n\nProgram za povezavo in nadzor Tektronix ali LeCroy osciloskopa.\nAvtomatsko se program poveze z IP naslovom 194.249.156.91.\nVnesi 'a' za nadaljevanje, 'q' za izhod ali IP za drugo napravo: ");
while(1){
scanf("%s",&ukaz);
if (strncasecmp(ukaz, "q",1) == 0) return 0;
else if (strncasecmp(ukaz, "a",1) != 0) ret=vxi11_open_device(ukaz,clink);
else ret=vxi11_open_device("194.249.156.91",clink); //privzeti IP naprave
printf("\nPovezan z ");
memset(buf, 0, BUF_LEN);
vxi11_send(clink, "*IDN?");
bytes_returned = vxi11_receive(clink, buf, BUF_LEN);
if (bytes_returned > 0) {
printf("%s",buf);
break;}
else if (bytes_returned == -15) {
printf("Error.");
if (strncasecmp(ukaz, "a",1) == 0) ret=vxi11_close_device("194.249.156.91",clink);
else ret=vxi11_close_device(ukaz,clink);
return 0;
}
}
printf("\nNekatere pomembnejse nastavitve:\n");
command("HEADER ON");
command("DATA:SOURCE CH1");
query("DAT?");
char odg[256];
printf("Zelite spreminjati nastavitve? y/n/q: ");
scanf("%s",&odg);
fgets(cmd,256,stdin);
if (strncasecmp(odg, "q",1) == 0) {
if (strncasecmp(ukaz, "a",1) == 0) ret=vxi11_close_device("194.249.156.91",clink);
else ret=vxi11_close_device(ukaz,clink);
return 0;
}
else if (strncasecmp(odg, "y",1) == 0){
printf("\nSpisek komand je v Programmer Manualu!\n");
while(1){
memset(cmd, 0, 256);
memset(buf, 0, BUF_LEN);
printf("Vnesi ukaz, vprasanje, 'q' za izhod ali 'x' za nadaljevanje: ");
fgets(cmd,256,stdin);
cmd[strlen(cmd)-1] = 0;
if (strncasecmp(cmd, "q",1) == 0) {
if (strncasecmp(ukaz, "a",1) == 0) ret=vxi11_close_device("194.249.156.91",clink);
else ret=vxi11_close_device(ukaz,clink);
return 0;
}
if (strncasecmp(cmd, "x",1) == 0) break;
if (vxi11_send(clink, cmd) < 0) break;
if (strstr(cmd, "?") != 0) {
bytes_returned = vxi11_receive(clink, buf, BUF_LEN);
if (bytes_returned > 0) {
printf("%s\n",buf);
}
else if (bytes_returned == -15) {
printf("*** [ NOTHING RECEIVED ] ***\n");
}
else break;
}
}
}
command("HEADER OFF");
printf("\nIzbor serije meritev\n1 = za zapis waveformov v binarnem formatu\n2 = MEASU:IMM test\n3 = Shenanigans\nVnesi #: ");
scanf("%d",&vnos);
//prva opcija
if (vnos==1){
printf("\nTrenutno je nastavljeno zapisovanje celotnih waveformov iz CH1 v datoteko 'test.txt'. Vnesite zeljeno stevilo ponovitev: ");
scanf("%d",&m);
test=fopen("/media/disk/vxi11_1.08/test.txt","w");
command("DATA:SOURCE CH1");
command("DATA:START 1");
command("DATA:STOP 1000");
command("DATA:ENCDG RPBINARY");
(void) time(&t1);
query("ACQUIRE:NUMFRAMESACQUIRED?");
for(i=1;i<m+1;i++) { //zajem binarnih podatkov
memset(buf, 0, BUF_LEN);
vxi11_send(clink, "CURVE?");
int bytes_returned = vxi11_receive(clink, buf, BUF_LEN);
if (bytes_returned > 0) fwrite(buf,1,bytes_returned,test);
if(strcmp(buf,pr1)!=0){
if (bytes_returned > 0) fwrite(buf,1,1000,test);
else if (bytes_returned == -15) printf("*** [ NOTHING RECEIVED ] ***\n");
}
strcpy(pr1,buf);
}
query("ACQUIRE:NUMFRAMESACQUIRED?");
(void) time(&t2);
printf("Koncano!\n");
printf("Trajanje: %ld s\n",(int)t2-t1);
fclose(test);
}
//druga opcija
else if (vnos==2){
test1=fopen("/media/disk/vxi11_1.08/test1.txt","w");
printf("Vnesi zeljeno stevilo meritev minimuma LeCroy: ");
scanf("%d",&m);
for (i=0;i<m;i++) queryrep("C1:PAVA? MIN",pr2,i);
fclose(test1);
}
//tretja opcija
else if (vnos==3){
test1=fopen("/media/disk/vxi11_1.08/test1.txt","w");
printf("Vnesi zeljeno stevilo zajemov: ");
scanf("%d",&m);
command("DATA:SOURCE CH1, CH2");
command("DATA:START 1");
command("DATA:STOP 1000");
command("DATA:ENCDG ASCII");
query("ACQUIRE:NUMFRAMESACQUIRED?");
for (i=0;i<m;i++) queryrep("CURVE?",pr2,i);
query("ACQUIRE:NUMFRAMESACQUIRED?");
fclose(test1);
}
if (strncasecmp(ukaz, "a",1) == 0) ret=vxi11_close_device("194.249.156.91",clink);
else ret=vxi11_close_device(ukaz,clink);
printf("Meritve opravljene!\nZa zakljucek pritisni 'q'! ");
scanf("%s",&end);
if (strcmp(end,"q")==0);
return 0;
}