Rev 306 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 306 | Rev 311 | ||
---|---|---|---|
Line 71... | Line 71... | ||
71 | switch (event) { |
71 | switch (event) { |
72 | case EVENT_COMMIT: |
72 | case EVENT_COMMIT: |
73 | GetCtrlVal(pa,PA_CHANNEL, &ch); |
73 | GetCtrlVal(pa,PA_CHANNEL, &ch); |
74 | iRet = TMI_TimeOut(TMI_DeviceId, 1); |
74 | iRet = TMI_TimeOut(TMI_DeviceId, 1); |
75 | iRet = TMI_Refresh(TMI_DeviceId); |
75 | iRet = TMI_Refresh(TMI_DeviceId); |
76 | - | ||
77 | - | ||
78 | iRet = TMI_MoniDataQ(TMI_DeviceId, ch+1, &Voltage, &Current, &cv_cc); |
76 | iRet = TMI_MoniDataQ(TMI_DeviceId, ch+1, &Voltage, &Current, &cv_cc); |
79 | 77 | ||
80 | SetCtrlVal(panel, PA_VMON, Voltage); |
78 | SetCtrlVal(panel, PA_VMON, Voltage); |
81 | SetCtrlVal(panel, PA_IMON, Current); |
79 | SetCtrlVal(panel, PA_IMON, Current); |
82 | SetCtrlVal(panel, PA_CVCC, cv_cc); |
80 | SetCtrlVal(panel, PA_CVCC, cv_cc); |
83 | 81 | ||
84 | break; |
82 | break; |
85 | } |
83 | } |
86 | return 0; |
84 | return 0; |
87 | } |
85 | } |
88 | 86 | ||
89 | 87 | ||
90 | int CVICALLBACK SelectChannelCB (int panel, int control, int event, |
88 | int CVICALLBACK SelectChannelCB (int panel, int control, int event, |
91 | void *callbackData, int eventData1, int eventData2) { |
89 | void *callbackData, int eventData1, int eventData2) { |
92 | unsigned char state, preset; |
90 | unsigned char state, preset; |
Line 94... | Line 92... | ||
94 | unsigned char ch; |
92 | unsigned char ch; |
95 | switch (event) { |
93 | switch (event) { |
96 | case EVENT_COMMIT: |
94 | case EVENT_COMMIT: |
97 | GetCtrlVal(pa,PA_CHANNEL, &ch); |
95 | GetCtrlVal(pa,PA_CHANNEL, &ch); |
98 | GetCtrlVal(pa,PA_PRESET, &preset); |
96 | GetCtrlVal(pa,PA_PRESET, &preset); |
99 | - | ||
100 | 97 | ||
101 | - | ||
102 | TMI_VoltageQ(TMI_DeviceId, ch+1, preset, &Voltage); |
98 | TMI_VoltageQ(TMI_DeviceId, ch+1, preset, &Voltage); |
103 | TMI_CurrentQ(TMI_DeviceId, ch+1, preset, &Current); |
99 | TMI_CurrentQ(TMI_DeviceId, ch+1, preset, &Current); |
- | 100 | ||
104 | SetCtrlVal(pa, PA_VSET, Voltage); |
101 | SetCtrlVal(pa, PA_VSET, Voltage); |
105 | SetCtrlVal(pa, PA_ISET, Current); |
102 | SetCtrlVal(pa, PA_ISET, Current); |
106 | 103 | ||
107 | break; |
104 | break; |
108 | } |
105 | } |
109 | return 0; |
106 | return 0; |
110 | } |
107 | } |
111 | 108 | ||
- | 109 | int SetCooling(char onoff){ |
|
- | 110 | int nb=0; |
|
- | 111 | nb = ComWrt (COM_PORT, &onoff, 1); |
|
- | 112 | return nb; |
|
- | 113 | } |
|
112 | 114 | ||
113 | #define tcpChk(f) if ((g_TCPError=(f)) < 0) {ReportTCPError(); return -1; } |
115 | #define tcpChk(f) if ((g_TCPError=(f)) < 0) {ReportTCPError(); return -1; } |
114 | 116 | ||
115 | /*---------------------------------------------------------------------------*/ |
117 | /*---------------------------------------------------------------------------*/ |
116 | /* Module-globals */ |
118 | /* Module-globals */ |
Line 172... | Line 174... | ||
172 | } else { |
174 | } else { |
173 | receiveBuf[dataSize] = '\0'; |
175 | receiveBuf[dataSize] = '\0'; |
174 | printf("Received %s\n", receiveBuf); |
176 | printf("Received %s\n", receiveBuf); |
175 | int cmd=0; |
177 | int cmd=0; |
176 | float arg; |
178 | float arg; |
177 | sscanf("%d%f",&cmd,&arg); |
179 | sscanf(receiveBuf,"%d%f",&cmd,&arg); |
178 | switch (cmd){ |
180 | switch (cmd){ |
179 | case 1: |
181 | case 1: |
180 | SetCtrlVal( |
182 | SetCtrlVal(pa,PA_TSET,arg); |
181 | break; |
183 | break; |
182 | default: |
184 | default: |
183 | break; |
185 | break; |
184 | 186 | ||
185 | } |
187 | } |
Line 250... | Line 252... | ||
250 | 252 | ||
251 | /* We are successfully connected -- gather info */ |
253 | /* We are successfully connected -- gather info */ |
252 | 254 | ||
253 | if (GetTCPHostAddr (tempBuf, 256) >= 0) printf("%s\n" ,tempBuf); |
255 | if (GetTCPHostAddr (tempBuf, 256) >= 0) printf("%s\n" ,tempBuf); |
254 | if (GetTCPHostName (tempBuf, 256) >= 0) printf("%s\n" ,tempBuf); |
256 | if (GetTCPHostName (tempBuf, 256) >= 0) printf("%s\n" ,tempBuf); |
255 | 257 | ||
256 | 258 | ||
257 | 259 | ||
258 | } |
260 | } |
259 | 261 | ||
260 | SelectChannelCB (pa, PA_CHANNEL, EVENT_COMMIT, NULL, 0,0); |
262 | SelectChannelCB (pa, PA_CHANNEL, EVENT_COMMIT, NULL, 0,0); |
261 | ReadVoltageCurrentCB (pa, PA_CHANNEL, EVENT_COMMIT, NULL, 0,0); |
263 | ReadVoltageCurrentCB (pa, PA_CHANNEL, EVENT_COMMIT, NULL, 0,0); |
262 | 264 | ||
Line 269... | Line 271... | ||
269 | if (registered) |
271 | if (registered) |
270 | UnregisterTCPServer (portNum); |
272 | UnregisterTCPServer (portNum); |
271 | DiscardPanel (pa); |
273 | DiscardPanel (pa); |
272 | TMI_Close(); |
274 | TMI_Close(); |
273 | if (gFp) fclose(gFp); |
275 | if (gFp) fclose(gFp); |
274 | return 0; |
276 | return 0; |
275 | } |
277 | } |
276 | 278 | ||
277 | 279 | ||
278 | int CVICALLBACK ExitCB (int panel, int control, int event, |
280 | int CVICALLBACK ExitCB (int panel, int control, int event, |
279 | void *callbackData, int eventData1, int eventData2) { |
281 | void *callbackData, int eventData1, int eventData2) { |
280 | switch (event) { |
282 | switch (event) { |
281 | case EVENT_COMMIT: |
283 | case EVENT_COMMIT: |
282 | QuitUserInterface (0); |
284 | QuitUserInterface (0); |
- | 285 | break; |
|
- | 286 | } |
|
- | 287 | return 0; |
|
- | 288 | } |
|
- | 289 | ||
- | 290 | int CVICALLBACK SwitchCoolingOnOffCB (int panel, int control, int event, |
|
- | 291 | void *callbackData, int eventData1, int eventData2) { |
|
- | 292 | int onoff=0; |
|
- | 293 | ||
- | 294 | switch (event) { |
|
- | 295 | case EVENT_COMMIT: |
|
- | 296 | GetCtrlVal(pa,control,&onoff); |
|
- | 297 | SetCooling(onoff); |
|
- | 298 | ||
283 | break; |
299 | break; |
284 | } |
300 | } |
285 | return 0; |
301 | return 0; |
286 | } |
302 | } |
287 | - | ||
288 | - | ||
289 | 303 | ||
290 | int CVICALLBACK SwitchOnOffCB (int panel, int control, int event, |
304 | int CVICALLBACK SwitchOnOffCB (int panel, int control, int event, |
291 | void *callbackData, int eventData1, int eventData2) { |
305 | void *callbackData, int eventData1, int eventData2) { |
292 | unsigned char state; |
306 | unsigned char state; |
293 | switch (event) { |
307 | switch (event) { |
Line 311... | Line 325... | ||
311 | double temp= atof(read_data); |
325 | double temp= atof(read_data); |
312 | double f[10]; |
326 | double f[10]; |
313 | int debug1; |
327 | int debug1; |
314 | GetCtrlVal(pa,PA_DEBUG_1, &debug1); |
328 | GetCtrlVal(pa,PA_DEBUG_1, &debug1); |
315 | //printf("%f#%s#", temp, read_data); |
329 | //printf("%f#%s#", temp, read_data); |
- | 330 | // temp1 , temp2 , temp3 , temp4 , temp humidity sens, rel.humidity |
|
- | 331 | if (bytes_read >0) { |
|
- | 332 | SetCtrlVal(pa,PA_ARDUINO, read_data); |
|
- | 333 | } |
|
316 | sscanf(read_data,"%lf %lf %lf %lf %lf %lf",&f[0],&f[1],&f[2],&f[3],&f[4],&f[5]); |
334 | sscanf(read_data,"%lf %lf %lf %lf %lf %lf",&f[0],&f[1],&f[2],&f[3],&f[4],&f[5]); |
317 | double humidity = f[5]; |
335 | double humidity = f[5]; |
- | 336 | double htemp = f[4]; |
|
318 | // printf("%lf %lf %lf %lf %lf %lf",f[0],f[1],f[2],f[3],f[4],f[5]); |
337 | // printf("%lf %lf %lf %lf %lf %lf",f[0],f[1],f[2],f[3],f[4],f[5]); |
319 | int RS232Error = ReturnRS232Err (); |
338 | int RS232Error = ReturnRS232Err (); |
320 | if (ReturnRS232Err ()) { |
339 | if (ReturnRS232Err ()) { |
321 | sprintf(read_data,"#%s\n", GetRS232ErrorString(RS232Error)); |
340 | sprintf(read_data,"#%s\n", GetRS232ErrorString(RS232Error)); |
322 | MessagePopup("RS232Err",read_data); |
341 | MessagePopup("RS232Err",read_data); |
Line 336... | Line 355... | ||
336 | TMI_Preset(TMI_DeviceId,preset); |
355 | TMI_Preset(TMI_DeviceId,preset); |
337 | GetCtrlVal(pa,PA_POLAR,&polar); |
356 | GetCtrlVal(pa,PA_POLAR,&polar); |
338 | 357 | ||
339 | double tdiff = temp - tset; |
358 | double tdiff = temp - tset; |
340 | double retpid = UpdatePID(&pid, tdiff, temp); |
359 | double retpid = UpdatePID(&pid, tdiff, temp); |
341 | const double troom = |
360 | const double troom = htemp; |
342 | double Pheat= 0.2 * (temp - troom); |
361 | double Pheat= 0.2 * (temp - troom); |
343 | double Ptec = retpid - Pheat*2; |
362 | double Ptec = retpid - Pheat*2; |
344 | vset = (polar*Ptec>0) ? sqrt(fabs(Ptec)) : 0; |
363 | vset = (polar*Ptec>0) ? sqrt(fabs(Ptec)) : 0; |
345 | if (debug1) printf("%d PID tmon=%f tset=%f tdiff=%f vmon=%f imom=%f pid=%f Pheat=%f =>vset %f", ch, temp, tset, tdiff, vmon, imon,retpid ,Pheat, vset); |
364 | if (debug1) printf("%d PID tmon=%f tset=%f tdiff=%f vmon=%f imom=%f pid=%f Pheat=%f =>vset %f", ch, temp, tset, tdiff, vmon, imon,retpid ,Pheat, vset); |
346 | GetCtrlVal(pa,PA_VMAX,&vmax); |
365 | GetCtrlVal(pa,PA_VMAX,&vmax); |
Line 360... | Line 379... | ||
360 | PlotStripChart (pa, PA_GRAPH, &temp, 1, 0, 0, VAL_DOUBLE); |
379 | PlotStripChart (pa, PA_GRAPH, &temp, 1, 0, 0, VAL_DOUBLE); |
361 | double pgraph[3]= {vmon,imon, 100*(temp-told)}; |
380 | double pgraph[3]= {vmon,imon, 100*(temp-told)}; |
362 | PlotStripChart (pa, PA_GRAPH_VMON, pgraph, 3, 0, 0, VAL_DOUBLE); |
381 | PlotStripChart (pa, PA_GRAPH_VMON, pgraph, 3, 0, 0, VAL_DOUBLE); |
363 | PlotStripChart (pa, PA_GRAPH_3, &humidity, 1, 0, 0, VAL_DOUBLE); |
382 | PlotStripChart (pa, PA_GRAPH_3, &humidity, 1, 0, 0, VAL_DOUBLE); |
364 | SetCtrlVal(pa,PA_TMON,temp); |
383 | SetCtrlVal(pa,PA_TMON,temp); |
365 | - | ||
- | 384 | SetCtrlVal(pa,PA_HTMON,htemp); |
|
366 | SetCtrlVal(pa,PA_HUMIDITY,humidity); |
385 | SetCtrlVal(pa,PA_HUMIDITY,humidity); |
367 | 386 | ||
368 | char transmitBuf[512]= {0}; |
387 | char transmitBuf[512]= {0}; |
369 | sprintf(transmitBuf, "%u %f %f %f %f\n", time(NULL), humidity, temp, tdiff, temp-told); |
388 | sprintf(transmitBuf, "%u %f %f %f %f\n", time(NULL), humidity, temp, tdiff, temp-told); |
370 | if (g_hconversation) |
389 | if (g_hconversation) |