Rev 165 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
159 | f9daq | 1 | #include "MPOD.h" |
163 | f9daq | 2 | #include <utility.h> |
159 | f9daq | 3 | #include "HVtest_ui.h" |
4 | |||
161 | f9daq | 5 | #define HVSLOT 3 |
165 | f9daq | 6 | #define NTICSMAX 240 |
161 | f9daq | 7 | |
164 | f9daq | 8 | static int p1h, pID, rID; //, tfID; |
159 | f9daq | 9 | |
10 | int CVICALLBACK refreshTimer (int panel, int control, int event, void *callbackData, |
||
11 | int eventData1, int eventData2) { |
||
12 | QueueUserEvent (9000, p1h, P1_REFRESHTIMER); |
||
13 | return (0); |
||
14 | } |
||
15 | |||
16 | int __stdcall WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, |
||
17 | LPSTR lpszCmdLine, int nCmdShow) { |
||
18 | |||
163 | f9daq | 19 | const int mo=HVSLOT; |
162 | f9daq | 20 | const int ch0=100*mo; |
21 | |||
22 | int mainonoff,HVonoffall; |
||
164 | f9daq | 23 | int HVonoff[4]={0,0,0,0}; |
24 | int HVonoff_rID[4]={P1_HVonoff_1,P1_HVonoff_2,P1_HVonoff_3,P1_HVonoff_4}; |
||
25 | int HVvdis_rID[4]={P1_HVvdis_1,P1_HVvdis_2,P1_HVvdis_3,P1_HVvdis_4}; |
||
26 | int HVcdis_rID[4]={P1_HVcdis_1,P1_HVcdis_2,P1_HVcdis_3,P1_HVcdis_4}; |
||
159 | f9daq | 27 | int iret; |
164 | f9daq | 28 | int i; |
29 | int TESTon=0,ntics=0; |
||
30 | double HVvset[4],HVcset[4],HVvrise; //,HVvfall; |
||
162 | f9daq | 31 | double HVvdis[4],HVcdis[4]; |
164 | f9daq | 32 | // char cret[2000]; |
159 | f9daq | 33 | char cMainSwitch[2][30]= {"Turn system OFF?","Turn system ON?"}; |
164 | f9daq | 34 | char HVBid[4][4]; |
35 | int HVBid_rID[4]={P1_HVBid_1,P1_HVBid_2,P1_HVBid_3,P1_HVBid_4}; |
||
36 | char HVBfname[4][200]; |
||
37 | FILE *HVBfp[4]={NULL,NULL,NULL,NULL}; |
||
165 | f9daq | 38 | FILE *LIDfp=NULL; |
39 | |||
159 | f9daq | 40 | HSNMP crate1; |
41 | |||
42 | if (InitCVIRTE (hInstance, 0, 0) == 0) |
||
43 | return -1; /* out of memory */ |
||
44 | |||
45 | MPOD_Start(); |
||
162 | f9daq | 46 | // MPOD_Open(0,"f9mpod.ijs.si"); |
161 | f9daq | 47 | MPOD_Open(0,"arich-mpod1.kek.jp"); |
159 | f9daq | 48 | crate1 = crateHsnmp[0]; |
49 | |||
162 | f9daq | 50 | // iret=MPOD_GetInt(0,"moduleNumber.0"); |
51 | // printf("Module Number = %i\n", iret); |
||
52 | // strcpy(cret, MPOD_GetString(0,"moduleDescription.ma2")); |
||
53 | // printf("Module type: %s\n",cret); |
||
54 | // iret=MPOD_GetIntCh(0,"fanNominalSpeed",0); |
||
55 | // printf("Fan nominal speed = %i\n", iret); |
||
159 | f9daq | 56 | |
57 | if ((p1h = LoadPanel (0, "HVtest_ui.uir", P1)) < 0) return -1; |
||
58 | DisplayPanel (p1h); |
||
164 | f9daq | 59 | SetCtrlVal (p1h, P1_TESTon, 0); |
165 | f9daq | 60 | LIDfp=fopen("lastids.txt","r"); |
61 | for (i=0;i<4;i++) { |
||
62 | fscanf(LIDfp,"%s",HVBid[i]); |
||
63 | SetCtrlVal(p1h,HVBid_rID[i],HVBid[i]); |
||
64 | } |
||
65 | fclose(LIDfp); |
||
66 | LIDfp=NULL; |
||
164 | f9daq | 67 | |
159 | f9daq | 68 | //Initial state |
69 | mainonoff=getMainSwitch(crate1); |
||
70 | SetCtrlVal (p1h, P1_MSW, mainonoff); |
||
71 | SetCtrlVal (p1h, P1_MSWLED, mainonoff); |
||
72 | iret=getMainStatus(crate1); |
||
73 | SetCtrlVal (p1h, P1_MST, iret); |
||
74 | iret=getFanNominalSpeed(crate1); |
||
75 | SetCtrlVal (p1h, P1_MFS, iret); |
||
76 | if (mainonoff) { |
||
162 | f9daq | 77 | HVonoffall=0; |
78 | for (i=0;i<4;i++) { |
||
79 | HVonoff[i]=getChannelSwitch(crate1, ch0+i); |
||
80 | if (HVonoff[i]) HVonoffall=1; |
||
81 | } |
||
82 | for (i=0;i<4;i++) { |
||
83 | if (!HVonoffall) HVonoff[i]=1; |
||
163 | f9daq | 84 | SetCtrlVal (p1h, HVonoff_rID[i], HVonoff[i]); |
162 | f9daq | 85 | } |
86 | HVvset[0]=getOutputVoltage(crate1,ch0); |
||
87 | SetCtrlVal (p1h, P1_HVvset, HVvset[0]); |
||
88 | HVcset[0]=1e+6*getOutputCurrent(crate1,ch0); |
||
89 | SetCtrlVal (p1h, P1_HVcset, HVcset[0]); |
||
163 | f9daq | 90 | SetAxisScalingMode (p1h, P1_G1, VAL_LEFT_YAXIS, VAL_MANUAL, -(HVcset[0]+1), 1.); |
162 | f9daq | 91 | HVvrise=getModuleRampSpeedVoltage(crate1,mo); |
92 | SetCtrlVal (p1h, P1_HVvrise, HVvrise); |
||
159 | f9daq | 93 | // vfall[0]=abs(getOutputFallRate(crate1,ch)); |
94 | // SetCtrlVal (p1h, P1_VFA0, vfall[0]); |
||
95 | } |
||
96 | // QueueUserEvent (1000, p1h, P1_RESET); |
||
97 | QueueUserEvent (9000, p1h, P1_REFRESHTIMER); |
||
98 | |||
99 | do { |
||
100 | GetUserEvent (1, &pID, &rID); |
||
101 | switch (rID) { |
||
102 | case P1_REFRESHTIMER: |
||
103 | mainonoff=getMainSwitch(crate1); |
||
104 | SetCtrlVal (p1h, P1_MSW, mainonoff); |
||
105 | SetCtrlVal (p1h, P1_MSWLED, mainonoff); |
||
164 | f9daq | 106 | if (mainonoff) { |
107 | iret=getMainStatus(crate1); |
||
108 | SetCtrlVal (p1h, P1_MST, iret); |
||
159 | f9daq | 109 | // ret=getOutputSenseMeasurement(crate1, ch); |
164 | f9daq | 110 | for (i=0; i<4; i++) { |
111 | HVvdis[i]=getOutputTerminalMeasurement(crate1, ch0+i); |
||
112 | SetCtrlVal (p1h, HVvdis_rID[i], HVvdis[i]); |
||
113 | HVcdis[i]=1e+6*getCurrentMeasurement(crate1, ch0+i); |
||
114 | SetCtrlVal (p1h, HVcdis_rID[i], HVcdis[i]); |
||
115 | } |
||
116 | PlotStripChart (p1h, P1_G1, HVcdis, 4, 0, 0, VAL_DOUBLE); |
||
117 | if (TESTon) { |
||
118 | ntics++; |
||
119 | for (i=0;i<4;i++) |
||
120 | fprintf(HVBfp[i],"%5d %10.1f %10.4f\n",ntics,HVvdis[i],HVcdis[i]); |
||
121 | switch (ntics) { |
||
122 | case 5: |
||
123 | SetCtrlVal(p1h,P1_HVonoffall, 1); |
||
124 | QueueUserEvent (1001, p1h, P1_HVonoffall); |
||
125 | break; |
||
126 | case NTICSMAX-25: |
||
127 | SetCtrlVal(p1h,P1_HVonoffall, 0); |
||
128 | QueueUserEvent (1001, p1h, P1_HVonoffall); |
||
129 | break; |
||
130 | case NTICSMAX: |
||
131 | SetCtrlVal (p1h, P1_TESTon, 0); |
||
132 | QueueUserEvent (1001, p1h, P1_TESTon); |
||
133 | break; |
||
134 | default: |
||
135 | break; |
||
136 | } |
||
137 | } |
||
163 | f9daq | 138 | } |
159 | f9daq | 139 | break; |
140 | case P1_MSW: |
||
141 | GetCtrlVal (p1h, P1_MSW, &mainonoff); |
||
142 | if (ConfirmPopup("Main switch!!!", cMainSwitch[mainonoff])) |
||
143 | setMainSwitch(crate1, mainonoff); |
||
162 | f9daq | 144 | if (mainonoff) { |
145 | Delay(5); |
||
146 | HVonoffall=0; |
||
147 | for (i=0; i<4; i++) { |
||
148 | HVonoff[i]=getChannelSwitch(crate1, ch0+i); |
||
149 | if (HVonoff[i]) HVonoffall=1; |
||
150 | } |
||
151 | for (i=0; i<4; i++) { |
||
152 | if (!HVonoffall) HVonoff[i]=1; |
||
153 | SetCtrlVal (p1h, HVonoff_rID[i], HVonoff[i]); |
||
154 | } |
||
155 | HVvset[0]=getOutputVoltage(crate1,ch0); |
||
156 | SetCtrlVal (p1h, P1_HVvset, HVvset[0]); |
||
157 | HVcset[0]=1e+6*getOutputCurrent(crate1,ch0); |
||
158 | SetCtrlVal (p1h, P1_HVcset, HVcset[0]); |
||
163 | f9daq | 159 | SetAxisScalingMode (p1h, P1_G1, VAL_LEFT_YAXIS, VAL_MANUAL, -(HVcset[0]+1), 1.); |
162 | f9daq | 160 | HVvrise=getModuleRampSpeedVoltage(crate1,mo); |
161 | SetCtrlVal (p1h, P1_HVvrise, HVvrise); |
||
162 | } |
||
159 | f9daq | 163 | break; |
165 | f9daq | 164 | case P1_HVBidinc: |
165 | if (!TESTon) { |
||
166 | for (i=0;i<4;i++) { |
||
167 | GetCtrlVal(p1h, HVBid_rID[i], HVBid[i]); |
||
168 | sscanf(HVBid[i],"%d",&iret); |
||
169 | iret+=4; |
||
170 | sprintf(HVBid[i],"%3.3d",iret); |
||
171 | SetCtrlVal(p1h, HVBid_rID[i], HVBid[i]); |
||
172 | } |
||
173 | } |
||
174 | break; |
||
163 | f9daq | 175 | } |
159 | f9daq | 176 | if (!mainonoff) continue; |
177 | switch (rID) { |
||
163 | f9daq | 178 | case P1_HVonoffall: |
179 | GetCtrlVal (p1h, P1_HVonoffall, &HVonoffall); |
||
180 | for (i=0;i<4;i++) { |
||
181 | GetCtrlVal (p1h, HVonoff_rID[i], &HVonoff[i]); |
||
182 | if (HVonoff[i]) |
||
183 | setChannelSwitch(crate1, ch0+i, HVonoffall); |
||
184 | } |
||
159 | f9daq | 185 | break; |
163 | f9daq | 186 | case P1_HVvset: |
187 | GetCtrlVal (p1h, P1_HVvset, &HVvset[0]); |
||
188 | for (i=0;i<4;i++) |
||
189 | setOutputVoltage(crate1, ch0+i, HVvset[0]); |
||
159 | f9daq | 190 | break; |
163 | f9daq | 191 | case P1_HVcset: |
192 | GetCtrlVal (p1h, P1_HVcset, &HVcset[0]); |
||
193 | SetAxisScalingMode (p1h, P1_G1, VAL_LEFT_YAXIS, VAL_MANUAL, -(HVcset[0]+1), 1.); |
||
194 | HVcset[0]/=1e+6; //[uA] |
||
195 | for (i=0;i<4;i++) |
||
196 | setOutputCurrent(crate1, ch0+i, HVcset[0]); |
||
159 | f9daq | 197 | break; |
163 | f9daq | 198 | case P1_HVvrise: |
199 | GetCtrlVal (p1h, P1_HVvrise, &HVvrise); |
||
200 | setModuleRampSpeedVoltage(crate1, mo, HVvrise); |
||
201 | HVvrise=getModuleRampSpeedVoltage(crate1,mo); |
||
202 | SetCtrlVal (p1h, P1_HVvrise, HVvrise); |
||
159 | f9daq | 203 | break; |
164 | f9daq | 204 | case P1_TESTon: |
205 | GetCtrlVal (p1h, P1_TESTon, &TESTon); |
||
206 | if (TESTon) { |
||
207 | ntics=0; |
||
208 | ClearStripChart (p1h, P1_G1); |
||
165 | f9daq | 209 | LIDfp=fopen("lastids.txt","w"); |
164 | f9daq | 210 | for (i=0;i<4;i++) { |
211 | GetCtrlVal(p1h, HVBid_rID[i], HVBid[i]); |
||
165 | f9daq | 212 | sprintf(HVBfname[i],"data/HVB_%s.dat",HVBid[i]); |
213 | fprintf(LIDfp,"%s\n",HVBid[i]); |
||
164 | f9daq | 214 | HVBfp[i]=fopen(HVBfname[i],"w"); |
215 | } |
||
165 | f9daq | 216 | fclose(LIDfp); |
217 | LIDfp=NULL; |
||
164 | f9daq | 218 | } else { |
219 | SetCtrlVal(p1h,P1_HVonoffall, 0); |
||
220 | QueueUserEvent (1001, p1h, P1_HVonoffall); |
||
165 | f9daq | 221 | for (i=0;i<4;i++) { |
164 | f9daq | 222 | fclose(HVBfp[i]); |
165 | f9daq | 223 | HVBfp[i]=NULL; |
224 | } |
||
166 | f9daq | 225 | QueueUserEvent(1002,p1h,P1_HVBidinc); |
164 | f9daq | 226 | } |
227 | break; |
||
159 | f9daq | 228 | // case P1_VFA0: |
229 | // GetCtrlVal (p1h, P1_VFA0, &ret); |
||
230 | // setOutputFallRate(crate1, ch, ret); |
||
231 | // vfall[0]=abs(getOutputFallRate(crate1,ch)); |
||
232 | // SetCtrlVal (p1h, P1_VFA0, vfall[0]); |
||
233 | // break; |
||
234 | } |
||
235 | } while ((rID != P1_EXIT)); |
||
236 | |||
237 | DiscardPanel (p1h); |
||
238 | |||
239 | MPOD_Close(0); |
||
240 | MPOD_End(); |
||
241 | |||
242 | return 0; |
||
243 | } |