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