Rev 303 | Rev 306 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 303 | Rev 305 | ||
---|---|---|---|
Line -... | Line 1... | ||
- | 1 | #include "K6517-ctrl.h" |
|
- | 2 | #include <tcpsupp.h> |
|
1 | #include <rs232.h> |
3 | #include <rs232.h> |
2 | #include <utility.h> |
4 | #include <utility.h> |
3 | #include <userint.h> |
5 | #include <userint.h> |
4 | #include <ansi_c.h> |
6 | #include <ansi_c.h> |
5 | #include <pw18-1.8aq.h> |
7 | #include <pw18-1.8aq.h> |
6 | #include "TempCtrl.h" |
8 | #include "TempCtrl.h" |
7 | FILE *gFp; |
9 | FILE *gFp; |
8 | 10 | ||
9 | #define RSTREG(a,x) (a&=(~(x))) |
11 | #define RSTREG(a,x) (a&=(~(x))) |
10 | #define SETREG(a,x) (a|=x) |
12 | #define SETREG(a,x) (a|=x) |
11 | 13 | ||
12 | int gMask=0xF; |
14 | int gMask=0xF; |
Line 22... | Line 24... | ||
22 | int bytes_read; |
24 | int bytes_read; |
23 | 25 | ||
24 | #define COM_PORT 11 |
26 | #define COM_PORT 11 |
25 | 27 | ||
26 | 28 | ||
27 | typedef struct |
29 | typedef struct { |
28 | { |
- | |
29 | double |
30 | double dState; // Last temperature input |
30 | double |
31 | double iState; // Integrator state |
31 | double |
32 | double iMax, iMin; // Maximum and minimum allowable integrator state |
32 |
|
33 | double iGain, // integral gain |
33 | pGain, // proportional gain |
34 | pGain, // proportional gain |
34 | dGain; // derivative gain |
35 | dGain; // derivative gain |
35 | } SPid; |
36 | } SPid; |
36 | 37 | ||
37 | SPid pid; |
38 | SPid pid; |
38 | 39 | ||
39 | double UpdatePID(SPid * |
40 | double UpdatePID(SPid *pid, double error, double temperature) { |
40 | { |
- | |
41 | double pTerm, dTerm, iTerm; |
41 | double pTerm, dTerm, iTerm; |
42 |
|
42 | pTerm = pid->pGain * error; |
43 | // calculate the proportional term |
43 | // calculate the proportional term |
44 | // calculate the integral state with appropriate limiting |
44 | // calculate the integral state with appropriate limiting |
45 | pid->iState += error; |
45 | pid->iState += error; |
46 | if (pid->iState > pid->iMax) pid->iState = pid->iMax; |
46 | if (pid->iState > pid->iMax) pid->iState = pid->iMax; |
47 | else if (pid->iState < pid->iMin) pid->iState = pid->iMin; |
47 | else if (pid->iState < pid->iMin) pid->iState = pid->iMin; |
48 | //if (debug ) |
48 | //if (debug ) |
49 | iTerm = pid->iGain * pid->iState; // calculate the integral term |
49 | iTerm = pid->iGain * pid->iState; // calculate the integral term |
50 | dTerm = pid->dGain * (temperature - pid->dState); |
50 | dTerm = pid->dGain * (temperature - pid->dState); |
51 | pid->dState = temperature; |
51 | pid->dState = temperature; |
52 | return pTerm + iTerm - dTerm; |
52 | return pTerm + iTerm - dTerm; |
53 | } |
53 | } |
54 | 54 | ||
55 | void SetDimming(int state) { |
55 | void SetDimming(int state) { |
56 | SetCtrlAttribute (pa, PA_START, ATTR_DIMMED, state); |
56 | SetCtrlAttribute (pa, PA_START, ATTR_DIMMED, state); |
57 | SetCtrlAttribute (pa, PA_EXIT, ATTR_DIMMED, state); |
57 | SetCtrlAttribute (pa, PA_EXIT, ATTR_DIMMED, state); |
Line 59... | Line 59... | ||
59 | } |
59 | } |
60 | 60 | ||
61 | 61 | ||
62 | 62 | ||
63 | int CVICALLBACK ReadVoltageCurrentCB (int panel, int control, int event, |
63 | int CVICALLBACK ReadVoltageCurrentCB (int panel, int control, int event, |
64 | void |
64 | void *callbackData, int eventData1, int eventData2) { |
65 | { |
65 | |
66 | - | ||
67 | int iRet; |
66 | int iRet; |
68 |
|
67 | char ch=0; |
69 |
|
68 | double Voltage; |
70 | double Current; |
69 | double Current; |
71 |
|
70 | char cv_cc; |
72 | switch |
71 | switch (event) { |
73 | { |
- | |
74 | case EVENT_COMMIT: |
72 | case EVENT_COMMIT: |
75 | GetCtrlVal(pa,PA_CHANNEL |
73 | GetCtrlVal(pa,PA_CHANNEL, &ch); |
76 | iRet = TMI_TimeOut(TMI_DeviceId, 1); |
74 | iRet = TMI_TimeOut(TMI_DeviceId, 1); |
77 | iRet = TMI_Refresh(TMI_DeviceId); |
75 | iRet = TMI_Refresh(TMI_DeviceId); |
78 | 76 | ||
79 | 77 | ||
80 | iRet = TMI_MoniDataQ(TMI_DeviceId, ch+1, &Voltage, &Current, &cv_cc); |
78 | iRet = TMI_MoniDataQ(TMI_DeviceId, ch+1, &Voltage, &Current, &cv_cc); |
81 | 79 | ||
82 | SetCtrlVal(panel, PA_VMON, Voltage); |
80 | SetCtrlVal(panel, PA_VMON, Voltage); |
83 | SetCtrlVal(panel, PA_IMON, Current); |
81 | SetCtrlVal(panel, PA_IMON, Current); |
84 | SetCtrlVal(panel, PA_CVCC, cv_cc); |
82 | SetCtrlVal(panel, PA_CVCC, cv_cc); |
85 | 83 | ||
86 | break; |
84 | break; |
87 | } |
85 | } |
88 | return 0; |
86 | return 0; |
89 | } |
87 | } |
90 | 88 | ||
91 | 89 | ||
92 | int CVICALLBACK SelectChannelCB (int panel, int control, int event, |
90 | int CVICALLBACK SelectChannelCB (int panel, int control, int event, |
93 | void |
91 | void *callbackData, int eventData1, int eventData2) { |
94 | { |
- | |
95 | unsigned char state, preset; |
92 | unsigned char state, preset; |
96 | double Voltage, Current; |
93 | double Voltage, Current; |
97 | unsigned |
94 | unsigned char ch; |
98 | switch |
95 | switch (event) { |
99 | { |
- | |
100 | case EVENT_COMMIT: |
96 | case EVENT_COMMIT: |
101 | GetCtrlVal( |
97 | GetCtrlVal(pa,PA_CHANNEL, &ch); |
102 | GetCtrlVal(pa,PA_PRESET, &preset); |
98 | GetCtrlVal(pa,PA_PRESET, &preset); |
103 | - | ||
104 | - | ||
105 | - | ||
106 | TMI_VoltageQ(TMI_DeviceId, ch+1, preset, &Voltage); |
- | |
107 | TMI_CurrentQ(TMI_DeviceId, ch+1, preset, &Current); |
- | |
108 | SetCtrlVal(pa, PA_VSET, Voltage); |
- | |
109 | SetCtrlVal(pa, PA_ISET, Current); |
- | |
110 | - | ||
111 | break; |
- | |
112 | } |
- | |
113 | return 0; |
- | |
114 | } |
- | |
115 | 99 | ||
- | 100 | ||
- | 101 | ||
- | 102 | TMI_VoltageQ(TMI_DeviceId, ch+1, preset, &Voltage); |
|
- | 103 | TMI_CurrentQ(TMI_DeviceId, ch+1, preset, &Current); |
|
- | 104 | SetCtrlVal(pa, PA_VSET, Voltage); |
|
- | 105 | SetCtrlVal(pa, PA_ISET, Current); |
|
- | 106 | ||
- | 107 | break; |
|
- | 108 | } |
|
- | 109 | return 0; |
|
- | 110 | } |
|
- | 111 | ||
- | 112 | ||
- | 113 | #define tcpChk(f) if ((g_TCPError=(f)) < 0) {ReportTCPError(); return -1; } |
|
- | 114 | ||
- | 115 | /*---------------------------------------------------------------------------*/ |
|
- | 116 | /* Module-globals */ |
|
- | 117 | /*---------------------------------------------------------------------------*/ |
|
- | 118 | static unsigned int g_hconversation; |
|
- | 119 | static int g_TCPError = 0; |
|
- | 120 | ||
- | 121 | /*---------------------------------------------------------------------------*/ |
|
- | 122 | /* Internal function prototypes */ |
|
- | 123 | /*---------------------------------------------------------------------------*/ |
|
- | 124 | /*---------------------------------------------------------------------------*/ |
|
- | 125 | /* Report TCP Errors if any */ |
|
- | 126 | /*---------------------------------------------------------------------------*/ |
|
- | 127 | static void ReportTCPError (void) { |
|
- | 128 | if (g_TCPError < 0) { |
|
- | 129 | char messageBuffer[1024]; |
|
- | 130 | sprintf(messageBuffer, |
|
- | 131 | "TCP library error message: %s\nSystem error message: %s", |
|
- | 132 | GetTCPErrorString (g_TCPError), GetTCPSystemErrorString()); |
|
- | 133 | MessagePopup ("Error", messageBuffer); |
|
- | 134 | } |
|
- | 135 | } |
|
- | 136 | ||
- | 137 | ||
- | 138 | int CVICALLBACK ServerTCPCB (unsigned handle, int event, int error, |
|
- | 139 | void *callbackData) { |
|
- | 140 | char receiveBuf[256] = {0}; |
|
- | 141 | ssize_t dataSize = sizeof (receiveBuf) - 1; |
|
- | 142 | char addrBuf[31]; |
|
- | 143 | ||
- | 144 | switch (event) { |
|
- | 145 | case TCP_CONNECT: |
|
- | 146 | if (g_hconversation) { |
|
- | 147 | /* We already have one client, don't accept another... */ |
|
- | 148 | tcpChk (GetTCPPeerAddr (handle, addrBuf, 31)); |
|
- | 149 | sprintf (receiveBuf, "-- Refusing conection request from " |
|
- | 150 | "%s --\n", addrBuf); |
|
- | 151 | printf("%s\n", receiveBuf); |
|
- | 152 | tcpChk (DisconnectTCPClient (handle)); |
|
- | 153 | } else { |
|
- | 154 | /* Handle this new client connection */ |
|
- | 155 | g_hconversation = handle; |
|
- | 156 | tcpChk (GetTCPPeerAddr (g_hconversation, addrBuf, 31)); |
|
- | 157 | printf("%s\n", addrBuf); |
|
- | 158 | tcpChk (GetTCPPeerName (g_hconversation, receiveBuf, 256)); |
|
- | 159 | printf("%s\n", receiveBuf); |
|
- | 160 | sprintf (receiveBuf, "-- New connection from %s --\n", |
|
- | 161 | addrBuf); |
|
- | 162 | printf("%s\n", receiveBuf); |
|
- | 163 | ||
- | 164 | /* Set the disconect mode so we do not need to terminate */ |
|
- | 165 | /* connections ourselves. */ |
|
- | 166 | tcpChk (SetTCPDisconnectMode (g_hconversation, TCP_DISCONNECT_AUTO)); |
|
- | 167 | } |
|
- | 168 | break; |
|
- | 169 | case TCP_DATAREADY: |
|
- | 170 | if ((dataSize = ServerTCPRead (g_hconversation, receiveBuf, dataSize, 1000)) < 0) { |
|
- | 171 | printf("Receive Error\n"); |
|
- | 172 | } else { |
|
- | 173 | receiveBuf[dataSize] = '\0'; |
|
- | 174 | printf("Received %s\n", receiveBuf); |
|
- | 175 | } |
|
- | 176 | break; |
|
- | 177 | case TCP_DISCONNECT: |
|
- | 178 | if (handle == g_hconversation) { |
|
- | 179 | /* The client we were talking to has disconnected... */ |
|
- | 180 | g_hconversation = 0; |
|
- | 181 | printf("-- Client disconnected --\n"); |
|
- | 182 | ||
- | 183 | /* Note that we do not need to do any more because we set the*/ |
|
- | 184 | /* disconnect mode to AUTO. */ |
|
- | 185 | } |
|
- | 186 | break; |
|
- | 187 | } |
|
- | 188 | return 0; |
|
- | 189 | } |
|
116 | 190 | ||
117 | 191 | ||
118 | 192 | ||
- | 193 | ||
- | 194 | ||
119 | int main (int argc, char *argv[]) |
195 | int main (int argc, char *argv[]) { |
120 | { |
- | |
121 | int DeviceId=0; |
196 | int DeviceId=0; |
122 | unsigned char ch; |
197 | unsigned char ch; |
123 | unsigned char MainOutput, preset; |
198 | unsigned char MainOutput, preset; |
124 | double Voltage, Current, tinterval; |
199 | double Voltage, Current, tinterval; |
125 | char str[0xFF]; |
200 | char str[0xFF]; |
126 | if (InitCVIRTE (0, argv, 0) == 0) |
201 | if (InitCVIRTE (0, argv, 0) == 0) |
127 | return -1; /* out of memory */ |
202 | return -1; /* out of memory */ |
128 | SetStdioPort (CVI_STDIO_WINDOW); |
203 | SetStdioPort (CVI_STDIO_WINDOW); |
129 | pid.iGain= 0. |
204 | pid.iGain= 0.1; |
130 | pid.dGain= |
205 | pid.dGain= 2; |
131 | pid.pGain = |
206 | pid.pGain = 5; |
132 | pid.iMax =100; |
207 | pid.iMax =100; |
133 | pid.iMin =-100 ; |
208 | pid.iMin =-100 ; |
134 | pid.iState=0; |
209 | pid.iState=0; |
135 | pid.dState=0; |
210 | pid.dState=0; |
136 | 211 | ||
137 | if ((pa = LoadPanel (0, "TempCtrl.uir", PA)) < 0) |
212 | if ((pa = LoadPanel (0, "TempCtrl.uir", PA)) < 0) |
138 | return -1; |
213 | return -1; |
139 | - | ||
- | 214 | DisableBreakOnLibraryErrors(); |
|
140 | if |
215 | if (TMI_Open()== 0) MessagePopup("Error","Cannot open USB device"); |
141 | DeviceId = TMI_OpenHandle ("PW-A","USB:1:1"); |
216 | DeviceId = TMI_OpenHandle ("PW-A","USB:1:1"); |
142 | if (TMI_Test() == 0 )MessagePopup("DLL error","Dll Error"); |
217 | if (TMI_Test() == 0 )MessagePopup("DLL error","Dll Error"); |
143 | if (DeviceId < 0) MessagePopup("Error","Not Connected"); |
218 | if (DeviceId < 0) MessagePopup("Error","Not Connected"); |
144 | printf("TMI device ID %d\n",TMI_DeviceId); |
219 | printf("TMI device ID %d\n",TMI_DeviceId); |
145 | 220 | ||
146 | TMI_MainOutputQ(TMI_DeviceId, &MainOutput); |
221 | TMI_MainOutputQ(TMI_DeviceId, &MainOutput); |
147 | TMI_PresetQ(TMI_DeviceId, &preset); |
222 | TMI_PresetQ(TMI_DeviceId, &preset); |
148 | SetCtrlVal(pa, PA_ONOFF, MainOutput); |
223 | SetCtrlVal(pa, PA_ONOFF, MainOutput); |
149 | SetCtrlVal(pa, PA_PRESET, preset); |
224 | SetCtrlVal(pa, PA_PRESET, preset); |
150 | /* |
225 | /* |
151 | GetCtrlVal(pa, P1_TINTERVAL, &tinterval); |
226 | GetCtrlVal(pa, P1_TINTERVAL, &tinterval); |
152 | SetCtrlAttribute (pa, P1_TIMER, ATTR_INTERVAL, tinterval); |
227 | SetCtrlAttribute (pa, P1_TIMER, ATTR_INTERVAL, tinterval); |
153 | */ |
228 | */ |
- | 229 | ||
- | 230 | SetWaitCursor (1); |
|
- | 231 | int portNum = 10000; |
|
- | 232 | int registered = 0; |
|
- | 233 | char tempBuf[256] = {0}; |
|
- | 234 | if (RegisterTCPServer (portNum, ServerTCPCB, 0) < 0) |
|
- | 235 | MessagePopup("TCP Server", "Server registration failed!"); |
|
- | 236 | else { |
|
- | 237 | SetWaitCursor (0); |
|
- | 238 | registered = 1; |
|
- | 239 | ||
- | 240 | /* We are successfully connected -- gather info */ |
|
- | 241 | ||
- | 242 | if (GetTCPHostAddr (tempBuf, 256) >= 0) printf("%s\n" ,tempBuf); |
|
- | 243 | if (GetTCPHostName (tempBuf, 256) >= 0) printf("%s\n" ,tempBuf); |
|
- | 244 | ||
- | 245 | ||
- | 246 | ||
- | 247 | } |
|
- | 248 | ||
154 | SelectChannelCB (pa, PA_CHANNEL, EVENT_COMMIT, NULL, 0,0); |
249 | SelectChannelCB (pa, PA_CHANNEL, EVENT_COMMIT, NULL, 0,0); |
155 | ReadVoltageCurrentCB (pa, PA_CHANNEL, EVENT_COMMIT, NULL, 0,0); |
250 | ReadVoltageCurrentCB (pa, PA_CHANNEL, EVENT_COMMIT, NULL, 0,0); |
156 | 251 | ||
157 | 252 | ||
158 | 253 | ||
159 | DisplayPanel (pa); |
254 | DisplayPanel (pa); |
160 | SetDimming(0); |
255 | SetDimming(0); |
161 | RunUserInterface (); |
256 | RunUserInterface (); |
162 | CloseCom(COM_PORT); |
257 | CloseCom(COM_PORT); |
- | 258 | if (registered) |
|
- | 259 | UnregisterTCPServer (portNum); |
|
163 | DiscardPanel (pa); |
260 | DiscardPanel (pa); |
164 |
|
261 | TMI_Close(); |
165 | if (gFp) fclose(gFp); |
262 | if (gFp) fclose(gFp); |
166 | return 0; |
263 | return 0; |
167 | } |
264 | } |
168 | 265 | ||
169 | 266 | ||
170 | int CVICALLBACK ExitCB (int panel, int control, int event, |
267 | int CVICALLBACK ExitCB (int panel, int control, int event, |
171 | void *callbackData, int eventData1, int eventData2) { |
268 | void *callbackData, int eventData1, int eventData2) { |
172 | switch (event) { |
269 | switch (event) { |
173 | case EVENT_COMMIT: |
270 | case EVENT_COMMIT: |
174 | QuitUserInterface (0); |
271 | QuitUserInterface (0); |
175 | break; |
272 | break; |
176 | } |
273 | } |
177 | return 0; |
274 | return 0; |
178 | } |
275 | } |
179 | 276 | ||
180 | 277 | ||
181 | 278 | ||
182 | int CVICALLBACK SwitchOnOffCB (int panel, int control, int event, |
279 | int CVICALLBACK SwitchOnOffCB (int panel, int control, int event, |
183 | void |
280 | void *callbackData, int eventData1, int eventData2) { |
184 | { |
- | |
185 | unsigned char state; |
281 | unsigned char state; |
186 | switch |
282 | switch (event) { |
187 | { |
- | |
188 | case EVENT_COMMIT: |
283 | case EVENT_COMMIT: |
189 | GetCtrlVal(panel, control, &state); |
284 | GetCtrlVal(panel, control, &state); |
190 | TMI_MainOutput(TMI_DeviceId, state); |
285 | TMI_MainOutput(TMI_DeviceId, state); |
191 | break; |
286 | break; |
192 | } |
287 | } |
193 | return 0; |
288 | return 0; |
194 | } |
289 | } |
195 | 290 | ||
196 | 291 | ||
197 | 292 | ||
198 | /* Callback Function */ |
293 | /* Callback Function */ |
199 | void ComCallback(int portNumber, int eventMask, void *callbackdata) { |
294 | void ComCallback(int portNumber, int eventMask, void *callbackdata) { |
200 | 295 | static double told=0; |
|
201 | if (eventMask & LWRS_RXFLAG) { |
296 | if (eventMask & LWRS_RXFLAG) { |
202 | //printf("Received specified character\n"); |
297 | //printf("Received specified character\n"); |
203 | int strLen = GetInQLen (COM_PORT); |
298 | int strLen = GetInQLen (COM_PORT); |
204 | bytes_read = ComRd (COM_PORT, read_data, strLen); |
299 | bytes_read = ComRd (COM_PORT, read_data, strLen); |
205 | double temp= atof(read_data); |
300 | double temp= atof(read_data); |
Line 207... | Line 302... | ||
207 | int debug1; |
302 | int debug1; |
208 | GetCtrlVal(pa,PA_DEBUG_1, &debug1); |
303 | GetCtrlVal(pa,PA_DEBUG_1, &debug1); |
209 | //printf("%f#%s#", temp, read_data); |
304 | //printf("%f#%s#", temp, read_data); |
210 | sscanf(read_data,"%lf %lf %lf %lf %lf %lf",&f[0],&f[1],&f[2],&f[3],&f[4],&f[5]); |
305 | sscanf(read_data,"%lf %lf %lf %lf %lf %lf",&f[0],&f[1],&f[2],&f[3],&f[4],&f[5]); |
211 | double humidity = f[5]; |
306 | double humidity = f[5]; |
212 | // printf("%lf %lf %lf %lf %lf %lf",f[0],f[1],f[2],f[3],f[4],f[5]); |
307 | // printf("%lf %lf %lf %lf %lf %lf",f[0],f[1],f[2],f[3],f[4],f[5]); |
213 | int RS232Error = ReturnRS232Err (); |
308 | int RS232Error = ReturnRS232Err (); |
214 | if (ReturnRS232Err ()) { |
309 | if (ReturnRS232Err ()) { |
215 | sprintf(read_data,"#%s\n", GetRS232ErrorString(RS232Error)); |
310 | sprintf(read_data,"#%s\n", GetRS232ErrorString(RS232Error)); |
216 | MessagePopup("RS232Err",read_data); |
311 | MessagePopup("RS232Err",read_data); |
217 | } else { |
312 | } else { |
218 | 313 | ||
219 | 314 | ||
220 | int polar; |
315 | int polar; |
221 | SelectChannelCB (pa, PA_CHANNEL, EVENT_COMMIT, NULL, 0,0); |
316 | SelectChannelCB (pa, PA_CHANNEL, EVENT_COMMIT, NULL, 0,0); |
222 | ReadVoltageCurrentCB (pa, PA_CHANNEL, EVENT_COMMIT, NULL, 0,0); |
317 | ReadVoltageCurrentCB (pa, PA_CHANNEL, EVENT_COMMIT, NULL, 0,0); |
223 | double tset,vmon,imon,vset,iset,vmax; |
318 | double tset,vmon,imon,vset,iset,vmax; |
224 | unsigned char ch, preset; |
319 | unsigned char ch, preset; |
225 | GetCtrlVal(pa,PA_TSET,&tset); |
320 | GetCtrlVal(pa,PA_TSET,&tset); |
226 | GetCtrlVal(pa,PA_VMON,&vmon); |
321 | GetCtrlVal(pa,PA_VMON,&vmon); |
227 | GetCtrlVal(pa,PA_IMON,&imon); |
322 | GetCtrlVal(pa,PA_IMON,&imon); |
228 | GetCtrlVal(pa,PA_CHANNEL, &ch); |
323 | GetCtrlVal(pa,PA_CHANNEL, &ch); |
229 | GetCtrlVal(pa,PA_PRESET,&preset); |
324 | GetCtrlVal(pa,PA_PRESET,&preset); |
230 | TMI_Preset(TMI_DeviceId,preset); |
325 | TMI_Preset(TMI_DeviceId,preset); |
231 | GetCtrlVal(pa,PA_POLAR,&polar); |
326 | GetCtrlVal(pa,PA_POLAR,&polar); |
232 | 327 | ||
233 | double tdiff = temp - tset; |
328 | double tdiff = temp - tset; |
234 | double retpid = UpdatePID(&pid, tdiff, temp); |
329 | double retpid = UpdatePID(&pid, tdiff, temp); |
235 | const double troom = 20; |
330 | const double troom = 20; |
236 | double Pheat= 0.2 * (temp - troom); |
331 | double Pheat= 0.2 * (temp - troom); |
237 | double Ptec = retpid - Pheat*2; |
332 | double Ptec = retpid - Pheat*2; |
238 | vset = (polar*Ptec>0) ? sqrt(fabs(Ptec)) : 0; |
333 | vset = (polar*Ptec>0) ? sqrt(fabs(Ptec)) : 0; |
239 | 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); |
334 | 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); |
240 | GetCtrlVal(pa,PA_VMAX,&vmax); |
335 | GetCtrlVal(pa,PA_VMAX,&vmax); |
241 | if (vset >vmax) vset=vmax; |
336 | if (vset >vmax) vset=vmax; |
242 | if (vset <0) vset =0; |
337 | if (vset <0) vset =0; |
243 | if (debug1) printf("vset --->%f \n",vset); |
338 | if (debug1) printf("vset --->%f \n",vset); |
244 | TMI_Voltage(TMI_DeviceId, ch+1, preset, vset); |
339 | TMI_Voltage(TMI_DeviceId, ch+1, preset, vset); |
245 | GetCtrlVal(pa,PA_IMAX,&iset); |
340 | GetCtrlVal(pa,PA_IMAX,&iset); |
246 | TMI_Current(TMI_DeviceId, ch+1, preset, iset); |
341 | TMI_Current(TMI_DeviceId, ch+1, preset, iset); |
247 | 342 | ||
248 | 343 | ||
249 | 344 | ||
250 | 345 | ||
251 | 346 | ||
252 | ReadVoltageCurrentCB (pa, PA_CHANNEL, EVENT_COMMIT, NULL, 0,0); |
347 | ReadVoltageCurrentCB (pa, PA_CHANNEL, EVENT_COMMIT, NULL, 0,0); |
253 | 348 | ||
254 | PlotStripChart (pa, PA_GRAPH, &temp, 1, 0, 0, VAL_DOUBLE); |
349 | PlotStripChart (pa, PA_GRAPH, &temp, 1, 0, 0, VAL_DOUBLE); |
255 | double pgraph[ |
350 | double pgraph[3]= {vmon,imon, 100*(temp-told)}; |
256 | PlotStripChart (pa, PA_GRAPH_VMON, pgraph, |
351 | PlotStripChart (pa, PA_GRAPH_VMON, pgraph, 3, 0, 0, VAL_DOUBLE); |
257 | PlotStripChart (pa, PA_GRAPH_3, &humidity, 1, 0, 0, VAL_DOUBLE); |
352 | PlotStripChart (pa, PA_GRAPH_3, &humidity, 1, 0, 0, VAL_DOUBLE); |
258 | SetCtrlVal(pa,PA_TMON,temp); |
353 | SetCtrlVal(pa,PA_TMON,temp); |
- | 354 | ||
- | 355 | SetCtrlVal(pa,PA_HUMIDITY,humidity); |
|
- | 356 | ||
- | 357 | char transmitBuf[512]= {0}; |
|
- | 358 | sprintf(transmitBuf, "%u %f %f %f %f\n", time(NULL), humidity, temp, tdiff, temp-told); |
|
- | 359 | if (g_hconversation) |
|
- | 360 | if ( ServerTCPWrite (g_hconversation, transmitBuf, strlen (transmitBuf), 1000) < 0) printf("Transmit Error\n"); |
|
259 | int log=0; |
361 | int log=0; |
260 | GetCtrlVal(pa,PA_LOG, &log); |
362 | GetCtrlVal(pa,PA_LOG, &log); |
261 | if (log) { |
363 | if (log) { |
262 | char fname[0xFF]; |
364 | char fname[0xFF]; |
263 | GetCtrlVal(pa,PA_FNAME, fname); |
365 | GetCtrlVal(pa,PA_FNAME, fname); |
264 | FILE *fp = fopen (fname,"a"); |
366 | FILE *fp = fopen (fname,"a"); |
265 | fprintf(fp, |
367 | fprintf(fp,transmitBuf); |
266 | fclose(fp); |
368 | fclose(fp); |
267 | 369 | ||
268 | } |
370 | } |
- | 371 | told= temp; |
|
269 | 372 | ||
270 | } |
373 | } |
271 | } |
374 | } |
272 | 375 | ||
273 | if (eventMask & LWRS_TXEMPTY) |
376 | if (eventMask & LWRS_TXEMPTY) |
274 | 377 | ||
Line 320... | Line 423... | ||
320 | 423 | ||
321 | int CVICALLBACK SetPresetCB (int panel, int control, int event, |
424 | int CVICALLBACK SetPresetCB (int panel, int control, int event, |
322 | void *callbackData, int eventData1, int eventData2) { |
425 | void *callbackData, int eventData1, int eventData2) { |
323 | 426 | ||
324 | switch (event) { |
427 | switch (event) { |
325 | case EVENT_COMMIT:{ |
428 | case EVENT_COMMIT: { |
326 | unsigned char preset; |
429 | unsigned char preset; |
327 | double Voltage, Current; |
430 | double Voltage, Current; |
328 | GetCtrlVal(panel, control, &preset); |
431 | GetCtrlVal(panel, control, &preset); |
329 | TMI_Preset(TMI_DeviceId, preset); |
432 | TMI_Preset(TMI_DeviceId, preset); |
330 | 433 | ||
331 | break; |
434 | break; |
332 | } |
435 | } |
333 | } |
436 | } |
334 | return 0; |
437 | return 0; |
335 | } |
438 | } |
- | 439 |