Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
146 | f9daq | 1 | /*Predelava vmesnika vxi11 za lastne potrebe IJS F9*/ |
2 | |||
3 | #include <stdio.h> |
||
4 | #include <stdlib.h> |
||
5 | #include <string.h> |
||
6 | #include <time.h> |
||
7 | #include "vxi11_user.h" |
||
8 | #define BUF_LEN 100000 |
||
9 | |||
10 | CLINK *clink; |
||
11 | FILE *test,*test1; |
||
12 | |||
13 | int query(char *mycmd){ |
||
14 | char buf[BUF_LEN]; |
||
15 | |||
16 | memset(buf, 0, BUF_LEN); |
||
17 | vxi11_send(clink, mycmd); |
||
18 | int bytes_returned = vxi11_receive(clink, buf, BUF_LEN); |
||
19 | if (bytes_returned > 0) { |
||
20 | printf("%s\n",buf); |
||
21 | } else if (bytes_returned == -15) printf("*** [ NOTHING RECEIVED ] ***\n"); |
||
22 | |||
23 | return 0; |
||
24 | } |
||
25 | |||
26 | int command(char *mycmd){ |
||
27 | char buf[BUF_LEN]; |
||
28 | |||
29 | memset(buf, 0, BUF_LEN); |
||
30 | vxi11_send(clink, mycmd); |
||
31 | |||
32 | return 0; |
||
33 | } |
||
34 | |||
35 | int queryrep(char *mycmd,char *mycmp,int i){ |
||
36 | char buf[BUF_LEN]; |
||
37 | |||
38 | memset(buf, 0, BUF_LEN); |
||
39 | vxi11_send(clink, mycmd); |
||
40 | int bytes_returned = vxi11_receive(clink, buf, BUF_LEN); |
||
41 | |||
42 | if(strcmp(buf,mycmp)!=0){ |
||
43 | if (bytes_returned > 0) fprintf(test1,"%d %s",i,buf); |
||
44 | else if (bytes_returned == -15) printf("*** [ NOTHING RECEIVED ] ***\n"); |
||
45 | |||
46 | } |
||
47 | strcpy(mycmp,buf); |
||
48 | |||
49 | return 0; |
||
50 | } |
||
51 | |||
52 | /*float *fbuf; |
||
53 | fbuf= (float *) buf; |
||
54 | if (bytes_returned > 0){ |
||
55 | for (int j=1;j<3;j++) printf("%f\n",fbuf[j]); |
||
56 | } |
||
57 | */ |
||
58 | |||
59 | int main(void) { |
||
60 | |||
61 | static char *device_ip; |
||
62 | static char *device_name; |
||
63 | char cmd[256],ukaz[256],end[256]; |
||
64 | char buf[BUF_LEN],pr1[BUF_LEN],pr2[BUF_LEN]; |
||
65 | int ret; |
||
66 | long bytes_returned; |
||
67 | |||
68 | int i,m,vnos; |
||
69 | |||
70 | clink = new CLINK; |
||
71 | time_t t1,t2; |
||
72 | |||
73 | /* |
||
74 | fread(buf,1,size,fp); |
||
75 | float *fbuf=(float *) buf; |
||
76 | fbuf[0] |
||
77 | |||
78 | */ |
||
79 | memset(ukaz, 0, 256); |
||
80 | 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: "); |
||
81 | |||
82 | while(1){ |
||
83 | scanf("%s",&ukaz); |
||
84 | |||
85 | if (strncasecmp(ukaz, "q",1) == 0) return 0; |
||
86 | |||
87 | else if (strncasecmp(ukaz, "a",1) != 0) ret=vxi11_open_device(ukaz,clink); |
||
88 | else ret=vxi11_open_device("194.249.156.91",clink); //privzeti IP naprave |
||
89 | |||
90 | printf("\nPovezan z "); |
||
91 | |||
92 | memset(buf, 0, BUF_LEN); |
||
93 | vxi11_send(clink, "*IDN?"); |
||
94 | bytes_returned = vxi11_receive(clink, buf, BUF_LEN); |
||
95 | if (bytes_returned > 0) { |
||
96 | printf("%s",buf); |
||
97 | break;} |
||
98 | else if (bytes_returned == -15) { |
||
99 | printf("Error."); |
||
100 | if (strncasecmp(ukaz, "a",1) == 0) ret=vxi11_close_device("194.249.156.91",clink); |
||
101 | else ret=vxi11_close_device(ukaz,clink); |
||
102 | return 0; |
||
103 | } |
||
104 | |||
105 | } |
||
106 | |||
107 | printf("\nNekatere pomembnejse nastavitve:\n"); |
||
108 | command("HEADER ON"); |
||
109 | command("DATA:SOURCE CH1"); |
||
110 | query("DAT?"); |
||
111 | |||
112 | char odg[256]; |
||
113 | printf("Zelite spreminjati nastavitve? y/n/q: "); |
||
114 | scanf("%s",&odg); |
||
115 | fgets(cmd,256,stdin); |
||
116 | |||
117 | if (strncasecmp(odg, "q",1) == 0) { |
||
118 | if (strncasecmp(ukaz, "a",1) == 0) ret=vxi11_close_device("194.249.156.91",clink); |
||
119 | else ret=vxi11_close_device(ukaz,clink); |
||
120 | return 0; |
||
121 | } |
||
122 | else if (strncasecmp(odg, "y",1) == 0){ |
||
123 | printf("\nSpisek komand je v Programmer Manualu!\n"); |
||
124 | while(1){ |
||
125 | memset(cmd, 0, 256); |
||
126 | memset(buf, 0, BUF_LEN); |
||
127 | |||
128 | printf("Vnesi ukaz, vprasanje, 'q' za izhod ali 'x' za nadaljevanje: "); |
||
129 | fgets(cmd,256,stdin); |
||
130 | cmd[strlen(cmd)-1] = 0; |
||
131 | if (strncasecmp(cmd, "q",1) == 0) { |
||
132 | if (strncasecmp(ukaz, "a",1) == 0) ret=vxi11_close_device("194.249.156.91",clink); |
||
133 | else ret=vxi11_close_device(ukaz,clink); |
||
134 | return 0; |
||
135 | } |
||
136 | if (strncasecmp(cmd, "x",1) == 0) break; |
||
137 | |||
138 | if (vxi11_send(clink, cmd) < 0) break; |
||
139 | if (strstr(cmd, "?") != 0) { |
||
140 | bytes_returned = vxi11_receive(clink, buf, BUF_LEN); |
||
141 | if (bytes_returned > 0) { |
||
142 | printf("%s\n",buf); |
||
143 | } |
||
144 | else if (bytes_returned == -15) { |
||
145 | printf("*** [ NOTHING RECEIVED ] ***\n"); |
||
146 | } |
||
147 | else break; |
||
148 | } |
||
149 | } |
||
150 | } |
||
151 | |||
152 | command("HEADER OFF"); |
||
153 | |||
154 | printf("\nIzbor serije meritev\n1 = za zapis waveformov v binarnem formatu\n2 = MEASU:IMM test\n3 = Shenanigans\nVnesi #: "); |
||
155 | scanf("%d",&vnos); |
||
156 | //prva opcija |
||
157 | if (vnos==1){ |
||
158 | |||
159 | printf("\nTrenutno je nastavljeno zapisovanje celotnih waveformov iz CH1 v datoteko 'test.txt'. Vnesite zeljeno stevilo ponovitev: "); |
||
160 | scanf("%d",&m); |
||
161 | |||
162 | test=fopen("/media/disk/vxi11_1.08/test.txt","w"); |
||
163 | command("DATA:SOURCE CH1"); |
||
164 | command("DATA:START 1"); |
||
165 | command("DATA:STOP 1000"); |
||
166 | command("DATA:ENCDG RPBINARY"); |
||
167 | |||
168 | (void) time(&t1); |
||
169 | query("ACQUIRE:NUMFRAMESACQUIRED?"); |
||
170 | |||
171 | for(i=1;i<m+1;i++) { //zajem binarnih podatkov |
||
172 | |||
173 | memset(buf, 0, BUF_LEN); |
||
174 | vxi11_send(clink, "CURVE?"); |
||
175 | int bytes_returned = vxi11_receive(clink, buf, BUF_LEN); |
||
176 | |||
177 | if (bytes_returned > 0) fwrite(buf,1,bytes_returned,test); |
||
178 | if(strcmp(buf,pr1)!=0){ |
||
179 | if (bytes_returned > 0) fwrite(buf,1,1000,test); |
||
180 | else if (bytes_returned == -15) printf("*** [ NOTHING RECEIVED ] ***\n"); |
||
181 | } |
||
182 | strcpy(pr1,buf); |
||
183 | } |
||
184 | |||
185 | query("ACQUIRE:NUMFRAMESACQUIRED?"); |
||
186 | (void) time(&t2); |
||
187 | |||
188 | printf("Koncano!\n"); |
||
189 | printf("Trajanje: %ld s\n",(int)t2-t1); |
||
190 | fclose(test); |
||
191 | |||
192 | } |
||
193 | //druga opcija |
||
194 | else if (vnos==2){ |
||
195 | |||
196 | test1=fopen("/media/disk/vxi11_1.08/test1.txt","w"); |
||
197 | |||
198 | printf("Vnesi zeljeno stevilo meritev minimuma LeCroy: "); |
||
199 | scanf("%d",&m); |
||
200 | |||
201 | for (i=0;i<m;i++) queryrep("C1:PAVA? MIN",pr2,i); |
||
202 | |||
203 | fclose(test1); |
||
204 | } |
||
205 | //tretja opcija |
||
206 | else if (vnos==3){ |
||
207 | |||
208 | test1=fopen("/media/disk/vxi11_1.08/test1.txt","w"); |
||
209 | |||
210 | printf("Vnesi zeljeno stevilo zajemov: "); |
||
211 | scanf("%d",&m); |
||
212 | |||
213 | command("DATA:SOURCE CH1, CH2"); |
||
214 | command("DATA:START 1"); |
||
215 | command("DATA:STOP 1000"); |
||
216 | command("DATA:ENCDG ASCII"); |
||
217 | |||
218 | query("ACQUIRE:NUMFRAMESACQUIRED?"); |
||
219 | |||
220 | for (i=0;i<m;i++) queryrep("CURVE?",pr2,i); |
||
221 | |||
222 | query("ACQUIRE:NUMFRAMESACQUIRED?"); |
||
223 | |||
224 | fclose(test1); |
||
225 | } |
||
226 | |||
227 | if (strncasecmp(ukaz, "a",1) == 0) ret=vxi11_close_device("194.249.156.91",clink); |
||
228 | else ret=vxi11_close_device(ukaz,clink); |
||
229 | |||
230 | printf("Meritve opravljene!\nZa zakljucek pritisni 'q'! "); |
||
231 | scanf("%s",&end); |
||
232 | |||
233 | if (strcmp(end,"q")==0); |
||
234 | |||
235 | return 0; |
||
236 | } |
||
237 |