Rev 351 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 351 | Rev 353 | ||
---|---|---|---|
1 | #include <cvirte.h> |
1 | #include <cvirte.h> |
2 | #include <userint.h> |
2 | #include <userint.h> |
3 | #include "fourier.h" |
3 | #include "fourier.h" |
4 | #include <utility.h> |
4 | #include <utility.h> |
5 | #include <ansi_c.h> |
5 | #include <ansi_c.h> |
6 | #include <rs232.h> |
6 | #include <rs232.h> |
7 | 7 | ||
8 | int read_term_index; |
8 | int read_term_index; |
9 | int read_term; |
9 | int read_term; |
10 | int read_cnt; |
10 | int read_cnt; |
11 | int bytes_read; |
11 | int bytes_read; |
12 | 12 | ||
13 | int pCOM1; |
13 | int pCOM1; |
14 | int pCOM2; |
14 | int pCOM2; |
15 | 15 | ||
16 | 16 | ||
17 | #define TEXT_LENGTH 2000 |
17 | #define TEXT_LENGTH 2000 |
18 | char read_data[TEXT_LENGTH]; |
18 | char read_data[TEXT_LENGTH]; |
19 | char read_data2[TEXT_LENGTH]; |
19 | char read_data2[TEXT_LENGTH]; |
20 | 20 | ||
21 | static int panel; |
21 | static int panel; |
22 | #define MAX_THREADS 10 |
22 | #define MAX_THREADS 10 |
23 | 23 | ||
24 | static CmtThreadPoolHandle poolHandle = 0; |
24 | static CmtThreadPoolHandle poolHandle = 0; |
25 | void SetDimming(int state) { |
25 | void SetDimming(int state) { |
26 | 26 | ||
27 | SetCtrlAttribute (panel, p1_START, ATTR_DIMMED, state); |
27 | SetCtrlAttribute (panel, p1_START, ATTR_DIMMED, state); |
28 | SetCtrlAttribute (panel, p1_EXIT, ATTR_DIMMED, state); |
28 | SetCtrlAttribute (panel, p1_EXIT, ATTR_DIMMED, state); |
29 | SetCtrlAttribute (panel, p1_STOP, ATTR_DIMMED, state); |
29 | SetCtrlAttribute (panel, p1_STOP, ATTR_DIMMED, state); |
30 | 30 | ||
31 | } |
31 | } |
32 | 32 | ||
33 | 33 | ||
34 | 34 | ||
35 | 35 | ||
36 | 36 | ||
37 | 37 | ||
38 | 38 | ||
39 | 39 | ||
40 | 40 | ||
41 | int main (int argc, char *argv[]) |
41 | int main (int argc, char *argv[]) |
42 | { |
42 | { |
43 | SetStdioPort (CVI_STDIO_WINDOW); |
43 | SetStdioPort (CVI_STDIO_WINDOW); |
44 | SetStdioWindowOptions (10000, 0, 0); |
44 | SetStdioWindowOptions (10000, 0, 0); |
45 | SetStdioWindowVisibility(1); |
45 | SetStdioWindowVisibility(1); |
46 | if (InitCVIRTE (0, argv, 0) == 0) |
46 | if (InitCVIRTE (0, argv, 0) == 0) |
47 | return -1; /* out of memory */ |
47 | return -1; /* out of memory */ |
48 | if ((panel= LoadPanel (0, "fourier.uir", p1)) < 0) |
48 | if ((panel= LoadPanel (0, "fourier.uir", p1)) < 0) |
49 | return -1; |
49 | return -1; |
50 | //CmtNewThreadPool (MAX_THREADS, &poolHandle); |
50 | //CmtNewThreadPool (MAX_THREADS, &poolHandle); |
51 | DisplayPanel (panel); |
51 | DisplayPanel (panel); |
52 | SetDimming(0); |
52 | SetDimming(0); |
53 | //StartCB(panel, 0, EVENT_COMMIT, NULL, 0 ,0); |
53 | //StartCB(panel, 0, EVENT_COMMIT, NULL, 0 ,0); |
54 | RunUserInterface (); |
54 | RunUserInterface (); |
55 | DiscardPanel (panel); |
55 | DiscardPanel (panel); |
56 | return 0; |
56 | return 0; |
57 | 57 | ||
58 | } |
58 | } |
59 | 59 | ||
60 | int CVICALLBACK ExitCB (int panel, int control, int event, |
60 | int CVICALLBACK ExitCB (int panel, int control, int event, |
61 | void *callbackData, int eventData1, int eventData2) |
61 | void *callbackData, int eventData1, int eventData2) |
62 | { |
62 | { |
63 | switch (event) |
63 | switch (event) |
64 | { |
64 | { |
65 | case EVENT_COMMIT: |
65 | case EVENT_COMMIT: |
66 | QuitUserInterface (0); |
66 | QuitUserInterface (0); |
67 | break; |
67 | break; |
68 | } |
68 | } |
69 | return 0; |
69 | return 0; |
70 | } |
70 | } |
71 | 71 | ||
72 | int CVICALLBACK StopCB (int panel, int control, int event, |
72 | int CVICALLBACK StopCB (int panel, int control, int event, |
73 | void *callbackData, int eventData1, int eventData2) |
73 | void *callbackData, int eventData1, int eventData2) |
74 | { |
74 | { |
75 | switch (event) |
75 | switch (event) |
76 | { |
76 | { |
77 | case EVENT_COMMIT: |
77 | case EVENT_COMMIT: |
78 | CloseCom(pCOM1); |
78 | CloseCom(pCOM1); |
79 | CloseCom(pCOM2); |
79 | CloseCom(pCOM2); |
80 | break; |
80 | break; |
81 | } |
81 | } |
82 | return 0; |
82 | return 0; |
83 | } |
83 | } |
84 | 84 | ||
85 | 85 | ||
86 | 86 | ||
87 | /* Callback Function */ |
87 | /* Callback Function */ |
88 | void ComCallback1(int portNumber, int eventMask, void *callbackdata) { |
88 | void ComCallback1(int portNumber, int eventMask, void *callbackdata) { |
89 | 89 | ||
90 | if (eventMask & LWRS_RXFLAG) { |
90 | if (eventMask & LWRS_RXFLAG) { |
91 | //printf("Received specified character\n"); |
91 | //printf("Received specified character\n"); |
92 | int strLen = GetInQLen (pCOM1); |
92 | int strLen = GetInQLen (pCOM1); |
93 | bytes_read = ComRd (pCOM1, read_data, strLen); |
93 | bytes_read = ComRd (pCOM1, read_data, strLen); |
94 | float voltage; |
94 | float voltage; |
95 | sscanf(read_data,"%f",&voltage); |
95 | sscanf(read_data,"%f",&voltage); |
96 | //printf("%f %d %d#%s#", temp,state[0], state[1], read_data); |
96 | //printf("%f %d %d#%s#", temp,state[0], state[1], read_data); |
97 | int RS232Error = ReturnRS232Err (); |
97 | int RS232Error = ReturnRS232Err (); |
98 | if (ReturnRS232Err ()) { |
98 | if (ReturnRS232Err ()) { |
99 | sprintf(read_data,"#%s\n", GetRS232ErrorString(RS232Error)); |
99 | sprintf(read_data,"#%s\n", GetRS232ErrorString(RS232Error)); |
100 | MessagePopup("RS232Err",read_data); |
100 | MessagePopup("RS232Err",read_data); |
101 | } else { |
101 | } else { |
102 | //float ohm; |
102 | //float ohm; |
103 | //double tset; |
103 | //double tset; |
104 | 104 | ||
105 | //char onoff; |
105 | //char onoff; |
106 | //double Voltage, Current; |
106 | //double Voltage, Current; |
107 | //char cres[200]; |
107 | //char cres[200]; |
108 | //int i=0; |
108 | //int i=0; |
109 | //int onoff1 = 0; |
109 | //int onoff1 = 0; |
110 | SetCtrlVal(panel, p1_VMON, voltage); |
110 | SetCtrlVal(panel, p1_VMON, voltage); |
111 | 111 | ||
112 | 112 | ||
113 | 113 | ||
114 | //Voltage =K617_vsource_get(); |
114 | //Voltage =K617_vsource_get(); |
115 | //Current =K617_get(cres,&i); |
115 | //Current =K617_get(cres,&i); |
116 | //K617_vsource_set(vset); |
116 | //K617_vsource_set(vset); |
117 | //K617_vsource_operate(onoff1); |
117 | //K617_vsource_operate(onoff1); |
118 | //SetCtrlVal(pa,PA_VOLTAGE,Voltage); |
118 | //SetCtrlVal(pa,PA_VOLTAGE,Voltage); |
119 | //SetCtrlVal(pa,PA_CURRENT,Current); |
119 | //SetCtrlVal(pa,PA_CURRENT,Current); |
120 | 120 | ||
121 | PlotStripChart (panel, p1_GRAPH, &voltage, 1, 0, 0, VAL_FLOAT); |
121 | PlotStripChart (panel, p1_GRAPH, &voltage, 1, 0, 0, VAL_FLOAT); |
122 | 122 | ||
123 | 123 | ||
124 | 124 | ||
125 | 125 | ||
126 | 126 | ||
127 | } |
127 | } |
128 | } |
128 | } |
129 | 129 | ||
130 | if (eventMask & LWRS_TXEMPTY) printf("Transmit queue now empty\n"); |
130 | if (eventMask & LWRS_TXEMPTY) printf("Transmit queue now empty\n"); |
131 | 131 | ||
132 | if (eventMask & LWRS_RECEIVE) { |
132 | if (eventMask & LWRS_RECEIVE) { |
133 | 133 | ||
134 | printf("50 or more bytes in input queue\n"); |
134 | printf("50 or more bytes in input queue\n"); |
135 | 135 | ||
136 | } |
136 | } |
137 | 137 | ||
138 | } |
138 | } |
139 | 139 | ||
140 | int pozicija = 0; |
140 | int pozicija = 0; |
141 | 141 | ||
142 | int SetPosition(int pos){ |
142 | int SetPosition(int pos){ |
143 | int nb=0; |
143 | int nb=0; |
144 | char str[20]; |
144 | char str[20]; |
145 | sprintf(str, "X%d\n", pos); |
145 | sprintf(str, "X%d\n", pos); |
146 | int len = strlen(str); |
146 | int len = strlen(str); |
147 | nb = ComWrt (pCOM2, str, len); |
147 | nb = ComWrt (pCOM2, str, len); |
148 | return nb; |
148 | return nb; |
149 | } |
149 | } |
150 | 150 | ||
151 | float vx = 100.0; |
151 | float vx = 100.0; |
152 | 152 | ||
153 | int SetSpeed(float v){ |
153 | int SetSpeed(float v){ |
154 | int nb = 0; |
154 | int nb = 0; |
155 | char vxset[20]; |
155 | char vxset[20]; |
156 | sprintf(vxset, "$110=%.2f\n", v); |
156 | sprintf(vxset, "$110=%.2f\n", v); |
157 | 157 | ||
158 | printf("Speed %s", vxset); |
158 | printf("Speed %s", vxset); |
159 | int len1 = strlen(vxset); |
159 | int len1 = strlen(vxset); |
160 | nb = ComWrt (pCOM2, vxset, len1); |
160 | nb = ComWrt (pCOM2, vxset, len1); |
161 | return nb; |
161 | return nb; |
162 | } |
162 | } |
163 | 163 | ||
164 | 164 | ||
165 | int first = 1; |
165 | int first = 1; |
166 | 166 | ||
167 | 167 | ||
168 | 168 | ||
169 | /* Callback Function */ |
169 | /* Callback Function */ |
170 | void ComCallback2(int portNumber, int eventMask, void *callbackdata) { |
170 | void ComCallback2(int portNumber, int eventMask, void *callbackdata) { |
171 | 171 | ||
172 | if (eventMask & LWRS_RXFLAG) { |
172 | if (eventMask & LWRS_RXFLAG) { |
173 | //printf("Received specified character\n"); |
173 | //printf("Received specified character\n"); |
174 | int strLen = GetInQLen (pCOM2); |
174 | int strLen = GetInQLen (pCOM2); |
175 | bytes_read = ComRd (pCOM2, read_data2, strLen); |
175 | bytes_read = ComRd (pCOM2, read_data2, strLen); |
176 | printf("%s\n", read_data2); |
176 | printf("%s\n", read_data2); |
177 | 177 | ||
178 | 178 | ||
179 | if(first){ |
179 | if(first){ |
180 | SetSpeed(100.00); |
180 | SetSpeed(100.00); |
181 | 181 | ||
182 | 182 | ||
183 | first = 0; |
183 | first = 0; |
184 | } |
184 | } |
185 | 185 | ||
186 | 186 | ||
187 | 187 | ||
188 | 188 | ||
189 | GetCtrlVal(panel,p1_POZICIJA, &pozicija); |
189 | GetCtrlVal(panel,p1_POZICIJA, &pozicija); |
190 | 190 | ||
191 | SetPosition(pozicija); |
191 | SetPosition(pozicija); |
192 | 192 | ||
193 | 193 | ||
194 | 194 | ||
195 | 195 | ||
196 | 196 | ||
197 | //printf("%f %d %d#%s#", temp,state[0], state[1], read_data); |
197 | //printf("%f %d %d#%s#", temp,state[0], state[1], read_data); |
198 | int RS232Error = ReturnRS232Err (); |
198 | int RS232Error = ReturnRS232Err (); |
199 | if (ReturnRS232Err ()) { |
199 | if (ReturnRS232Err ()) { |
200 | sprintf(read_data2,"#%s\n", GetRS232ErrorString(RS232Error)); |
200 | sprintf(read_data2,"#%s\n", GetRS232ErrorString(RS232Error)); |
201 | MessagePopup("RS232Err",read_data2); |
201 | MessagePopup("RS232Err",read_data2); |
202 | } else { |
202 | } else { |
203 | //float ohm; |
203 | //float ohm; |
204 | //double tset; |
204 | //double tset; |
205 | 205 | ||
206 | //char onoff; |
206 | //char onoff; |
207 | //double Voltage, Current; |
207 | //double Voltage, Current; |
208 | //char cres[200]; |
208 | //char cres[200]; |
209 | //int i=0; |
209 | //int i=0; |
210 | //int onoff1 = 0; |
210 | //int onoff1 = 0; |
211 | //SetCtrlVal(panel, p1_VMON, voltage); |
211 | //SetCtrlVal(panel, p1_VMON, voltage); |
212 | 212 | ||
213 | 213 | ||
214 | 214 | ||
215 | //Voltage =K617_vsource_get(); |
215 | //Voltage =K617_vsource_get(); |
216 | //Current =K617_get(cres,&i); |
216 | //Current =K617_get(cres,&i); |
217 | //K617_vsource_set(vset); |
217 | //K617_vsource_set(vset); |
218 | //K617_vsource_operate(onoff1); |
218 | //K617_vsource_operate(onoff1); |
219 | //SetCtrlVal(pa,PA_VOLTAGE,Voltage); |
219 | //SetCtrlVal(pa,PA_VOLTAGE,Voltage); |
220 | //SetCtrlVal(pa,PA_CURRENT,Current); |
220 | //SetCtrlVal(pa,PA_CURRENT,Current); |
221 | 221 | ||
222 | //PlotStripChart (panel, p1_GRAPH, &voltage, 1, 0, 0, VAL_FLOAT); |
222 | //PlotStripChart (panel, p1_GRAPH, &voltage, 1, 0, 0, VAL_FLOAT); |
223 | 223 | ||
224 | 224 | ||
225 | 225 | ||
226 | 226 | ||
227 | 227 | ||
228 | } |
228 | } |
229 | } |
229 | } |
230 | 230 | ||
231 | //if (eventMask & LWRS_TXEMPTY) printf("Transmit queue now empty\n"); |
231 | //if (eventMask & LWRS_TXEMPTY) printf("Transmit queue now empty\n"); |
232 | 232 | ||
233 | if (eventMask & LWRS_RECEIVE) { |
233 | if (eventMask & LWRS_RECEIVE) { |
234 | 234 | ||
235 | printf("50 or more bytes in input queue\n"); |
235 | printf("50 or more bytes in input queue\n"); |
236 | 236 | ||
237 | } |
237 | } |
238 | 238 | ||
239 | } |
239 | } |
240 | 240 | ||
241 | 241 | ||
242 | int CVICALLBACK StartCB (int panel, int control, int event, |
242 | int CVICALLBACK StartCB (int panel, int control, int event, |
243 | void *callbackData, int eventData1, int eventData2) |
243 | void *callbackData, int eventData1, int eventData2) |
244 | { |
244 | { |
245 | int ierr; |
245 | int ierr; |
246 | int ierr2; |
246 | int ierr2; |
247 | 247 | ||
248 | switch (event) { |
248 | switch (event) { |
249 | case EVENT_COMMIT: |
249 | case EVENT_COMMIT: |
250 | 250 | ||
251 | 251 | ||
252 | first = 1; |
252 | first = 1; |
253 | GetCtrlVal(panel,p1_COM1,&pCOM1); |
253 | GetCtrlVal(panel,p1_COM1,&pCOM1); |
254 | GetCtrlVal(panel,p1_COM2,&pCOM2); |
254 | GetCtrlVal(panel,p1_COM2,&pCOM2); |
255 | 255 | ||
256 | 256 | ||
257 | //printf("%d %d\n", pCOM1, pCOM2); |
257 | //printf("%d %d\n", pCOM1, pCOM2); |
258 | ierr = OpenComConfig (pCOM1, "", 115200, 0, 8, 1, 512, 512); |
258 | ierr = OpenComConfig (pCOM1, "", 115200, 0, 8, 1, 512, 512); |
259 | /* Turn off Hardware handshaking (loopback test will not function with it on) */ |
259 | /* Turn off Hardware handshaking (loopback test will not function with it on) */ |
260 | SetCTSMode (pCOM1, LWRS_HWHANDSHAKE_OFF); |
260 | SetCTSMode (pCOM1, LWRS_HWHANDSHAKE_OFF); |
261 | 261 | ||
262 | /* Make sure Serial buffers are empty */ |
262 | /* Make sure Serial buffers are empty */ |
263 | FlushInQ (pCOM1); |
263 | FlushInQ (pCOM1); |
264 | FlushOutQ (pCOM1); |
264 | FlushOutQ (pCOM1); |
265 | 265 | ||
266 | int notifyCount1 = 50; /* Wait for at least 50 bytes in queue. */ |
266 | int notifyCount1 = 50; /* Wait for at least 50 bytes in queue. */ |
267 | int eventChar1 = 10; /* Wait for LF. */ |
267 | int eventChar1 = 10; /* Wait for LF. */ |
268 | int eventMask1 = LWRS_RXFLAG | LWRS_TXEMPTY | LWRS_RECEIVE; |
268 | int eventMask1 = LWRS_RXFLAG | LWRS_TXEMPTY | LWRS_RECEIVE; |
269 | 269 | ||
270 | ierr2 = OpenComConfig (pCOM2, "", 115200, 0, 8, 1, 512, 512); |
270 | ierr2 = OpenComConfig (pCOM2, "", 115200, 0, 8, 1, 512, 512); |
271 | /* Turn off Hardware handshaking (loopback test will not function with it on) */ |
271 | /* Turn off Hardware handshaking (loopback test will not function with it on) */ |
272 | SetCTSMode (pCOM2, LWRS_HWHANDSHAKE_OFF); |
272 | SetCTSMode (pCOM2, LWRS_HWHANDSHAKE_OFF); |
273 | 273 | ||
274 | printf("ierr %d %d\n", ierr, ierr2); |
274 | printf("ierr %d %d\n", ierr, ierr2); |
275 | 275 | ||
276 | 276 | ||
277 | /* Make sure Serial buffers are empty */ |
277 | /* Make sure Serial buffers are empty */ |
278 | FlushInQ (pCOM2); |
278 | FlushInQ (pCOM2); |
279 | FlushOutQ (pCOM2); |
279 | FlushOutQ (pCOM2); |
280 | 280 | ||
281 | int notifyCount2 = 50; /* Wait for at least 50 bytes in queue. */ |
281 | int notifyCount2 = 50; /* Wait for at least 50 bytes in queue. */ |
282 | int eventChar2 = 10; /* Wait for LF. */ |
282 | int eventChar2 = 10; /* Wait for LF. */ |
283 | int eventMask2 = LWRS_RXFLAG | LWRS_TXEMPTY | LWRS_RECEIVE; |
283 | int eventMask2 = LWRS_RXFLAG | LWRS_TXEMPTY | LWRS_RECEIVE; |
284 | 284 | ||
285 | 285 | ||
286 | 286 | ||
287 | 287 | ||
288 | 288 | ||
289 | //InstallComCallback (pCOM1, eventMask1, notifyCount1, eventChar1, ComCallback1, NULL); |
289 | //InstallComCallback (pCOM1, eventMask1, notifyCount1, eventChar1, ComCallback1, NULL); |
290 | InstallComCallback (pCOM2, eventMask2, notifyCount2, eventChar2, ComCallback2, NULL); |
290 | InstallComCallback (pCOM2, eventMask2, notifyCount2, eventChar2, ComCallback2, NULL); |
291 | 291 | ||
292 | 292 | ||
293 | 293 | ||
294 | 294 | ||
295 | break; |
295 | break; |
296 | } |
296 | } |
297 | return 0; |
297 | return 0; |
298 | } |
298 | } |
299 | 299 | ||
300 | 300 | ||
301 | 301 | ||
302 | 302 | ||
303 | 303 | ||
304 | int CVICALLBACK GoToEndCB (int panel, int control, int event, |
304 | int CVICALLBACK GoToEndCB (int panel, int control, int event, |
305 | void *callbackData, int eventData1, int eventData2) |
305 | void *callbackData, int eventData1, int eventData2) |
306 | { |
306 | { |
307 | switch (event) |
307 | switch (event) |
308 | { |
308 | { |
309 | case EVENT_COMMIT: |
309 | case EVENT_COMMIT: |
310 | 310 | ||
311 | break; |
311 | break; |
312 | } |
312 | } |
313 | return 0; |
313 | return 0; |
314 | } |
314 | } |
315 | 315 | ||
316 | int CVICALLBACK GoToZeroCB (int panel, int control, int event, |
316 | int CVICALLBACK GoToZeroCB (int panel, int control, int event, |
317 | void *callbackData, int eventData1, int eventData2) |
317 | void *callbackData, int eventData1, int eventData2) |
318 | { |
318 | { |
319 | switch (event) |
319 | switch (event) |
320 | { |
320 | { |
321 | case EVENT_COMMIT: |
321 | case EVENT_COMMIT: |
322 | int nb = 0; |
322 | int nb = 0; |
323 | 323 | ||
324 | nb = ComWrt (pCOM2, "X0\n", 4); |
324 | nb = ComWrt (pCOM2, "X0\n", 4); |
325 | return nb; |
325 | return nb; |
326 | break; |
326 | break; |
327 | } |
327 | } |
328 | return 0; |
328 | return 0; |
329 | } |
329 | } |
330 | 330 | ||
331 | int CVICALLBACK ResetCB (int panel, int control, int event, |
331 | int CVICALLBACK ResetCB (int panel, int control, int event, |
332 | void *callbackData, int eventData1, int eventData2) |
332 | void *callbackData, int eventData1, int eventData2) |
333 | { |
333 | { |
334 | switch (event) |
334 | switch (event) |
335 | { |
335 | { |
336 | case EVENT_COMMIT: |
336 | case EVENT_COMMIT: |
337 | 337 | ||
338 | break; |
338 | break; |
339 | } |
339 | } |
340 | return 0; |
340 | return 0; |
341 | } |
341 | } |
342 | 342 | ||
343 | 343 | ||
344 | 344 |