Rev 163 | Rev 165 | Go to most recent revision | 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 |
164 | f9daq | 6 | #define NTICSMAX 120 |
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}; |
||
159 | f9daq | 38 | |
39 | HSNMP crate1; |
||
40 | |||
41 | if (InitCVIRTE (hInstance, 0, 0) == 0) |
||
42 | return -1; /* out of memory */ |
||
43 | |||
44 | MPOD_Start(); |
||
162 | f9daq | 45 | // MPOD_Open(0,"f9mpod.ijs.si"); |
161 | f9daq | 46 | MPOD_Open(0,"arich-mpod1.kek.jp"); |
159 | f9daq | 47 | crate1 = crateHsnmp[0]; |
48 | |||
162 | f9daq | 49 | // iret=MPOD_GetInt(0,"moduleNumber.0"); |
50 | // printf("Module Number = %i\n", iret); |
||
51 | // strcpy(cret, MPOD_GetString(0,"moduleDescription.ma2")); |
||
52 | // printf("Module type: %s\n",cret); |
||
53 | // iret=MPOD_GetIntCh(0,"fanNominalSpeed",0); |
||
54 | // printf("Fan nominal speed = %i\n", iret); |
||
159 | f9daq | 55 | |
56 | if ((p1h = LoadPanel (0, "HVtest_ui.uir", P1)) < 0) return -1; |
||
57 | DisplayPanel (p1h); |
||
164 | f9daq | 58 | SetCtrlVal (p1h, P1_TESTon, 0); |
159 | f9daq | 59 | |
164 | f9daq | 60 | |
159 | f9daq | 61 | //Initial state |
62 | mainonoff=getMainSwitch(crate1); |
||
63 | SetCtrlVal (p1h, P1_MSW, mainonoff); |
||
64 | SetCtrlVal (p1h, P1_MSWLED, mainonoff); |
||
65 | iret=getMainStatus(crate1); |
||
66 | SetCtrlVal (p1h, P1_MST, iret); |
||
67 | iret=getFanNominalSpeed(crate1); |
||
68 | SetCtrlVal (p1h, P1_MFS, iret); |
||
69 | if (mainonoff) { |
||
162 | f9daq | 70 | HVonoffall=0; |
71 | for (i=0;i<4;i++) { |
||
72 | HVonoff[i]=getChannelSwitch(crate1, ch0+i); |
||
73 | if (HVonoff[i]) HVonoffall=1; |
||
74 | } |
||
75 | for (i=0;i<4;i++) { |
||
76 | if (!HVonoffall) HVonoff[i]=1; |
||
163 | f9daq | 77 | SetCtrlVal (p1h, HVonoff_rID[i], HVonoff[i]); |
162 | f9daq | 78 | } |
79 | HVvset[0]=getOutputVoltage(crate1,ch0); |
||
80 | SetCtrlVal (p1h, P1_HVvset, HVvset[0]); |
||
81 | HVcset[0]=1e+6*getOutputCurrent(crate1,ch0); |
||
82 | SetCtrlVal (p1h, P1_HVcset, HVcset[0]); |
||
163 | f9daq | 83 | SetAxisScalingMode (p1h, P1_G1, VAL_LEFT_YAXIS, VAL_MANUAL, -(HVcset[0]+1), 1.); |
162 | f9daq | 84 | HVvrise=getModuleRampSpeedVoltage(crate1,mo); |
85 | SetCtrlVal (p1h, P1_HVvrise, HVvrise); |
||
159 | f9daq | 86 | // vfall[0]=abs(getOutputFallRate(crate1,ch)); |
87 | // SetCtrlVal (p1h, P1_VFA0, vfall[0]); |
||
88 | } |
||
89 | // QueueUserEvent (1000, p1h, P1_RESET); |
||
90 | QueueUserEvent (9000, p1h, P1_REFRESHTIMER); |
||
91 | |||
92 | do { |
||
93 | GetUserEvent (1, &pID, &rID); |
||
94 | switch (rID) { |
||
95 | case P1_REFRESHTIMER: |
||
96 | mainonoff=getMainSwitch(crate1); |
||
97 | SetCtrlVal (p1h, P1_MSW, mainonoff); |
||
98 | SetCtrlVal (p1h, P1_MSWLED, mainonoff); |
||
164 | f9daq | 99 | if (mainonoff) { |
100 | iret=getMainStatus(crate1); |
||
101 | SetCtrlVal (p1h, P1_MST, iret); |
||
159 | f9daq | 102 | // ret=getOutputSenseMeasurement(crate1, ch); |
164 | f9daq | 103 | for (i=0; i<4; i++) { |
104 | HVvdis[i]=getOutputTerminalMeasurement(crate1, ch0+i); |
||
105 | SetCtrlVal (p1h, HVvdis_rID[i], HVvdis[i]); |
||
106 | HVcdis[i]=1e+6*getCurrentMeasurement(crate1, ch0+i); |
||
107 | SetCtrlVal (p1h, HVcdis_rID[i], HVcdis[i]); |
||
108 | } |
||
109 | PlotStripChart (p1h, P1_G1, HVcdis, 4, 0, 0, VAL_DOUBLE); |
||
110 | if (TESTon) { |
||
111 | ntics++; |
||
112 | for (i=0;i<4;i++) |
||
113 | fprintf(HVBfp[i],"%5d %10.1f %10.4f\n",ntics,HVvdis[i],HVcdis[i]); |
||
114 | switch (ntics) { |
||
115 | case 5: |
||
116 | SetCtrlVal(p1h,P1_HVonoffall, 1); |
||
117 | QueueUserEvent (1001, p1h, P1_HVonoffall); |
||
118 | break; |
||
119 | case NTICSMAX-25: |
||
120 | SetCtrlVal(p1h,P1_HVonoffall, 0); |
||
121 | QueueUserEvent (1001, p1h, P1_HVonoffall); |
||
122 | break; |
||
123 | case NTICSMAX: |
||
124 | SetCtrlVal (p1h, P1_TESTon, 0); |
||
125 | QueueUserEvent (1001, p1h, P1_TESTon); |
||
126 | break; |
||
127 | default: |
||
128 | break; |
||
129 | } |
||
130 | } |
||
163 | f9daq | 131 | } |
159 | f9daq | 132 | break; |
133 | case P1_MSW: |
||
134 | GetCtrlVal (p1h, P1_MSW, &mainonoff); |
||
135 | if (ConfirmPopup("Main switch!!!", cMainSwitch[mainonoff])) |
||
136 | setMainSwitch(crate1, mainonoff); |
||
162 | f9daq | 137 | if (mainonoff) { |
138 | Delay(5); |
||
139 | HVonoffall=0; |
||
140 | for (i=0; i<4; i++) { |
||
141 | HVonoff[i]=getChannelSwitch(crate1, ch0+i); |
||
142 | if (HVonoff[i]) HVonoffall=1; |
||
143 | } |
||
144 | for (i=0; i<4; i++) { |
||
145 | if (!HVonoffall) HVonoff[i]=1; |
||
146 | SetCtrlVal (p1h, HVonoff_rID[i], HVonoff[i]); |
||
147 | } |
||
148 | HVvset[0]=getOutputVoltage(crate1,ch0); |
||
149 | SetCtrlVal (p1h, P1_HVvset, HVvset[0]); |
||
150 | HVcset[0]=1e+6*getOutputCurrent(crate1,ch0); |
||
151 | SetCtrlVal (p1h, P1_HVcset, HVcset[0]); |
||
163 | f9daq | 152 | SetAxisScalingMode (p1h, P1_G1, VAL_LEFT_YAXIS, VAL_MANUAL, -(HVcset[0]+1), 1.); |
162 | f9daq | 153 | HVvrise=getModuleRampSpeedVoltage(crate1,mo); |
154 | SetCtrlVal (p1h, P1_HVvrise, HVvrise); |
||
155 | } |
||
159 | f9daq | 156 | break; |
163 | f9daq | 157 | } |
159 | f9daq | 158 | if (!mainonoff) continue; |
159 | switch (rID) { |
||
163 | f9daq | 160 | case P1_HVonoffall: |
161 | GetCtrlVal (p1h, P1_HVonoffall, &HVonoffall); |
||
162 | for (i=0;i<4;i++) { |
||
163 | GetCtrlVal (p1h, HVonoff_rID[i], &HVonoff[i]); |
||
164 | if (HVonoff[i]) |
||
165 | setChannelSwitch(crate1, ch0+i, HVonoffall); |
||
166 | } |
||
159 | f9daq | 167 | break; |
163 | f9daq | 168 | case P1_HVvset: |
169 | GetCtrlVal (p1h, P1_HVvset, &HVvset[0]); |
||
170 | for (i=0;i<4;i++) |
||
171 | setOutputVoltage(crate1, ch0+i, HVvset[0]); |
||
159 | f9daq | 172 | break; |
163 | f9daq | 173 | case P1_HVcset: |
174 | GetCtrlVal (p1h, P1_HVcset, &HVcset[0]); |
||
175 | SetAxisScalingMode (p1h, P1_G1, VAL_LEFT_YAXIS, VAL_MANUAL, -(HVcset[0]+1), 1.); |
||
176 | HVcset[0]/=1e+6; //[uA] |
||
177 | for (i=0;i<4;i++) |
||
178 | setOutputCurrent(crate1, ch0+i, HVcset[0]); |
||
159 | f9daq | 179 | break; |
163 | f9daq | 180 | case P1_HVvrise: |
181 | GetCtrlVal (p1h, P1_HVvrise, &HVvrise); |
||
182 | setModuleRampSpeedVoltage(crate1, mo, HVvrise); |
||
183 | HVvrise=getModuleRampSpeedVoltage(crate1,mo); |
||
184 | SetCtrlVal (p1h, P1_HVvrise, HVvrise); |
||
159 | f9daq | 185 | break; |
164 | f9daq | 186 | case P1_TESTon: |
187 | GetCtrlVal (p1h, P1_TESTon, &TESTon); |
||
188 | if (TESTon) { |
||
189 | ntics=0; |
||
190 | ClearStripChart (p1h, P1_G1); |
||
191 | for (i=0;i<4;i++) { |
||
192 | GetCtrlVal(p1h, HVBid_rID[i], HVBid[i]); |
||
193 | sprintf(HVBfname[i],"HVB_%s.dat",HVBid[i]); |
||
194 | HVBfp[i]=fopen(HVBfname[i],"w"); |
||
195 | } |
||
196 | } else { |
||
197 | SetCtrlVal(p1h,P1_HVonoffall, 0); |
||
198 | QueueUserEvent (1001, p1h, P1_HVonoffall); |
||
199 | for (i=0;i<4;i++) |
||
200 | fclose(HVBfp[i]); |
||
201 | } |
||
202 | break; |
||
159 | f9daq | 203 | // case P1_VFA0: |
204 | // GetCtrlVal (p1h, P1_VFA0, &ret); |
||
205 | // setOutputFallRate(crate1, ch, ret); |
||
206 | // vfall[0]=abs(getOutputFallRate(crate1,ch)); |
||
207 | // SetCtrlVal (p1h, P1_VFA0, vfall[0]); |
||
208 | // break; |
||
209 | } |
||
210 | } while ((rID != P1_EXIT)); |
||
211 | |||
212 | DiscardPanel (p1h); |
||
213 | |||
214 | MPOD_Close(0); |
||
215 | MPOD_End(); |
||
216 | |||
217 | return 0; |
||
218 | } |