Rev 281 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 281 | Rev 304 | ||
|---|---|---|---|
| - | 1 | #include <tcpsupp.h> |
|
| 1 | #include <formatio.h> |
2 | #include <formatio.h> |
| 2 | #include <userint.h> |
3 | #include <userint.h> |
| 3 | #include <ansi_c.h> |
4 | #include <ansi_c.h> |
| 4 | #include <utility.h> |
5 | #include <utility.h> |
| 5 | #include <gpib.h> |
6 | #include <gpib.h> |
| 6 | #include "toolbox.h" |
7 | #include "toolbox.h" |
| 7 | #include "prologix.h" |
8 | #include "prologix.h" |
| 8 | #include "K6517.h" |
9 | #include "K6517.h" |
| 9 | 10 | ||
| 10 | K6517STATUS K6517Stat; |
11 | K6517STATUS K6517Stat; |
| 11 | static int K6517_Interface,K6517_Port,K6517_Gdev; |
12 | static int K6517_Interface,K6517_Port,K6517_Gdev; |
| 12 | static int iret; |
13 | static int iret; |
| 13 | static int stop; |
14 | static int stop; |
| - | 15 | static int debugCode; |
|
| 14 | int _VI_FUNC K6517_status_print (void); |
16 | int _VI_FUNC K6517_status_print (void); |
| 15 | void GpibError(char *msg) { |
17 | void GpibError(char *msg) { |
| 16 | 18 | ||
| 17 | printf ("%s\n", msg); |
19 | printf ("%s\n", msg); |
| 18 | 20 | ||
| 19 | printf ("ibsta = &H%x <", ibsta); |
21 | printf ("ibsta = &H%x <", ibsta); |
| 20 | if (ibsta & ERR ) printf (" ERR"); |
22 | if (ibsta & ERR ) printf (" ERR"); |
| 21 | if (ibsta & TIMO) printf (" TIMO"); |
23 | if (ibsta & TIMO) printf (" TIMO"); |
| 22 | if (ibsta & END ) printf (" END"); |
24 | if (ibsta & END ) printf (" END"); |
| 23 | if (ibsta & SRQI) printf (" SRQI"); |
25 | if (ibsta & SRQI) printf (" SRQI"); |
| 24 | if (ibsta & RQS ) printf (" RQS"); |
26 | if (ibsta & RQS ) printf (" RQS"); |
| 25 | if (ibsta & CMPL) printf (" CMPL"); |
27 | if (ibsta & CMPL) printf (" CMPL"); |
| 26 | if (ibsta & LOK ) printf (" LOK"); |
28 | if (ibsta & LOK ) printf (" LOK"); |
| 27 | if (ibsta & REM ) printf (" REM"); |
29 | if (ibsta & REM ) printf (" REM"); |
| 28 | if (ibsta & CIC ) printf (" CIC"); |
30 | if (ibsta & CIC ) printf (" CIC"); |
| 29 | if (ibsta & ATN ) printf (" ATN"); |
31 | if (ibsta & ATN ) printf (" ATN"); |
| 30 | if (ibsta & TACS) printf (" TACS"); |
32 | if (ibsta & TACS) printf (" TACS"); |
| 31 | if (ibsta & LACS) printf (" LACS"); |
33 | if (ibsta & LACS) printf (" LACS"); |
| 32 | if (ibsta & DTAS) printf (" DTAS"); |
34 | if (ibsta & DTAS) printf (" DTAS"); |
| 33 | if (ibsta & DCAS) printf (" DCAS"); |
35 | if (ibsta & DCAS) printf (" DCAS"); |
| 34 | printf (" >\n"); |
36 | printf (" >\n"); |
| 35 | 37 | ||
| 36 | printf ("iberr = %d", iberr); |
38 | printf ("iberr = %d", iberr); |
| 37 | if (iberr == EDVR) printf (" EDVR <DOS Error>\n"); |
39 | if (iberr == EDVR) printf (" EDVR <DOS Error>\n"); |
| 38 | if (iberr == ECIC) printf (" ECIC <Not Controller-In-Charge>\n"); |
40 | if (iberr == ECIC) printf (" ECIC <Not Controller-In-Charge>\n"); |
| 39 | if (iberr == ENOL) printf (" ENOL <No Listener>\n"); |
41 | if (iberr == ENOL) printf (" ENOL <No Listener>\n"); |
| 40 | if (iberr == EADR) printf (" EADR <Address error>\n"); |
42 | if (iberr == EADR) printf (" EADR <Address error>\n"); |
| 41 | if (iberr == EARG) printf (" EARG <Invalid argument>\n"); |
43 | if (iberr == EARG) printf (" EARG <Invalid argument>\n"); |
| 42 | if (iberr == ESAC) printf (" ESAC <Not System Controller>\n"); |
44 | if (iberr == ESAC) printf (" ESAC <Not System Controller>\n"); |
| 43 | if (iberr == EABO) printf (" EABO <Operation aborted>\n"); |
45 | if (iberr == EABO) printf (" EABO <Operation aborted>\n"); |
| 44 | if (iberr == ENEB) printf (" ENEB <No GPIB board>\n"); |
46 | if (iberr == ENEB) printf (" ENEB <No GPIB board>\n"); |
| 45 | if (iberr == EOIP) printf (" EOIP <Async I/O in progress>\n"); |
47 | if (iberr == EOIP) printf (" EOIP <Async I/O in progress>\n"); |
| 46 | if (iberr == ECAP) printf (" ECAP <No capability>\n"); |
48 | if (iberr == ECAP) printf (" ECAP <No capability>\n"); |
| 47 | if (iberr == EFSO) printf (" EFSO <File system error>\n"); |
49 | if (iberr == EFSO) printf (" EFSO <File system error>\n"); |
| 48 | if (iberr == EBUS) printf (" EBUS <Command error>\n"); |
50 | if (iberr == EBUS) printf (" EBUS <Command error>\n"); |
| 49 | if (iberr == ESTB) printf (" ESTB <Status byte lost>\n"); |
51 | if (iberr == ESTB) printf (" ESTB <Status byte lost>\n"); |
| 50 | if (iberr == ESRQ) printf (" ESRQ <SRQ stuck on>\n"); |
52 | if (iberr == ESRQ) printf (" ESRQ <SRQ stuck on>\n"); |
| 51 | if (iberr == ETAB) printf (" ETAB <Table Overflow>\n"); |
53 | if (iberr == ETAB) printf (" ETAB <Table Overflow>\n"); |
| 52 | 54 | ||
| 53 | printf ("ibcntl = %ld\n", ibcntl); |
55 | printf ("ibcntl = %ld\n", ibcntl); |
| 54 | printf ("\n"); |
56 | printf ("\n"); |
| 55 | 57 | ||
| 56 | /* Call ibonl to take the device and interface offline */ |
58 | /* Call ibonl to take the device and interface offline */ |
| 57 | ibonl (K6517_Gdev,0); |
59 | ibonl (K6517_Gdev,0); |
| 58 | 60 | ||
| 59 | exit(1); |
61 | exit(1); |
| 60 | } |
62 | } |
| 61 | 63 | ||
| 62 | void _VI_FUNC K6517_open (int interface, int port, int primary_addr, |
64 | void _VI_FUNC K6517_open (int interface, int port, int primary_addr, |
| 63 | int secondary_addr, int timeout) |
65 | int secondary_addr, int timeout) |
| 64 | { |
66 | { |
| 65 | char cmd[100]; |
67 | char cmd[100]; |
| 66 | int status; |
68 | int status; |
| 67 | /* |
69 | /* |
| 68 | K6517_Gdev = OpenDev ("GPIB0", ""); |
70 | K6517_Gdev = OpenDev ("GPIB0", ""); |
| 69 | if (ibsta & ERR) GpibError("OpenDev Error"); |
71 | if (ibsta & ERR) GpibError("OpenDev Error"); |
| 70 | iret = ibpad (K6517_Gdev, 0); |
72 | iret = ibpad (K6517_Gdev, 0); |
| 71 | if (ibsta & ERR) GpibError("OpenDev Error"); |
73 | if (ibsta & ERR) GpibError("OpenDev Error"); |
| 72 | iret = ibsad (K6517_Gdev, NO_SAD); |
74 | iret = ibsad (K6517_Gdev, NO_SAD); |
| 73 | iret = ibtmo (K6517_Gdev, T10s); |
75 | iret = ibtmo (K6517_Gdev, T10s); |
| 74 | iret = ibeot (K6517_Gdev, 1); |
76 | iret = ibeot (K6517_Gdev, 1); |
| 75 | iret = ibeos (K6517_Gdev, 0); |
77 | iret = ibeos (K6517_Gdev, 0); |
| 76 | */ |
78 | */ |
| 77 | K6517_Interface=interface; |
79 | K6517_Interface=interface; |
| 78 | K6517_Port=port; |
80 | K6517_Port=port; |
| 79 | switch (K6517_Interface){ |
81 | switch (K6517_Interface){ |
| 80 | case 1: |
82 | case 1: |
| 81 | status = PROLOGIX_Open (K6517_Port); |
83 | status = PROLOGIX_Open (K6517_Port); |
| 82 | printf("K6517_open %d\n", status); |
84 | printf("K6517_open %d\n", status); |
| 83 | sprintf(cmd,"++addr %0d",primary_addr); |
85 | sprintf(cmd,"++addr %0d",primary_addr); |
| 84 | PROLOGIX_Send (cmd); |
86 | PROLOGIX_Send (cmd); |
| 85 | PROLOGIX_Send ("++auto 0"); |
87 | PROLOGIX_Send ("++auto 0"); |
| 86 | PROLOGIX_Send ("++eoi 1"); |
88 | PROLOGIX_Send ("++eoi 1"); |
| 87 | PROLOGIX_Send ("++eot_enable 0"); |
89 | PROLOGIX_Send ("++eot_enable 0"); |
| 88 | PROLOGIX_Send ("++read_tmo_ms 1000"); |
90 | PROLOGIX_Send ("++read_tmo_ms 1000"); |
| 89 | break; |
91 | break; |
| 90 | default: |
92 | default: |
| 91 | K6517_Gdev = ibdev(K6517_Port,primary_addr,secondary_addr,timeout,1,0); |
93 | K6517_Gdev = ibdev(K6517_Port,primary_addr,secondary_addr,timeout,1,0); |
| 92 | if (ibsta & ERR) GpibError("OpenDev Error"); |
94 | if (ibsta & ERR) GpibError("OpenDev Error"); |
| 93 | } |
95 | } |
| 94 | printf("Interface %d\n", interface); |
96 | printf("Interface %d\n", interface); |
| 95 | K6517_send("*RST",0); |
97 | K6517_send("*RST",0); |
| 96 | K6517_send("*IDN?", 5); |
98 | K6517_send("*IDN?", 5); |
| 97 | char cres[100]; |
99 | char cres[100]; |
| 98 | cres[0]= 0; |
100 | cres[0]= 0; |
| 99 | int len = K6517_receive (cres, 50); |
101 | int len = K6517_receive (cres, 50); |
| 100 | printf("[%d] %s\n", len, cres); |
102 | printf("[%d] %s\n", len, cres); |
| 101 | 103 | ||
| 102 | Delay(GDELAY); |
104 | Delay(GDELAY); |
| 103 | return; |
105 | return; |
| 104 | } |
106 | } |
| 105 | 107 | ||
| 106 | void _VI_FUNC K6517_clear (void) |
108 | void _VI_FUNC K6517_clear (void) |
| 107 | { |
109 | { |
| 108 | switch (K6517_Interface){ |
110 | switch (K6517_Interface){ |
| 109 | case 1: |
111 | case 1: |
| 110 | PROLOGIX_Send("++clr"); |
112 | PROLOGIX_Send("++clr"); |
| 111 | break; |
113 | break; |
| 112 | default: |
114 | default: |
| 113 | iret = ibclr (K6517_Gdev); // Clear the device |
115 | iret = ibclr (K6517_Gdev); // Clear the device |
| 114 | if (ibsta & ERR) GpibError("OpenDev Error"); |
116 | if (ibsta & ERR) GpibError("OpenDev Error"); |
| 115 | } |
117 | } |
| 116 | // Delay(GDELAY); |
118 | // Delay(GDELAY); |
| 117 | Delay(2.); |
119 | Delay(2.); |
| 118 | return; |
120 | return; |
| 119 | } |
121 | } |
| 120 | 122 | ||
| 121 | void _VI_FUNC K6517_send (char *cmd, int len) |
123 | void _VI_FUNC K6517_send (char *cmd, int len) |
| 122 | { |
124 | { |
| 123 | printf("-> %s\n", cmd); |
125 | if (debugCode) printf("-> %s\n", cmd); |
| 124 | if (!len) len = strlen(cmd); |
126 | if (!len) len = strlen(cmd); |
| 125 | switch (K6517_Interface){ |
127 | switch (K6517_Interface){ |
| 126 | case 1: |
128 | case 1: |
| 127 | PROLOGIX_Send(cmd); |
129 | PROLOGIX_Send(cmd); |
| 128 | break; |
130 | break; |
| 129 | default: |
131 | default: |
| 130 | iret = ibwrt (K6517_Gdev, cmd, len); |
132 | iret = ibwrt (K6517_Gdev, cmd, len); |
| 131 | if (ibsta & ERR) GpibError("OpenDev Error"); |
133 | if (ibsta & ERR) GpibError("OpenDev Error"); |
| 132 | } |
134 | } |
| 133 | Delay(GDELAY); |
135 | Delay(GDELAY); |
| 134 | return; |
136 | return; |
| 135 | } |
137 | } |
| 136 | 138 | ||
| 137 | int _VI_FUNC K6517_receive (char *response, int maxbyt) |
139 | int _VI_FUNC K6517_receive (char *response, int maxbyt) |
| 138 | { |
140 | { |
| 139 | int ierr=0; |
141 | int ierr=0; |
| 140 | switch (K6517_Interface){ |
142 | switch (K6517_Interface){ |
| 141 | case 1: |
143 | case 1: |
| 142 | PROLOGIX_Send("++read eoi"); |
144 | PROLOGIX_Send("++read eoi"); |
| 143 | ierr= PROLOGIX_Receive (response,maxbyt); |
145 | ierr= PROLOGIX_Receive (response,maxbyt); |
| 144 | printf("<---Read [%d] %s\n", ierr, response); |
146 | if (debugCode) printf("<---Read [%d] %s\n", ierr, response); |
| 145 | return ierr; |
147 | return ierr; |
| 146 | break; |
148 | break; |
| 147 | default: |
149 | default: |
| 148 | iret = ibrd (K6517_Gdev, response, maxbyt); |
150 | iret = ibrd (K6517_Gdev, response, maxbyt); |
| 149 | if (ibsta & ERR) GpibError("OpenDev Error"); |
151 | if (ibsta & ERR) GpibError("OpenDev Error"); |
| 150 | response[ibcntl]=0; |
152 | response[ibcntl]=0; |
| 151 | return ibcntl; |
153 | return ibcntl; |
| 152 | } |
154 | } |
| 153 | } |
155 | } |
| 154 | 156 | ||
| 155 | void _VI_FUNC K6517_status (void) |
157 | void _VI_FUNC K6517_status (void) |
| 156 | { |
158 | { |
| 157 | int len; |
159 | int len; |
| 158 | char cres[100]; |
160 | char cres[100]; |
| 159 | 161 | ||
| 160 | K6517_send ("U0X", 3); |
162 | K6517_send ("U0X", 3); |
| 161 | len = K6517_receive (cres, 90); |
163 | len = K6517_receive (cres, 90); |
| 162 | sscanf(cres," 617%1d%2d%1d%1d%1d%1d%1d%1d%1d%1d%1d%2d%1d%2c", |
164 | sscanf(cres," 617%1d%2d%1d%1d%1d%1d%1d%1d%1d%1d%1d%2d%1d%2c", |
| 163 | &K6517Stat.function,&K6517Stat.range,&K6517Stat.zero_check, |
165 | &K6517Stat.function,&K6517Stat.range,&K6517Stat.zero_check, |
| 164 | &K6517Stat.zero_correct,&K6517Stat.suppress,&K6517Stat.trigger, |
166 | &K6517Stat.zero_correct,&K6517Stat.suppress,&K6517Stat.trigger, |
| 165 | &K6517Stat.vsource_operate,&K6517Stat.read_mode, |
167 | &K6517Stat.vsource_operate,&K6517Stat.read_mode, |
| 166 | &K6517Stat.data_prefix,&K6517Stat.display, |
168 | &K6517Stat.data_prefix,&K6517Stat.display, |
| 167 | &K6517Stat.data_store,&K6517Stat.srq,&K6517Stat.eoi,K6517Stat.terminator); |
169 | &K6517Stat.data_store,&K6517Stat.srq,&K6517Stat.eoi,K6517Stat.terminator); |
| 168 | printf("617FRRCZNTOBGDQMMKYY\n"); |
170 | printf("617FRRCZNTOBGDQMMKYY\n"); |
| 169 | printf("%s\n",cres); |
171 | printf("%s\n",cres); |
| 170 | // K6517_send ("X", 1); |
172 | // K6517_send ("X", 1); |
| 171 | return; |
173 | return; |
| 172 | } |
174 | } |
| 173 | 175 | ||
| 174 | void _VI_FUNC K6517_data_format (int mode) |
176 | void _VI_FUNC K6517_data_format (int mode) |
| 175 | { |
177 | { |
| 176 | int len; |
178 | int len; |
| 177 | char cmd[100]; |
179 | char cmd[100]; |
| 178 | 180 | ||
| 179 | len=sprintf(cmd,"G%0dX",mode); |
181 | len=sprintf(cmd,"G%0dX",mode); |
| 180 | K6517_send (cmd, len); |
182 | K6517_send (cmd, len); |
| 181 | return; |
183 | return; |
| 182 | } |
184 | } |
| 183 | 185 | ||
| 184 | double _VI_FUNC K6517_get (char *prefix, int *loc) |
186 | double _VI_FUNC K6517_get (char *prefix, int *loc) |
| 185 | { |
187 | { |
| 186 | 188 | ||
| 187 | double value; |
189 | double value; |
| 188 | char cres[100]; |
190 | char cres[100]; |
| 189 | 191 | ||
| 190 | K6517_send ("SENS:FUNC 'curr'",0); |
192 | K6517_send ("SENS:FUNC 'curr'",0); |
| 191 | // K6517_send (":SENS:CURR:RANG:UPP 21e-3",0); |
193 | // K6517_send (":SENS:CURR:RANG:UPP 21e-3",0); |
| 192 | // K6517_send ("SYST:ZCH 0",0); |
194 | // K6517_send ("SYST:ZCH 0",0); |
| 193 | K6517_send ("READ?",0); |
195 | K6517_send ("READ?",0); |
| 194 | 196 | ||
| 195 | cres[0]= 0; |
197 | cres[0]= 0; |
| 196 | int len = K6517_receive (cres, 50); |
198 | int len = K6517_receive (cres, 50); |
| 197 | printf("current >%d, %s\n",len,cres); |
199 | if (debugCode) printf("current >%d, %s\n",len,cres); |
| 198 | 200 | ||
| 199 | return atof(cres); |
201 | return atof(cres); |
| 200 | /* |
202 | /* |
| 201 | K6517_send ("X", 1); |
203 | K6517_send ("X", 1); |
| 202 | len = K6517_receive (cres, 50); |
204 | len = K6517_receive (cres, 50); |
| 203 | if (loc) { |
205 | if (loc) { |
| 204 | *loc=-1; |
206 | *loc=-1; |
| 205 | sscanf(cres,"%4c%lg,%d",prefix, &value, loc); |
207 | sscanf(cres,"%4c%lg,%d",prefix, &value, loc); |
| 206 | prefix[4]=0; |
208 | prefix[4]=0; |
| 207 | } else { |
209 | } else { |
| 208 | sscanf(cres,"%*4c%lg,%*d",&value); |
210 | sscanf(cres,"%*4c%lg,%*d",&value); |
| 209 | } |
211 | } |
| 210 | |
212 | |
| 211 | return value; |
213 | return value; |
| 212 | */ |
214 | */ |
| 213 | 215 | ||
| 214 | } |
216 | } |
| 215 | 217 | ||
| 216 | void _VI_FUNC K6517_current_mode (double range) |
218 | void _VI_FUNC K6517_current_mode (double range) |
| 217 | { |
219 | { |
| 218 | int len; |
220 | int len; |
| 219 | char cmd[100]; |
221 | char cmd[100]; |
| 220 | 222 | ||
| 221 | if (range > 0) { |
223 | if (range > 0) { |
| 222 | len=sprintf(cmd,":SENS:CURR:RANG:AUTO OFF"); |
224 | len=sprintf(cmd,":SENS:CURR:RANG:AUTO OFF"); |
| 223 | len=sprintf(cmd,":SENS:CURR:RANG:UPP %g",range); |
225 | len=sprintf(cmd,":SENS:CURR:RANG:UPP %g",range); |
| 224 | } |
226 | } |
| 225 | else len=sprintf(cmd,":SENS:CURR:RANG:AUTO ON"); |
227 | else len=sprintf(cmd,":SENS:CURR:RANG:AUTO ON"); |
| 226 | // printf("%d, %s\n",len,cmd); |
228 | // printf("%d, %s\n",len,cmd); |
| 227 | K6517_send (cmd, len); |
229 | K6517_send (cmd, len); |
| 228 | Delay(1); |
230 | Delay(1); |
| 229 | K6517_send ("SYST:ZCH 0",0); |
231 | K6517_send ("SYST:ZCH 0",0); |
| 230 | return; |
232 | return; |
| 231 | } |
233 | } |
| 232 | 234 | ||
| 233 | void _VI_FUNC K6517_zero_correct (int zcorrect) |
235 | void _VI_FUNC K6517_zero_correct (int zcorrect) |
| 234 | { |
236 | { |
| 235 | K6517_send ("C0X", 3); |
237 | K6517_send ("C0X", 3); |
| 236 | K6517_send ("Z0X", 3); |
238 | K6517_send ("Z0X", 3); |
| 237 | if (zcorrect) { |
239 | if (zcorrect) { |
| 238 | K6517_send ("C1X", 3); |
240 | K6517_send ("C1X", 3); |
| 239 | Delay(2); |
241 | Delay(2); |
| 240 | K6517_send ("Z1X", 3); |
242 | K6517_send ("Z1X", 3); |
| 241 | K6517_send ("C0X", 3); |
243 | K6517_send ("C0X", 3); |
| 242 | } |
244 | } |
| 243 | return; |
245 | return; |
| 244 | } |
246 | } |
| 245 | 247 | ||
| 246 | void _VI_FUNC K6517_trigger_mode (int mode) |
248 | void _VI_FUNC K6517_trigger_mode (int mode) |
| 247 | { |
249 | { |
| 248 | int len; |
250 | int len; |
| 249 | char cmd[100]; |
251 | char cmd[100]; |
| 250 | 252 | ||
| 251 | //len=sprintf(cmd,"T%0dX",mode); |
253 | //len=sprintf(cmd,"T%0dX",mode); |
| 252 | //K6517_send (cmd, len); |
254 | //K6517_send (cmd, len); |
| 253 | return; |
255 | return; |
| 254 | } |
256 | } |
| 255 | 257 | ||
| 256 | void _VI_FUNC K6517_reading_mode (int mode) |
258 | void _VI_FUNC K6517_reading_mode (int mode) |
| 257 | { |
259 | { |
| 258 | int len; |
260 | int len; |
| 259 | char cmd[100]; |
261 | char cmd[100]; |
| 260 | 262 | ||
| 261 | //len=sprintf(cmd,"B%0dX",mode); |
263 | //len=sprintf(cmd,"B%0dX",mode); |
| 262 | //K6517_send (cmd, len); |
264 | //K6517_send (cmd, len); |
| 263 | return; |
265 | return; |
| 264 | } |
266 | } |
| 265 | 267 | ||
| 266 | void _VI_FUNC K6517_vsource_set (float value) |
268 | void _VI_FUNC K6517_vsource_set (float value) |
| 267 | { |
269 | { |
| 268 | int len; |
270 | int len; |
| 269 | char cmd[100]; |
271 | char cmd[100]; |
| 270 | len=sprintf(cmd,":SOURCE:VOLTAGE %f",value); |
272 | len=sprintf(cmd,":SOURCE:VOLTAGE %f",value); |
| - | 273 | K6517_send (cmd, len); |
|
| - | 274 | len=sprintf(cmd,":SOURCE:VOLTAGE:MCONNECT ON"); |
|
| 271 | K6517_send (cmd, len); |
275 | K6517_send (cmd, len); |
| 272 | return; |
276 | return; |
| 273 | } |
277 | } |
| 274 | 278 | ||
| 275 | double _VI_FUNC K6517_vsource_get (void) |
279 | double _VI_FUNC K6517_vsource_get (void) |
| 276 | { |
280 | { |
| 277 | double value; |
281 | double value; |
| 278 | 282 | ||
| 279 | /* |
283 | /* |
| 280 | K6517_send ("SENS:FUNC 'volt'",0); |
284 | K6517_send ("SENS:FUNC 'volt'",0); |
| 281 | K6517_send ("SENS:VOLT:RANG:AUTO ON",0); |
285 | K6517_send ("SENS:VOLT:RANG:AUTO ON",0); |
| 282 | K6517_send ("SYST:ZCH 0",0); |
286 | K6517_send ("SYST:ZCH 0",0); |
| 283 | K6517_send ("READ?",0); |
287 | K6517_send ("READ?",0); |
| 284 | */ |
288 | */ |
| 285 | K6517_send (":MEASure:VOLTage?",0); |
289 | K6517_send (":MEASure:VOLTage?",0); |
| 286 | char cres[100]; |
290 | char cres[100]; |
| 287 | cres[0]= 0; |
291 | cres[0]= 0; |
| 288 | int len = K6517_receive (cres, 50); |
292 | int len = K6517_receive (cres, 50); |
| 289 | 293 | ||
| 290 | 294 | ||
| 291 | return atof(cres); |
295 | return atof(cres); |
| 292 | } |
296 | } |
| 293 | 297 | ||
| 294 | void _VI_FUNC K6517_vsource_operate (int operate) |
298 | void _VI_FUNC K6517_vsource_operate (int operate) |
| 295 | { |
299 | { |
| 296 | 300 | ||
| 297 | if (operate){ |
301 | if (operate){ |
| 298 | // K6517_send (":SOURCE:VOLTAGE:MCONNECT 1", 0); |
302 | // K6517_send (":SOURCE:VOLTAGE:MCONNECT 1", 0); |
| 299 | // K6517_send (":SENS:VOLTAGE:MANual:VSOurce:OPERate 1", 0); |
303 | // K6517_send (":SENS:VOLTAGE:MANual:VSOurce:OPERate 1", 0); |
| 300 | //K6517_send (":MCONNECT 1", 0); |
304 | //K6517_send (":MCONNECT 1", 0); |
| 301 | K6517_send (":OUTP ON", 0); |
305 | K6517_send (":OUTP ON", 0); |
| 302 | 306 | ||
| 303 | // K6517_send (":SOURCE:VOLTAGE:RANGE 99", 0); |
307 | // K6517_send (":SOURCE:VOLTAGE:RANGE 99", 0); |
| 304 | // K6517_send (":SOURCE:VOLTAGE 22", 0); |
308 | // K6517_send (":SOURCE:VOLTAGE 22", 0); |
| 305 | } else { |
309 | } else { |
| 306 | //K6517_send (":SOURCE:VOLTAGE 0", 0); |
310 | //K6517_send (":SOURCE:VOLTAGE 0", 0); |
| 307 | // K6517_send (":SENSe:VOLTAGE:MANual:VSOurce:OPERate 0", 0); |
311 | // K6517_send (":SENSe:VOLTAGE:MANual:VSOurce:OPERate 0", 0); |
| 308 | // K6517_send (":SOURCE:VOLTAGE:MCONNECT 0", 0); |
312 | // K6517_send (":SOURCE:VOLTAGE:MCONNECT 0", 0); |
| 309 | K6517_send (":OUTP OFF", 0); |
313 | K6517_send (":OUTP OFF", 0); |
| 310 | //K6517_send (":MCONNECT 0", 0); |
314 | //K6517_send (":MCONNECT 0", 0); |
| 311 | 315 | ||
| 312 | } |
316 | } |
| 313 | K6517_send (":STATUS:OPER?",0); |
317 | K6517_send (":STATUS:OPER?",0); |
| 314 | char cres[100]; |
318 | char cres[100]; |
| 315 | cres[0]= 0; |
319 | cres[0]= 0; |
| 316 | int len = K6517_receive (cres, 50); |
320 | int len = K6517_receive (cres, 50); |
| 317 | 321 | ||
| 318 | 322 | ||
| 319 | // return atoi(cres); |
323 | // return atoi(cres); |
| 320 | } |
324 | } |
| 321 | 325 | ||
| 322 | void _VI_FUNC K6517_close (void) |
326 | void _VI_FUNC K6517_close (void) |
| 323 | { |
327 | { |
| 324 | // iret = CloseDev (K6517_Gdev); |
328 | // iret = CloseDev (K6517_Gdev); |
| 325 | switch (K6517_Interface){ |
329 | switch (K6517_Interface){ |
| 326 | case 1: |
330 | case 1: |
| 327 | PROLOGIX_Close(); |
331 | PROLOGIX_Close(); |
| 328 | break; |
332 | break; |
| 329 | default: |
333 | default: |
| 330 | iret = ibonl(K6517_Gdev, 0);// Take the device offline |
334 | iret = ibonl(K6517_Gdev, 0);// Take the device offline |
| 331 | if (ibsta & ERR) GpibError("OpenDev Error"); |
335 | if (ibsta & ERR) GpibError("OpenDev Error"); |
| 332 | } |
336 | } |
| 333 | return; |
337 | return; |
| 334 | } |
338 | } |
| 335 | 339 | ||
| 336 | void _VI_FUNC K6517_test (void) |
340 | void _VI_FUNC K6517_test (void) |
| 337 | { |
341 | { |
| 338 | int i; |
342 | int i; |
| 339 | double value; |
343 | double value; |
| 340 | char cres[100]; |
344 | char cres[100]; |
| 341 | 345 | ||
| 342 | K6517_clear (); |
346 | K6517_clear (); |
| 343 | K6517_current_mode (0); |
347 | K6517_current_mode (0); |
| 344 | K6517_zero_correct (1); |
348 | K6517_zero_correct (1); |
| 345 | K6517_data_format (0); |
349 | K6517_data_format (0); |
| 346 | K6517_trigger_mode (1); |
350 | K6517_trigger_mode (1); |
| 347 | K6517_vsource_set (-100.); |
351 | K6517_vsource_set (-100.); |
| 348 | K6517_vsource_operate (1); |
352 | K6517_vsource_operate (1); |
| 349 | 353 | ||
| 350 | K6517_status(); |
354 | K6517_status(); |
| 351 | 355 | ||
| 352 | value=K6517_get(cres,&i); |
356 | value=K6517_get(cres,&i); |
| 353 | printf("%s, %lg, %d\n",cres,value,i); |
357 | printf("%s, %lg, %d\n",cres,value,i); |
| 354 | value=K6517_vsource_get(); |
358 | value=K6517_vsource_get(); |
| 355 | printf("%lg\n",value); |
359 | printf("%lg\n",value); |
| 356 | value=K6517_get(cres,&i); |
360 | value=K6517_get(cres,&i); |
| 357 | printf("%s, %lg, %d\n",cres,value,i); |
361 | printf("%s, %lg, %d\n",cres,value,i); |
| 358 | value=K6517_get(cres,&i); |
362 | value=K6517_get(cres,&i); |
| 359 | printf("%s, %lg, %d\n",cres,value,i); |
363 | printf("%s, %lg, %d\n",cres,value,i); |
| 360 | value=K6517_get(cres,&i); |
364 | value=K6517_get(cres,&i); |
| 361 | printf("%s, %lg, %d\n",cres,value,i); |
365 | printf("%s, %lg, %d\n",cres,value,i); |
| 362 | value=K6517_get(cres,&i); |
366 | value=K6517_get(cres,&i); |
| 363 | printf("%s, %lg, %d\n",cres,value,i); |
367 | printf("%s, %lg, %d\n",cres,value,i); |
| 364 | Delay(5); |
368 | Delay(5); |
| 365 | K6517_vsource_operate (0); |
369 | K6517_vsource_operate (0); |
| 366 | 370 | ||
| 367 | 371 | ||
| 368 | } |
372 | } |
| 369 | 373 | ||
| 370 | #ifdef K6517_MAIN |
374 | #ifdef K6517_MAIN |
| 371 | 375 | ||
| 372 | #include <cvirte.h> |
376 | #include <cvirte.h> |
| 373 | #include <userint.h> |
377 | #include <userint.h> |
| 374 | #include "K6517-ctrl.h" |
378 | #include "K6517-ctrl.h" |
| 375 | int pnl; int gLogToFile; |
379 | int pnl; int gLogToFile; |
| 376 | int pn2; |
380 | int pn2; |
| 377 | int gLogToFile; |
381 | int gLogToFile; |
| 378 | int vmon[4]={P1_VMON_1}; |
382 | int vmon[4]={P1_VMON_1}; |
| 379 | int imon[4]={P1_IMON_1 }; |
383 | int imon[4]={P1_IMON_1 }; |
| 380 | int vset[4]={P1_U_1 }; |
384 | int vset[4]={P1_U_1 }; |
| 381 | int iset[4]={P1_I_1 }; |
385 | int iset[4]={P1_I_1 }; |
| 382 | int radiob[4]={P1_BOX_1 }; |
386 | int radiob[4]={P1_BOX_1 }; |
| 383 | 387 | ||
| 384 | int cvcc[4]={P1_CVCC_1 }; |
388 | int cvcc[4]={P1_CVCC_1 }; |
| 385 | const unsigned char Pre_1 = 1; |
389 | const unsigned char Pre_1 = 1; |
| 386 | int gMask=0xF; |
390 | int gMask=0xF; |
| 387 | 391 | ||
| 388 | int pnl; |
392 | int pnl; |
| 389 | FILE *gFp; |
393 | FILE *gFp; |
| 390 | 394 | ||
| - | 395 | static int tfID; |
|
| - | 396 | static int rID; |
|
| - | 397 | static CmtThreadPoolHandle poolHandle = 0; |
|
| - | 398 | #define MAX_THREADS 10 |
|
| - | 399 | ||
| - | 400 | ||
| - | 401 | ||
| - | 402 | /*---------------------------------------------------------------------------*/ |
|
| - | 403 | /* Macros */ |
|
| - | 404 | /*---------------------------------------------------------------------------*/ |
|
| - | 405 | #define tcpChk(f) if ((g_TCPError=(f)) < 0) {ReportTCPError();} |
|
| - | 406 | ||
| - | 407 | ||
| - | 408 | /*---------------------------------------------------------------------------*/ |
|
| - | 409 | /* Internal function prototypes */ |
|
| - | 410 | /*---------------------------------------------------------------------------*/ |
|
| - | 411 | int CVICALLBACK ClientTCPCB (unsigned handle, int event, int error, |
|
| - | 412 | void *callbackData); |
|
| - | 413 | static void ReportTCPError (void); |
|
| - | 414 | ||
| - | 415 | /*---------------------------------------------------------------------------*/ |
|
| - | 416 | /* Module-globals */ |
|
| - | 417 | /*---------------------------------------------------------------------------*/ |
|
| - | 418 | static unsigned int g_hconversation; |
|
| - | 419 | static int g_hmainPanel; |
|
| - | 420 | static int g_connected = 0; |
|
| - | 421 | static int g_TCPError = 0; |
|
| - | 422 | ||
| - | 423 | /*---------------------------------------------------------------------------*/ |
|
| - | 424 | /* Report TCP Errors if any */ |
|
| - | 425 | /*---------------------------------------------------------------------------*/ |
|
| - | 426 | static void ReportTCPError(void) |
|
| - | 427 | { |
|
| - | 428 | if (g_TCPError < 0) |
|
| - | 429 | { |
|
| - | 430 | char messageBuffer[1024]; |
|
| - | 431 | sprintf(messageBuffer, |
|
| - | 432 | "TCP library error message: %s\nSystem error message: %s", |
|
| - | 433 | GetTCPErrorString (g_TCPError), GetTCPSystemErrorString()); |
|
| - | 434 | MessagePopup ("Error", messageBuffer); |
|
| - | 435 | g_TCPError = 0; |
|
| - | 436 | } |
|
| - | 437 | } |
|
| - | 438 | /*---------------------------------------------------------------------------*/ |
|
| - | 439 | ||
| - | 440 | ||
| - | 441 | int CVICALLBACK DisconnectCB (int panel, int control, int event, |
|
| - | 442 | void *callbackData, int eventData1, int eventData2) { |
|
| - | 443 | switch (event) { |
|
| - | 444 | case EVENT_COMMIT: |
|
| - | 445 | if (g_connected) |
|
| - | 446 | DisconnectFromTCPServer (g_hconversation); |
|
| - | 447 | g_hconversation = 0; |
|
| - | 448 | g_connected = 0; |
|
| - | 449 | break; |
|
| - | 450 | } |
|
| - | 451 | return 0; |
|
| - | 452 | } |
|
| - | 453 | ||
| - | 454 | int CVICALLBACK ConnectCB (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { |
|
| - | 455 | int portNum=10000; |
|
| - | 456 | char tempBuf[512]; |
|
| - | 457 | sprintf(tempBuf,"localhost"); |
|
| - | 458 | switch (event) { |
|
| - | 459 | case EVENT_COMMIT: |
|
| - | 460 | if (ConnectToTCPServer (&g_hconversation, portNum, tempBuf, ClientTCPCB, NULL, 5000) < 0) |
|
| - | 461 | MessagePopup("TCP Client", "Connection to server failed !"); |
|
| - | 462 | else |
|
| - | 463 | { |
|
| - | 464 | SetWaitCursor (0); |
|
| - | 465 | g_connected = 1; |
|
| - | 466 | ||
| - | 467 | /* We are successfully connected -- gather info */ |
|
| - | 468 | ||
| - | 469 | if (GetTCPHostAddr (tempBuf, 256) >= 0) printf("%s\n" ,tempBuf); |
|
| - | 470 | if (GetTCPHostName (tempBuf, 256) >= 0) printf("%s\n" ,tempBuf); |
|
| - | 471 | ||
| - | 472 | tcpChk (GetTCPPeerAddr (g_hconversation, tempBuf, 256)); |
|
| - | 473 | printf("%s\n" ,tempBuf); |
|
| - | 474 | tcpChk (GetTCPPeerName (g_hconversation, tempBuf, 256)); |
|
| - | 475 | printf("%s\n" ,tempBuf); |
|
| - | 476 | } |
|
| - | 477 | break; |
|
| - | 478 | } |
|
| - | 479 | return 0; |
|
| - | 480 | } |
|
| - | 481 | ||
| - | 482 | ||
| - | 483 | int CVICALLBACK ClientTCPCB (unsigned handle, int event, int error, void *callbackData) |
|
| - | 484 | { |
|
| - | 485 | char receiveBuf[256] = {0}; |
|
| - | 486 | ssize_t dataSize = sizeof (receiveBuf) - 1; |
|
| - | 487 | ||
| - | 488 | switch (event) |
|
| - | 489 | { |
|
| - | 490 | case TCP_DATAREADY: |
|
| - | 491 | if ((dataSize = ClientTCPRead (g_hconversation, receiveBuf, |
|
| - | 492 | dataSize, 1000)) |
|
| - | 493 | < 0) |
|
| - | 494 | { |
|
| - | 495 | printf( "Receive Error\n"); |
|
| - | 496 | } |
|
| - | 497 | else |
|
| - | 498 | { |
|
| - | 499 | receiveBuf[dataSize] = '\0'; |
|
| - | 500 | //printf("%s", receiveBuf); |
|
| - | 501 | float temp = 0; |
|
| - | 502 | float humidity = 0; |
|
| - | 503 | float dt=0; |
|
| - | 504 | float tdiff=0; |
|
| - | 505 | int t0 = 0; |
|
| - | 506 | sscanf(receiveBuf, "%d%f%f%f%f", &t0,&humidity,&temp, &tdiff, &dt); |
|
| - | 507 | SetCtrlVal(pn2,P2_TMON, temp); |
|
| - | 508 | SetCtrlVal(pn2,P2_HUMIDITY, humidity); |
|
| - | 509 | if (fabs(tdiff)<0.5 && fabs(dt) < 0.2) SetCtrlVal(pn2,P2_LED, 1); |
|
| - | 510 | else SetCtrlVal(pn2,P2_LED, 0); |
|
| - | 511 | } |
|
| - | 512 | break; |
|
| - | 513 | case TCP_DISCONNECT: |
|
| - | 514 | MessagePopup ("TCP Client", "Server has closed connection!"); |
|
| - | 515 | ||
| - | 516 | g_connected = 0; |
|
| - | 517 | ||
| - | 518 | break; |
|
| - | 519 | } |
|
| - | 520 | return 0; |
|
| - | 521 | } |
|
| - | 522 | ||
| - | 523 | ||
| - | 524 | void SetDimming(int state) { |
|
| - | 525 | SetCtrlAttribute (pnl, P2_IVSCAN, ATTR_DIMMED, state); |
|
| - | 526 | SetCtrlAttribute (pnl, P2_EXIT, ATTR_DIMMED, state); |
|
| - | 527 | SetCtrlAttribute (pnl, P2_STOP, ATTR_DIMMED, !state); |
|
| - | 528 | } |
|
| - | 529 | ||
| - | 530 | void CVICALLBACK EndOfThread ( CmtThreadPoolHandle poolhandle, |
|
| - | 531 | CmtThreadFunctionID functionID, unsigned int event, |
|
| - | 532 | int value, void *callbackData ) { |
|
| - | 533 | SetDimming(0); |
|
| - | 534 | printf("End of Thread \n"); |
|
| - | 535 | return ; |
|
| - | 536 | ||
| - | 537 | } |
|
| - | 538 | ||
| - | 539 | int ivscan (void *arg); |
|
| - | 540 | ||
| - | 541 | int TScan () { |
|
| - | 542 | ||
| - | 543 | double temp; |
|
| - | 544 | int n=0; |
|
| - | 545 | int led; |
|
| - | 546 | GetNumTableRows (pn2, P2_TABLE, &n ); |
|
| - | 547 | for(int i=0; i<n; i++) { |
|
| - | 548 | GetTableCellVal (pn2, P2_TABLE, MakePoint (1,i+1), &temp); |
|
| - | 549 | if (temp>100) break; |
|
| - | 550 | char transmitBuf[512]= {0}; |
|
| - | 551 | sprintf(transmitBuf, "1 %f\n", temp); |
|
| - | 552 | SetCtrlVal(pn2,P2_LED, 0); |
|
| - | 553 | if (g_hconversation) |
|
| - | 554 | if ( ClientTCPWrite (g_hconversation, transmitBuf, strlen (transmitBuf), 1000) < 0) printf("Transmit Error\n"); |
|
| - | 555 | ||
| - | 556 | do { |
|
| - | 557 | time_t t0 = time(NULL); |
|
| - | 558 | SetCtrlVal(pn2,P2_TIME, ctime(&t0)); |
|
| - | 559 | Delay(1); |
|
| - | 560 | GetCtrlVal(pn2,P2_LED, &led); |
|
| - | 561 | if (stop) break; |
|
| - | 562 | } while (!led); |
|
| - | 563 | if (stop) break; |
|
| - | 564 | ||
| - | 565 | int itemp = (int) temp; |
|
| - | 566 | ivscan(&itemp); |
|
| - | 567 | printf("%d %f\n",i,temp); |
|
| - | 568 | } |
|
| - | 569 | ||
| - | 570 | return 0; |
|
| - | 571 | } |
|
| - | 572 | ||
| - | 573 | ||
| - | 574 | int CVICALLBACK TScanCB (int panel, int control, int event, |
|
| - | 575 | void *callbackData, int eventData1, int eventData2) { |
|
| - | 576 | ||
| - | 577 | switch (event) { |
|
| - | 578 | case EVENT_COMMIT:{ |
|
| - | 579 | ThreadFunctionPtr mythread = TScan; |
|
| - | 580 | CmtScheduleThreadPoolFunctionAdv (poolHandle, mythread, &rID, |
|
| - | 581 | DEFAULT_THREAD_PRIORITY, |
|
| - | 582 | EndOfThread, |
|
| - | 583 | EVENT_TP_THREAD_FUNCTION_END, |
|
| - | 584 | NULL, RUN_IN_SCHEDULED_THREAD, |
|
| - | 585 | &tfID); |
|
| - | 586 | } |
|
| - | 587 | break; |
|
| - | 588 | } |
|
| - | 589 | return 0; |
|
| - | 590 | } |
|
| 391 | 591 | ||
| 392 | int CVICALLBACK TimerOnOffCB (int panel, int control, int event, |
592 | int CVICALLBACK TimerOnOffCB (int panel, int control, int event, |
| 393 | void *callbackData, int eventData1, int eventData2) |
593 | void *callbackData, int eventData1, int eventData2) |
| 394 | { |
594 | { |
| 395 | int state; |
595 | int state; |
| 396 | switch (event) |
596 | switch (event) |
| 397 | { |
597 | { |
| 398 | case EVENT_COMMIT: |
598 | case EVENT_COMMIT: |
| 399 | GetCtrlVal(panel, control, &state); |
599 | GetCtrlVal(panel, control, &state); |
| 400 | if (state){ |
600 | if (state){ |
| 401 | ResumeTimerCallbacks(); |
601 | ResumeTimerCallbacks(); |
| 402 | } else { |
602 | } else { |
| 403 | SuspendTimerCallbacks (); |
603 | SuspendTimerCallbacks (); |
| 404 | printf ("Disabling timer....\n"); |
604 | printf ("Disabling timer....\n"); |
| 405 | } |
605 | } |
| 406 | break; |
606 | break; |
| 407 | } |
607 | } |
| 408 | return 0; |
608 | return 0; |
| 409 | } |
609 | } |
| 410 | 610 | ||
| 411 | // reads the run number from the first line in the file |
611 | // reads the run number from the first line in the file |
| 412 | int GetRunNumberFromFile(char *fname) { |
612 | int GetRunNumberFromFile(char *fname) { |
| 413 | char line[MAX_PATHNAME_LEN]; |
613 | char line[MAX_PATHNAME_LEN]; |
| 414 | int ndim= MAX_PATHNAME_LEN; |
614 | int ndim= MAX_PATHNAME_LEN; |
| 415 | int current_run = -1; |
615 | int current_run = -1; |
| 416 | FILE *fp = NULL; |
616 | FILE *fp = NULL; |
| 417 | ssize_t size; |
617 | ssize_t size; |
| 418 | 618 | ||
| 419 | if ( GetFileInfo(fname,&size) ) fp = fopen(fname,"r"); |
619 | if ( GetFileInfo(fname,&size) ) fp = fopen(fname,"r"); |
| 420 | 620 | ||
| 421 | if (fp) { |
621 | if (fp) { |
| 422 | if (fgets(line,ndim,fp)!= NULL) current_run = atoi(line); |
622 | if (fgets(line,ndim,fp)!= NULL) current_run = atoi(line); |
| 423 | fclose(fp); |
623 | fclose(fp); |
| 424 | } |
624 | } |
| 425 | return current_run; |
625 | return current_run; |
| 426 | 626 | ||
| 427 | } |
627 | } |
| 428 | 628 | ||
| 429 | int IncreaseRunNumberInFile(char *fname) { |
629 | int IncreaseRunNumberInFile(char *fname) { |
| 430 | 630 | ||
| 431 | int current_run = GetRunNumberFromFile(fname); |
631 | int current_run = GetRunNumberFromFile(fname); |
| 432 | FILE *fp = fopen(fname,"w"); |
632 | FILE *fp = fopen(fname,"w"); |
| 433 | 633 | ||
| 434 | if (fp) { |
634 | if (fp) { |
| 435 | fprintf(fp,"%d", current_run+1 ); |
635 | fprintf(fp,"%d", current_run+1 ); |
| 436 | fclose(fp); |
636 | fclose(fp); |
| 437 | } |
637 | } |
| 438 | return current_run+1; |
638 | return current_run+1; |
| 439 | } |
639 | } |
| - | 640 | ||
| 440 | 641 | ||
| 441 | int __stdcall WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, |
642 | int __stdcall WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, |
| 442 | LPSTR lpszCmdLine, int nCmdShow) |
643 | LPSTR lpszCmdLine, int nCmdShow) |
| 443 | { |
644 | { |
| 444 | char cres[100]; |
645 | char cres[100]; |
| 445 | double Voltage, Current, tinterval; |
646 | double Voltage, Current, tinterval; |
| 446 | if (InitCVIRTE (hInstance, 0, 0) == 0) return -1; /* out of memory */ |
647 | if (InitCVIRTE (hInstance, 0, 0) == 0) return -1; /* out of memory */ |
| 447 | SetStdioPort (CVI_STDIO_WINDOW); |
648 | SetStdioPort (CVI_STDIO_WINDOW); |
| - | 649 | SetSleepPolicy(VAL_SLEEP_MORE); |
|
| - | 650 | CmtNewThreadPool (MAX_THREADS, &poolHandle); |
|
| - | 651 | ||
| 448 | if ((pnl = LoadPanel (0, "K6517-ctrl.uir", P1)) < 0) return -1; |
652 | if ((pnl = LoadPanel (0, "K6517-ctrl.uir", P1)) < 0) return -1; |
| 449 | if ((pn2 = LoadPanel (0, "K6517-ctrl.uir", P2)) < 0) return -1; |
653 | if ((pn2 = LoadPanel (0, "K6517-ctrl.uir", P2)) < 0) return -1; |
| 450 | - | ||
| - | 654 | DisableBreakOnLibraryErrors(); |
|
| 451 | K6517_open (1,4,3,0,13); |
655 | K6517_open (1,4,3,0,13); |
| 452 | 656 | ||
| 453 | 657 | ||
| 454 | SetCtrlVal(pnl, P1_ONOFF, 0); |
658 | SetCtrlVal(pnl, P1_ONOFF, 0); |
| 455 | GetCtrlVal(pnl, P1_TINTERVAL, &tinterval); |
659 | GetCtrlVal(pnl, P1_TINTERVAL, &tinterval); |
| 456 | SetCtrlAttribute (pnl, P1_TIMER, ATTR_INTERVAL, tinterval); |
660 | SetCtrlAttribute (pnl, P1_TIMER, ATTR_INTERVAL, tinterval); |
| 457 | TimerOnOffCB(pnl, P1_TIMERON, EVENT_COMMIT,NULL,0,0); |
661 | TimerOnOffCB(pnl, P1_TIMERON, EVENT_COMMIT,NULL,0,0); |
| 458 | for (unsigned char ch=0;ch<1;ch++){ |
662 | for (unsigned char ch=0;ch<1;ch++){ |
| 459 | int ison,i; |
663 | int ison,i; |
| 460 | Voltage =K6517_vsource_get(); |
664 | Voltage =K6517_vsource_get(); |
| 461 | Current =K6517_get(cres,&i); |
665 | Current =K6517_get(cres,&i); |
| 462 | SetCtrlVal(pnl, vset[ch], Voltage); |
666 | SetCtrlVal(pnl, vset[ch], Voltage); |
| 463 | SetCtrlVal(pnl, iset[ch], Current); |
667 | SetCtrlVal(pnl, iset[ch], Current); |
| 464 | GetCtrlVal(pnl, radiob[ch], &ison); |
668 | GetCtrlVal(pnl, radiob[ch], &ison); |
| 465 | gMask = ison; |
669 | gMask = ison; |
| 466 | } |
670 | } |
| 467 | 671 | ||
| 468 | DisplayPanel (pnl); |
672 | DisplayPanel (pnl); |
| 469 | DisplayPanel (pn2); |
673 | DisplayPanel (pn2); |
| 470 | RunUserInterface (); |
674 | RunUserInterface (); |
| - | 675 | CmtDiscardThreadPool (poolHandle); |
|
| - | 676 | if (g_connected) |
|
| - | 677 | DisconnectFromTCPServer (g_hconversation); |
|
| 471 | DiscardPanel (pn2); |
678 | DiscardPanel (pn2); |
| 472 | DiscardPanel (pnl); |
679 | DiscardPanel (pnl); |
| 473 | K6517_close(); |
680 | K6517_close(); |
| 474 | 681 | ||
| 475 | if (gFp) fclose(gFp); |
682 | if (gFp) fclose(gFp); |
| 476 | 683 | ||
| 477 | 684 | ||
| 478 | return 0; |
685 | return 0; |
| 479 | } |
686 | } |
| 480 | 687 | ||
| 481 | 688 | ||
| 482 | 689 | ||
| 483 | 690 | ||
| 484 | int CVICALLBACK SwitchOnOffCB (int panel, int control, int event, |
691 | int CVICALLBACK SwitchOnOffCB (int panel, int control, int event, |
| 485 | void *callbackData, int eventData1, int eventData2) |
692 | void *callbackData, int eventData1, int eventData2) |
| 486 | { |
693 | { |
| 487 | unsigned char state; |
694 | unsigned char state; |
| 488 | switch (event) |
695 | switch (event) |
| 489 | { |
696 | { |
| 490 | case EVENT_COMMIT: |
697 | case EVENT_COMMIT: |
| 491 | GetCtrlVal(panel, control, &state); |
698 | GetCtrlVal(panel, control, &state); |
| 492 | K6517_vsource_operate (state); |
699 | K6517_vsource_operate (state); |
| 493 | break; |
700 | break; |
| 494 | } |
701 | } |
| 495 | return 0; |
702 | return 0; |
| 496 | } |
703 | } |
| 497 | 704 | ||
| 498 | int CVICALLBACK SetCB (int panel, int control, int event, |
705 | int CVICALLBACK SetCB (int panel, int control, int event, |
| 499 | void *callbackData, int eventData1, int eventData2) |
706 | void *callbackData, int eventData1, int eventData2) |
| 500 | { |
707 | { |
| 501 | 708 | ||
| 502 | char cres[100]; |
709 | char cres[100]; |
| 503 | int i; |
710 | int i; |
| 504 | switch (event) |
711 | switch (event) |
| 505 | { |
712 | { |
| 506 | case EVENT_COMMIT: |
713 | case EVENT_COMMIT: |
| 507 | 714 | ||
| 508 | for (unsigned char ch = 0; ch<1;ch++){ |
715 | for (unsigned char ch = 0; ch<1;ch++){ |
| 509 | //printf("ch %d %x\n", ch, gMask); |
716 | //printf("ch %d %x\n", ch, gMask); |
| 510 | if (gMask){ |
717 | if (gMask){ |
| 511 | double Voltage; |
718 | double Voltage; |
| 512 | double Current; |
719 | double Current; |
| 513 | GetCtrlVal(panel, vset[ch], &Voltage); |
720 | GetCtrlVal(panel, vset[ch], &Voltage); |
| 514 | GetCtrlVal(panel, iset[ch], &Current); |
721 | GetCtrlVal(panel, iset[ch], &Current); |
| 515 | printf("->ch %d VSet %g Iset %g\n", ch, Voltage, Current); |
722 | printf("->ch %d VSet %g Iset %g\n", ch, Voltage, Current); |
| 516 | 723 | ||
| 517 | K6517_vsource_set (Voltage); |
724 | K6517_vsource_set (Voltage); |
| 518 | Voltage=K6517_vsource_get(); |
725 | Voltage=K6517_vsource_get(); |
| 519 | 726 | ||
| 520 | // TMI_Current(TMI_DeviceId, ch+1, Pre_1, Current); |
727 | // TMI_Current(TMI_DeviceId, ch+1, Pre_1, Current); |
| 521 | Current=K6517_get(cres,&i); |
728 | Current=K6517_get(cres,&i); |
| 522 | printf("<-ch %d VSet %g Iset %g\n", ch, Voltage, Current); |
729 | printf("<-ch %d VSet %g Iset %g\n", ch, Voltage, Current); |
| 523 | 730 | ||
| 524 | } |
731 | } |
| 525 | } |
732 | } |
| 526 | break; |
733 | break; |
| 527 | } |
734 | } |
| 528 | return 0; |
735 | return 0; |
| 529 | } |
736 | } |
| 530 | 737 | ||
| 531 | int CVICALLBACK ReadCB (int panel, int control, int event, |
738 | int CVICALLBACK ReadCB (int panel, int control, int event, |
| 532 | void *callbackData, int eventData1, int eventData2) |
739 | void *callbackData, int eventData1, int eventData2) |
| 533 | { |
740 | { |
| 534 | 741 | ||
| 535 | int iRet; |
742 | int iRet; |
| 536 | char ch=0; |
743 | char ch=0; |
| 537 | double Voltage; |
744 | double Voltage; |
| 538 | double Current; |
745 | double Current; |
| 539 | char cv_cc; |
746 | char cv_cc; |
| 540 | char cres[100]; |
747 | char cres[100]; |
| 541 | 748 | ||
| 542 | switch (event) |
749 | switch (event) |
| 543 | { |
750 | { |
| 544 | case EVENT_COMMIT: |
751 | case EVENT_COMMIT: |
| 545 | for (ch = 0; ch<1;ch++){ |
752 | for (ch = 0; ch<1;ch++){ |
| 546 | if (gMask){ |
753 | if (gMask){ |
| 547 | int ison,i; |
754 | int ison,i; |
| 548 | Voltage =K6517_vsource_get(); |
755 | Voltage =K6517_vsource_get(); |
| 549 | Current =K6517_get(cres,&i); |
756 | Current =K6517_get(cres,&i); |
| 550 | cv_cc = 1; |
757 | cv_cc = 1; |
| 551 | printf("ch %d VSet %g Iset %g\n", ch, Voltage, Current); |
758 | printf("ch %d VSet %g Iset %g\n", ch, Voltage, Current); |
| 552 | SetCtrlVal(panel, vmon[ch], Voltage); |
759 | SetCtrlVal(panel, vmon[ch], Voltage); |
| 553 | SetCtrlVal(panel, imon[ch], Current); |
760 | SetCtrlVal(panel, imon[ch], Current); |
| 554 | SetCtrlVal(panel, cvcc[ch], cv_cc); |
761 | SetCtrlVal(panel, cvcc[ch], cv_cc); |
| 555 | } |
762 | } |
| 556 | } |
763 | } |
| 557 | break; |
764 | break; |
| 558 | } |
765 | } |
| 559 | return 0; |
766 | return 0; |
| 560 | } |
767 | } |
| 561 | 768 | ||
| 562 | int CVICALLBACK SetIntervalCB (int panel, int control, int event, |
769 | int CVICALLBACK SetIntervalCB (int panel, int control, int event, |
| 563 | void *callbackData, int eventData1, int eventData2) { |
770 | void *callbackData, int eventData1, int eventData2) { |
| 564 | double tinterval; |
771 | double tinterval; |
| 565 | switch (event) { |
772 | switch (event) { |
| 566 | case EVENT_COMMIT: |
773 | case EVENT_COMMIT: |
| 567 | GetCtrlVal(panel, control, &tinterval); |
774 | GetCtrlVal(panel, control, &tinterval); |
| 568 | SetCtrlAttribute (panel, P1_TIMER, ATTR_INTERVAL, tinterval); |
775 | SetCtrlAttribute (panel, P1_TIMER, ATTR_INTERVAL, tinterval); |
| 569 | break; |
776 | break; |
| 570 | } |
777 | } |
| 571 | return 0; |
778 | return 0; |
| 572 | } |
779 | } |
| 573 | 780 | ||
| 574 | 781 | ||
| 575 | 782 | ||
| 576 | int CVICALLBACK ExitCB (int panel, int control, int event, |
783 | int CVICALLBACK ExitCB (int panel, int control, int event, |
| 577 | void *callbackData, int eventData1, int eventData2) |
784 | void *callbackData, int eventData1, int eventData2) |
| 578 | { |
785 | { |
| 579 | switch (event) |
786 | switch (event) |
| 580 | { |
787 | { |
| 581 | case EVENT_COMMIT: |
788 | case EVENT_COMMIT: |
| 582 | K6517_send (":OUTP OFF", 0); |
789 | K6517_send (":OUTP OFF", 0); |
| 583 | QuitUserInterface(0); |
790 | QuitUserInterface(0); |
| 584 | break; |
791 | break; |
| 585 | } |
792 | } |
| 586 | return 0; |
793 | return 0; |
| 587 | } |
794 | } |
| 588 | 795 | ||
| 589 | int CVICALLBACK SetMaskCB (int panel, int control, int event, |
796 | int CVICALLBACK SetMaskCB (int panel, int control, int event, |
| 590 | void *callbackData, int eventData1, int eventData2) |
797 | void *callbackData, int eventData1, int eventData2) |
| 591 | { int ison; |
798 | { int ison; |
| 592 | switch (event) |
799 | switch (event) |
| 593 | { |
800 | { |
| 594 | case EVENT_COMMIT: |
801 | case EVENT_COMMIT: |
| 595 | GetCtrlVal(panel, control, &ison); |
802 | GetCtrlVal(panel, control, &ison); |
| 596 | for (int i=0;i<1;i++) if (control == radiob[i]) break; |
803 | for (int i=0;i<1;i++) if (control == radiob[i]) break; |
| 597 | gMask = ison; |
804 | gMask = ison; |
| 598 | break; |
805 | break; |
| 599 | } |
806 | } |
| 600 | return 0; |
807 | return 0; |
| 601 | } |
808 | } |
| 602 | 809 | ||
| 603 | 810 | ||
| 604 | int CVICALLBACK LogToFileCB (int panel, int control, int event, |
811 | int CVICALLBACK LogToFileCB (int panel, int control, int event, |
| 605 | void *callbackData, int eventData1, int eventData2) |
812 | void *callbackData, int eventData1, int eventData2) |
| 606 | { |
813 | { |
| 607 | 814 | ||
| 608 | switch (event) |
815 | switch (event) |
| 609 | { |
816 | { |
| 610 | case EVENT_COMMIT: |
817 | case EVENT_COMMIT: |
| 611 | GetCtrlVal(panel, control, &gLogToFile); |
818 | GetCtrlVal(panel, control, &gLogToFile); |
| 612 | 819 | ||
| 613 | break; |
820 | break; |
| 614 | } |
821 | } |
| 615 | return 0; |
822 | return 0; |
| 616 | } |
823 | } |
| 617 | 824 | ||
| 618 | int CVICALLBACK TimerCB (int panel, int control, int event, |
825 | int CVICALLBACK TimerCB (int panel, int control, int event, |
| 619 | void *callbackData, int eventData1, int eventData2) |
826 | void *callbackData, int eventData1, int eventData2) |
| 620 | { |
827 | { |
| 621 | switch (event) |
828 | switch (event) |
| 622 | { |
829 | { |
| 623 | 830 | ||
| 624 | unsigned char ch; |
831 | unsigned char ch; |
| 625 | double current[4]; |
832 | double current[4]; |
| 626 | double voltage; |
833 | double voltage; |
| 627 | char cv_cc = 0; |
834 | char cv_cc = 0; |
| 628 | char cres[100]; |
835 | char cres[100]; |
| 629 | int i=0; |
836 | int i=0; |
| 630 | case EVENT_TIMER_TICK: |
837 | case EVENT_TIMER_TICK: |
| 631 | for (ch = 0; ch<1;ch++){ |
838 | for (ch = 0; ch<1;ch++){ |
| 632 | if (gMask){ |
839 | if (gMask){ |
| 633 | voltage =K6517_vsource_get(); |
840 | voltage =K6517_vsource_get(); |
| 634 | current[ch] =K6517_get(cres,&i); |
841 | current[ch] =K6517_get(cres,&i); |
| 635 | 842 | ||
| 636 | if (gLogToFile){ |
843 | if (gLogToFile){ |
| 637 | if (!gFp) { |
844 | if (!gFp) { |
| 638 | gFp= fopen("K6517.log","w"); |
845 | gFp= fopen("K6517.log","w"); |
| 639 | fprintf(gFp,"#time\tch\tU\tI\tCV_CC\n"); |
846 | fprintf(gFp,"#time\tch\tU\tI\tCV_CC\n"); |
| 640 | } |
847 | } |
| 641 | fprintf(gFp,"%ul\t%d\t%g\t%g\t%d\n", time(NULL), ch+1, voltage, current[ch], cv_cc); |
848 | fprintf(gFp,"%ul\t%d\t%g\t%g\t%d\n", time(NULL), ch+1, voltage, current[ch], cv_cc); |
| 642 | } |
849 | } |
| 643 | } |
850 | } |
| 644 | } |
851 | } |
| 645 | PlotStripChart (panel, P1_GRAPH, current, 1, 0, 0, VAL_DOUBLE); |
852 | PlotStripChart (panel, P1_GRAPH, current, 1, 0, 0, VAL_DOUBLE); |
| 646 | PlotStripChart (panel, P1_GRAPH_1, &voltage, 1, 0, 0, VAL_DOUBLE); |
853 | PlotStripChart (panel, P1_GRAPH_1, &voltage, 1, 0, 0, VAL_DOUBLE); |
| 647 | break; |
854 | break; |
| 648 | } |
855 | } |
| 649 | return 0; |
856 | return 0; |
| 650 | } |
857 | } |
| 651 | 858 | ||
| 652 | int CVICALLBACK TestCB (int panel, int control, int event, |
859 | int CVICALLBACK TestCB (int panel, int control, int event, |
| 653 | void *callbackData, int eventData1, int eventData2) { |
860 | void *callbackData, int eventData1, int eventData2) { |
| 654 | switch (event) { |
861 | switch (event) { |
| 655 | case EVENT_COMMIT: |
862 | case EVENT_COMMIT: |
| 656 | K6517_test(); |
863 | K6517_test(); |
| 657 | break; |
864 | break; |
| 658 | } |
865 | } |
| 659 | return 0; |
866 | return 0; |
| 660 | } |
867 | } |
| 661 | 868 | ||
| 662 | 869 | ||
| 663 | int |
870 | int ivscan (void *arg) { |
| 664 |
|
871 | int *iarg = (int *) arg; |
| 665 | int nsteps; |
872 | int nsteps; |
| 666 | double umin, umax, u; |
873 | double umin, umax, u; |
| 667 | double *xpoints; |
874 | double *xpoints; |
| 668 | double *ypoints; |
875 | double *ypoints; |
| 669 | static int plivhandle=0; |
876 | static int plivhandle=0; |
| 670 | double current; |
877 | double current; |
| 671 | double voltage; |
878 | double voltage; |
| 672 | char cv_cc = 0; |
879 | char cv_cc = 0; |
| 673 | char cres[100]; |
880 | char cres[100]; |
| 674 | char fileName[100]; |
881 | char fileName[100]; |
| 675 | char fname[100]; |
882 | char fname[100]; |
| 676 | char path[100]; |
883 | char path[100]; |
| 677 | double range; |
884 | double range; |
| 678 | int k=0; |
885 | int k=0; |
| 679 | int state; |
886 | int state; |
| 680 | int overflow; |
887 | int overflow; |
| 681 | char ovf[10]; |
888 | char ovf[10]; |
| 682 | FILE *fp; |
889 | FILE *fp; |
| 683 | time_t mtime; |
890 | time_t mtime; |
| 684 | ssize_t size; |
891 | ssize_t size; |
| 685 | - | ||
| 686 |
|
892 | int repeatscan = 1; |
| 687 |
|
893 | while (repeatscan){ |
| - | 894 | ||
| - | 895 | ||
| 688 | K6517_send (":OUTP ON", 0); |
896 | K6517_send (":OUTP ON", 0); |
| 689 | // GetCtrlVal(panel, P2_UMIN, &umin); |
- | |
| 690 | // GetCtrlVal(panel, P2_UMAX, &umax); |
- | |
| 691 | // GetCtrlVal(panel, P2_NSTEPS, &nsteps); |
- | |
| - | 897 | ||
| 692 | SetCtrlVal(pnl, P1_TIMERON, 0); |
898 | SetCtrlVal(pnl, P1_TIMERON, 0); |
| 693 | GetCtrlVal( |
899 | GetCtrlVal(pn2, P2_FILENAME, fileName); |
| 694 | GetCtrlVal( |
900 | GetCtrlVal(pn2, P2_PATH, path); |
| 695 | // GetCtrlVal(panel, P2_RANGE, &range); |
- | |
| - | 901 | ||
| 696 | TimerOnOffCB(pnl, P1_TIMERON, EVENT_COMMIT, NULL, 0, 0); |
902 | TimerOnOffCB(pnl, P1_TIMERON, EVENT_COMMIT, NULL, 0, 0); |
| - | 903 | GetCtrlVal(pn2, P2_REPEAT, &repeatscan); |
|
| - | 904 | if (repeatscan) { |
|
| - | 905 | int month, day, year, hours,minutes,seconds; |
|
| - | 906 | GetSystemDate (&month,&day ,&year ); |
|
| - | 907 | GetSystemTime(&hours, &minutes, &seconds); |
|
| - | 908 | sprintf(fname ,"%s/%s.%d_%d_%d_%d_%d.dat", path, fileName,year,month,day,hours,minutes ); |
|
| - | 909 | fp = fopen(fname,"w"); |
|
| - | 910 | } else { |
|
| - | 911 | if (*iarg>=100) sprintf(fname, "%s/%s.dat", path, fileName); |
|
| 697 | sprintf |
912 | else sprintf(fname, "%s/%s_T%d.dat", path, fileName,*iarg); |
| 698 | if ( !GetFileInfo(fname,&size) ) |
913 | if ( !GetFileInfo(fname,&size) || strstr("test",fileName)!=NULL ) |
| 699 | fp = fopen(fname,"w"); |
914 | fp = fopen(fname,"w"); |
| 700 | else { |
915 | else { |
| 701 | sprintf(cres, "File %s exist\n Remove it first",fname); |
916 | sprintf(cres, "File %s exist\n Remove it first",fname); |
| 702 | MessagePopup ("Info", cres); |
917 | MessagePopup ("Info", cres); |
| 703 | return 0; |
918 | return 0; |
| - | 919 | } |
|
| 704 | } |
920 | } |
| 705 | time(&mtime); |
921 | time(&mtime); |
| 706 | printf("#%s %s\n",DateStr(), TimeStr()); |
922 | printf("#%s %s\n",DateStr(), TimeStr()); |
| 707 | if (fp) fprintf(fp, "#%s %s\n",DateStr(), TimeStr()); |
923 | if (fp) fprintf(fp, "#%s %s\n",DateStr(), TimeStr()); |
| 708 | // K6517_current_mode (range); |
924 | // K6517_current_mode (range); |
| 709 | stop = 0; |
925 | stop = 0; |
| 710 | LogScaleCB ( |
926 | LogScaleCB (pn2, P2_LOGSCALE, EVENT_COMMIT,NULL, 0, 0); |
| 711 | int voltageMax[4]={P2_UMAX_1,P2_UMAX_2,P2_UMAX_3,P2_UMAX_4}; |
927 | int voltageMax[4]={P2_UMAX_1,P2_UMAX_2,P2_UMAX_3,P2_UMAX_4}; |
| 712 | int voltageMin[4]={P2_UMIN_1,P2_UMIN_2,P2_UMIN_3,P2_UMIN_4}; |
928 | int voltageMin[4]={P2_UMIN_1,P2_UMIN_2,P2_UMIN_3,P2_UMIN_4}; |
| 713 | int numberOfSteps[4]={P2_NSTEPS_1,P2_NSTEPS_2,P2_NSTEPS_3,P2_NSTEPS_4}; |
929 | int numberOfSteps[4]={P2_NSTEPS_1,P2_NSTEPS_2,P2_NSTEPS_3,P2_NSTEPS_4}; |
| 714 | int selectRange[4]={P2_RANGE_1,P2_RANGE_2,P2_RANGE_3,P2_RANGE_4}; |
930 | int selectRange[4]={P2_RANGE_1,P2_RANGE_2,P2_RANGE_3,P2_RANGE_4}; |
| 715 | int intervals[4]={P2_SLCT_1,P2_SLCT_2,P2_SLCT_3,P2_SLCT_4}; |
931 | int intervals[4]={P2_SLCT_1,P2_SLCT_2,P2_SLCT_3,P2_SLCT_4}; |
| 716 | int nrOfInt; |
932 | int nrOfInt; |
| 717 | int nrOfSteps; |
933 | int nrOfSteps; |
| 718 | int N=0; |
934 | int N=0; |
| 719 | int K=0; |
935 | int K=0; |
| 720 | for (int j=0;j<4;j++){ |
936 | for (int j=0;j<4;j++){ |
| 721 | GetCtrlVal( |
937 | GetCtrlVal(pn2, intervals[j], &nrOfInt); |
| 722 | N = N + nrOfInt; |
938 | N = N + nrOfInt; |
| 723 | GetCtrlVal( |
939 | GetCtrlVal(pn2, numberOfSteps[j], &nrOfSteps); |
| 724 | K = K + nrOfSteps; |
940 | K = K + nrOfSteps; |
| 725 | } |
941 | } |
| 726 | xpoints = (double *) malloc ((K-N+2)*sizeof(double)); |
942 | xpoints = (double *) malloc ((K-N+2)*sizeof(double)*4); |
| 727 | ypoints = (double *) malloc ((K-N+2)*sizeof(double)); |
943 | ypoints = (double *) malloc ((K-N+2)*sizeof(double)*4); |
| 728 | int tockaK=0; |
944 | int tockaK=0; |
| - | 945 | double t1,t2; |
|
| - | 946 | GetCtrlVal(pn2, P2_DELAY, &t1); |
|
| - | 947 | GetCtrlVal(pn2, P2_DELAY2, &t2); |
|
| - | 948 | ||
| 729 | for (int i=0;i<N;i++){ |
949 | for (int i=0;i<N;i++){ |
| 730 | GetCtrlVal( |
950 | GetCtrlVal(pn2, voltageMin[i], &umin); |
| 731 | GetCtrlVal( |
951 | GetCtrlVal(pn2, voltageMax[i], &umax); |
| 732 | GetCtrlVal( |
952 | GetCtrlVal(pn2, numberOfSteps[i], &nsteps); |
| 733 | GetCtrlVal( |
953 | GetCtrlVal(pn2, selectRange[i], &range); |
| 734 | K6517_current_mode (range); |
954 | K6517_current_mode (range); |
| 735 | for (int n=0;n<nsteps+1;n++){ |
955 | for (int n=0;n<nsteps+1;n++){ |
| - | 956 | ||
| 736 | if (i>0) { |
957 | if (i>0) { |
| 737 | if(n==0) n++; |
958 | if(n==0) n++; |
| 738 | }; |
959 | }; |
| 739 | u= umin+ n*(umax-umin)/nsteps; |
960 | u= umin+ n*(umax-umin)/nsteps; |
| - | 961 | if (n==0) { |
|
| - | 962 | K6517_vsource_set (u); |
|
| - | 963 | Delay(1); |
|
| - | 964 | K6517_get(cres,&k); |
|
| - | 965 | K6517_vsource_set (u); |
|
| - | 966 | Delay(1); |
|
| - | 967 | K6517_get(cres,&k); |
|
| - | 968 | ||
| - | 969 | } |
|
| 740 | K6517_vsource_set (u); |
970 | K6517_vsource_set (u); |
| - | 971 | current =K6517_get(cres,&k); |
|
| - | 972 | if (n==0) Delay(t1); |
|
| - | 973 | Delay(t2); |
|
| 741 | // voltage =K6517_vsource_get(); |
974 | // voltage =K6517_vsource_get(); |
| 742 | current =K6517_get(cres,&k); |
975 | current =K6517_get(cres,&k); |
| 743 |
|
976 | // if (current > range) printf("Overflow +\n"); |
| 744 |
|
977 | // if (current < -range) printf("Overflow -\n"); |
| 745 | voltage = u; |
978 | voltage = u; |
| 746 | xpoints[tockaK]= voltage; |
979 | xpoints[tockaK]= voltage; |
| 747 | ypoints[tockaK]= current; |
980 | ypoints[tockaK]= current; |
| 748 | SetCtrlVal( |
981 | SetCtrlVal(pn2, P2_VMON, voltage); |
| - | 982 | SetCtrlVal(pn2, P2_VCUR, current); |
|
| - | 983 | double temperature=0; |
|
| - | 984 | double humidity=0; |
|
| - | 985 | GetCtrlVal(pn2, P2_TMON, &temperature); |
|
| - | 986 | GetCtrlVal(pn2, P2_HUMIDITY, &humidity); |
|
| 749 | if (fp) fprintf(fp, "%d %g %g %g\n |
987 | if (fp) fprintf(fp, "%d %g %g %g %g %g\n",tockaK, u, voltage,current, humidity, temperature); |
| 750 | printf("n=%d u=%g voltage=%g current=%g\n",tockaK, u, voltage,current); |
988 | if (debugCode) printf("n=%d u=%g voltage=%g current=%g\n",tockaK, u, voltage,current); |
| 751 | if (plivhandle) DeleteGraphPlot ( |
989 | if (plivhandle) DeleteGraphPlot (pn2, P2_GRAPHIV, plivhandle, VAL_IMMEDIATE_DRAW); |
| 752 | plivhandle = PlotXY ( |
990 | plivhandle = PlotXY (pn2, P2_GRAPHIV, xpoints, ypoints, tockaK+1, VAL_DOUBLE, VAL_DOUBLE, VAL_CONNECTED_POINTS, VAL_BOLD_X, VAL_SOLID, 1, VAL_RED); |
| 753 | ProcessSystemEvents(); |
991 | ProcessSystemEvents(); |
| 754 | tockaK++; |
992 | tockaK++; |
| 755 | if (stop) break; |
993 | if (stop) break; |
| 756 | } |
994 | } |
| - | 995 | if (stop) break; |
|
| 757 | } |
996 | } |
| - | 997 | u = 0; |
|
| - | 998 | K6517_vsource_set (u); |
|
| - | 999 | SetCtrlVal(pn2, P2_VMON, u); |
|
| - | 1000 | ||
| - | 1001 | SetCtrlVal(pnl, P1_ONOFF, 0); |
|
| - | 1002 | K6517_vsource_operate (0); |
|
| 758 | fclose(fp); |
1003 | fclose(fp); |
| 759 | free(xpoints); |
1004 | free(xpoints); |
| 760 | free(ypoints); |
1005 | free(ypoints); |
| - | 1006 | if (stop) break; |
|
| - | 1007 | if (repeatscan){ |
|
| - | 1008 | double period; |
|
| - | 1009 | GetCtrlVal(pn2,P2_PERIOD,&period); |
|
| - | 1010 | while (period>0){ |
|
| - | 1011 | Delay(1); |
|
| - | 1012 | period--; |
|
| - | 1013 | SetCtrlVal(pn2,P2_NEXTSCAN, period); |
|
| - | 1014 | if (stop) { |
|
| - | 1015 | SetCtrlVal(pn2,P2_NEXTSCAN, 0); |
|
| - | 1016 | return 0; |
|
| - | 1017 | } |
|
| - | 1018 | } |
|
| - | 1019 | } |
|
| - | 1020 | ||
| - | 1021 | } |
|
| - | 1022 | return 0; |
|
| - | 1023 | } |
|
| - | 1024 | ||
| - | 1025 | ||
| - | 1026 | ||
| - | 1027 | ||
| - | 1028 | ||
| - | 1029 | int CVICALLBACK IVSCANCB (int panel, int control, int event, |
|
| - | 1030 | void *callbackData, int eventData1, int eventData2) { |
|
| - | 1031 | ||
| - | 1032 | rID=100; |
|
| - | 1033 | switch (event) { |
|
| - | 1034 | case EVENT_COMMIT:{ |
|
| - | 1035 | ThreadFunctionPtr mythread = ivscan; |
|
| - | 1036 | CmtScheduleThreadPoolFunctionAdv (poolHandle, mythread, &rID, |
|
| - | 1037 | DEFAULT_THREAD_PRIORITY, |
|
| - | 1038 | EndOfThread, |
|
| - | 1039 | EVENT_TP_THREAD_FUNCTION_END, |
|
| - | 1040 | NULL, RUN_IN_SCHEDULED_THREAD, |
|
| - | 1041 | &tfID); |
|
| - | 1042 | } |
|
| 761 | break; |
1043 | break; |
| 762 | } |
1044 | } |
| 763 | return 0; |
1045 | return 0; |
| 764 | } |
1046 | } |
| - | 1047 | ||
| 765 | 1048 | ||
| 766 | int CVICALLBACK SETVOLTCB (int panel, int control, int event, |
1049 | int CVICALLBACK SETVOLTCB (int panel, int control, int event, |
| 767 | void *callbackData, int eventData1, int eventData2) { |
1050 | void *callbackData, int eventData1, int eventData2) { |
| 768 | double voltage; |
1051 | double voltage; |
| 769 | switch (event) { |
1052 | switch (event) { |
| 770 | case EVENT_COMMIT: |
1053 | case EVENT_COMMIT: |
| 771 | GetCtrlVal(panel, P2_VOLT, &voltage); |
1054 | GetCtrlVal(panel, P2_VOLT, &voltage); |
| 772 | K6517_vsource_set (voltage); |
1055 | K6517_vsource_set (voltage); |
| - | 1056 | SetCtrlVal(panel, P2_VMON, voltage); |
|
| 773 | break; |
1057 | break; |
| 774 | } |
1058 | } |
| 775 | return 0; |
1059 | return 0; |
| 776 | } |
1060 | } |
| 777 | 1061 | ||
| 778 | 1062 | ||
| 779 | int CVICALLBACK StopCB (int panel, int control, int event, |
1063 | int CVICALLBACK StopCB (int panel, int control, int event, |
| 780 | void *callbackData, int eventData1, int eventData2) { |
1064 | void *callbackData, int eventData1, int eventData2) { |
| 781 | switch (event) { |
1065 | switch (event) { |
| 782 | case EVENT_COMMIT: |
1066 | case EVENT_COMMIT: |
| 783 | stop = 1; |
1067 | stop = 1; |
| 784 | break; |
1068 | break; |
| 785 | } |
1069 | } |
| 786 | return 0; |
1070 | return 0; |
| 787 | } |
1071 | } |
| 788 | 1072 | ||
| 789 | int CVICALLBACK LogScaleCB (int panel, int control, int event, |
1073 | int CVICALLBACK LogScaleCB (int panel, int control, int event, |
| 790 | void *callbackData, int eventData1, int eventData2) { |
1074 | void *callbackData, int eventData1, int eventData2) { |
| 791 | int selected; |
1075 | int selected; |
| 792 | switch (event) { |
1076 | switch (event) { |
| 793 | case EVENT_COMMIT: |
1077 | case EVENT_COMMIT: |
| 794 | GetCtrlVal(panel, control, &selected); |
1078 | GetCtrlVal(panel, control, &selected); |
| 795 | if(selected) SetCtrlAttribute (panel, P2_GRAPHIV,ATTR_YMAP_MODE, VAL_LOG); |
1079 | if(selected) SetCtrlAttribute (panel, P2_GRAPHIV,ATTR_YMAP_MODE, VAL_LOG); |
| 796 | else SetCtrlAttribute (panel, P2_GRAPHIV,ATTR_YMAP_MODE, VAL_LINEAR); |
1080 | else SetCtrlAttribute (panel, P2_GRAPHIV,ATTR_YMAP_MODE, VAL_LINEAR); |
| 797 | break; |
1081 | break; |
| 798 | } |
1082 | } |
| 799 | return 0; |
1083 | return 0; |
| 800 | } |
1084 | } |
| 801 | 1085 | ||
| 802 | 1086 | ||
| 803 | //**************************** |
1087 | //**************************** |
| 804 | int EscapeString(const char *i, char *o) { |
1088 | int EscapeString(const char *i, char *o) { |
| 805 | int iptr=0, optr = 0; |
1089 | int iptr=0, optr = 0; |
| 806 | // walk though the input string |
1090 | // walk though the input string |
| 807 | for (iptr = 0; iptr < strlen(i); iptr++, optr++) { |
1091 | for (iptr = 0; iptr < strlen(i); iptr++, optr++) { |
| 808 | // search for |
1092 | // search for |
| 809 | if ( (i[iptr]=='\\') ) { |
1093 | if ( (i[iptr]=='\\') ) { |
| 810 | printf("Escape String %d %d \n",i[iptr] , i[iptr]==92 ) ; |
1094 | printf("Escape String %d %d \n",i[iptr] , i[iptr]==92 ) ; |
| 811 | //sa02Printf("Escape String %d %d \n",i[iptr] , ( (i[iptr] == 92) || (i[iptr] == 42) )) ; |
1095 | //sa02Printf("Escape String %d %d \n",i[iptr] , ( (i[iptr] == 92) || (i[iptr] == 42) )) ; |
| 812 | o[optr] = i[iptr]; |
1096 | o[optr] = i[iptr]; |
| 813 | optr++; |
1097 | optr++; |
| 814 | } |
1098 | } |
| 815 | o[optr] = i[iptr]; |
1099 | o[optr] = i[iptr]; |
| 816 | } |
1100 | } |
| 817 | o[optr] = '\0'; |
1101 | o[optr] = '\0'; |
| 818 | return 0; |
1102 | return 0; |
| 819 | } |
1103 | } |
| 820 | 1104 | ||
| 821 | 1105 | ||
| 822 | int CVICALLBACK DrawCB (int panel, int control, int event, |
1106 | int CVICALLBACK DrawCB (int panel, int control, int event, |
| 823 | void *callbackData, int eventData1, int eventData2) { |
1107 | void *callbackData, int eventData1, int eventData2) { |
| 824 | switch (event) { |
1108 | switch (event) { |
| 825 | case EVENT_COMMIT:{ |
1109 | case EVENT_COMMIT:{ |
| 826 | char fileName[100]; |
1110 | char fileName[100]; |
| 827 | char fname[100]; |
1111 | char fname[100]; |
| 828 | char path[100]; |
1112 | char path[100]; |
| 829 | GetCtrlVal(panel, P2_FILENAME, fileName); |
1113 | GetCtrlVal(panel, P2_FILENAME, fileName); |
| 830 | GetCtrlVal(panel, P2_PATH, path); |
1114 | GetCtrlVal(panel, P2_PATH, path); |
| 831 | sprintf(fname, "%s/%s.dat", path, fileName); |
1115 | sprintf(fname, "%s/%s.dat", path, fileName); |
| 832 | int status; |
1116 | int status; |
| 833 | char name[MAX_PATHNAME_LEN]; |
1117 | char name[MAX_PATHNAME_LEN]; |
| 834 | // char dfile[MAX_PATHNAME_LEN]; |
1118 | // char dfile[MAX_PATHNAME_LEN]; |
| 835 | // char efile[MAX_PATHNAME_LEN]; |
1119 | // char efile[MAX_PATHNAME_LEN]; |
| 836 | // status = FileSelectPopup ("dat", "*.dat", ".dat", |
1120 | // status = FileSelectPopup ("dat", "*.dat", ".dat", |
| 837 | // "Izberi datoteko s podatki", |
1121 | // "Izberi datoteko s podatki", |
| 838 | // VAL_LOAD_BUTTON, 0, 0, 1, 0, efile); |
1122 | // VAL_LOAD_BUTTON, 0, 0, 1, 0, efile); |
| 839 | // EscapeString(efile,dfile); |
1123 | // EscapeString(efile,dfile); |
| 840 | sprintf(name ,"C:/root/bin/root.exe IUdraw.cxx(\\\"%s\\\")", fname); |
1124 | sprintf(name ,"C:/root/bin/root.exe IUdraw.cxx(\\\"%s\\\")", fname); |
| 841 | // sprintf(name ,"C:/root/bin/root.exe IUdraw.cxx"); |
1125 | // sprintf(name ,"C:/root/bin/root.exe IUdraw.cxx"); |
| 842 | printf("%s\n",name); |
1126 | printf("%s\n",name); |
| 843 | LaunchExecutable(name); |
1127 | LaunchExecutable(name); |
| 844 | break; |
1128 | break; |
| 845 | } |
1129 | } |
| 846 | } |
1130 | } |
| 847 | return 0; |
1131 | return 0; |
| 848 | } |
1132 | } |
| 849 | 1133 | ||
| 850 | 1134 | ||
| 851 | int CVICALLBACK Print (int panel, int control, int event, |
1135 | int CVICALLBACK Print (int panel, int control, int event, |
| 852 | void *callbackData, int eventData1, int eventData2) { |
1136 | void *callbackData, int eventData1, int eventData2) { |
| 853 | char dfile[MAX_PATHNAME_LEN]; |
1137 | char dfile[MAX_PATHNAME_LEN]; |
| 854 | char name[MAX_PATHNAME_LEN]; |
1138 | char name[MAX_PATHNAME_LEN]; |
| 855 | int h2=0; |
1139 | int h2=0; |
| 856 | switch (event) { |
1140 | switch (event) { |
| 857 | case EVENT_COMMIT: { |
1141 | case EVENT_COMMIT: { |
| 858 | int hours, minutes, seconds; |
1142 | int hours, minutes, seconds; |
| 859 | int month, day, year; |
1143 | int month, day, year; |
| 860 | int id=-1; |
1144 | int id=-1; |
| 861 | //int bitmap = 0; |
1145 | //int bitmap = 0; |
| 862 | 1146 | ||
| 863 | GetSystemDate (&month,&day ,&year ); |
1147 | GetSystemDate (&month,&day ,&year ); |
| 864 | GetSystemTime(&hours, &minutes, &seconds); |
1148 | GetSystemTime(&hours, &minutes, &seconds); |
| 865 | sprintf(name,"IV"); |
1149 | sprintf(name,"IV"); |
| 866 | sprintf(dfile ,"%d_%d_%d_%d_%d_%s.bmp",year,month,day,hours,minutes, name ); |
1150 | sprintf(dfile ,"%d_%d_%d_%d_%d_%s.bmp",year,month,day,hours,minutes, name ); |
| 867 | SaveCtrlDisplayToFile (panel,P2_GRAPHIV, 0, -1, -1, dfile); |
1151 | SaveCtrlDisplayToFile (panel,P2_GRAPHIV, 0, -1, -1, dfile); |
| 868 | printf("bmp image saved as %s\n", dfile); |
1152 | printf("bmp image saved as %s\n", dfile); |
| 869 | 1153 | ||
| 870 | //PrintCtrl (p1h, P1_GRAPH2D, "sa02_CVI", 1, 1); |
1154 | //PrintCtrl (p1h, P1_GRAPH2D, "sa02_CVI", 1, 1); |
| 871 | } |
1155 | } |
| 872 | break; |
1156 | break; |
| 873 | } |
1157 | } |
| 874 | return 0; |
1158 | return 0; |
| 875 | } |
1159 | } |
| 876 | 1160 | ||
| 877 | int CVICALLBACK DebugCB (int panel, int control, int event, |
1161 | int CVICALLBACK DebugCB (int panel, int control, int event, |
| 878 | void *callbackData, int eventData1, int eventData2) { |
1162 | void *callbackData, int eventData1, int eventData2) { |
| 879 | int selected; |
1163 | int selected; |
| 880 |
|
1164 | |
| 881 | switch (event) { |
1165 | switch (event) { |
| 882 | case EVENT_COMMIT: |
1166 | case EVENT_COMMIT: |
| 883 | GetCtrlVal(panel, control, &selected); |
1167 | GetCtrlVal(panel, control, &selected); |
| 884 | if(selected) debugCode = 1; |
1168 | if(selected) debugCode = 1; |
| 885 | else debugCode = 0; |
1169 | else debugCode = 0; |
| 886 | break; |
1170 | break; |
| 887 | } |
1171 | } |
| 888 | return 0; |
1172 | return 0; |
| 889 | } |
1173 | } |
| 890 | 1174 | ||
| 891 | int CVICALLBACK Exit2CB (int panel, int control, int event, |
1175 | int CVICALLBACK Exit2CB (int panel, int control, int event, |
| 892 | void *callbackData, int eventData1, int eventData2) { |
1176 | void *callbackData, int eventData1, int eventData2) { |
| 893 | switch (event) { |
1177 | switch (event) { |
| 894 | case EVENT_COMMIT: |
1178 | case EVENT_COMMIT: |
| 895 | K6517_send (":OUTP OFF", 0); |
1179 | K6517_send (":OUTP OFF", 0); |
| 896 | QuitUserInterface(0); |
1180 | QuitUserInterface(0); |
| 897 | break; |
1181 | break; |
| 898 | } |
1182 | } |
| 899 | return 0; |
1183 | return 0; |
| 900 | } |
1184 | } |
| - | 1185 | ||
| - | 1186 | ||
| - | 1187 | ||
| 901 | #endif |
1188 | #endif |
| 902 | 1189 | ||