Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
147 | f9daq | 1 | #ifdef _MAIN |
2 | #include <cvirte.h> |
||
3 | #include <userint.h> |
||
4 | #include "mpod_uir.h" |
||
5 | |||
6 | #include "netsnmplib.h" |
||
7 | #include "WIENER_SNMP.h" |
||
8 | |||
9 | |||
10 | static int p1h; |
||
11 | HSNMP mpod; |
||
12 | |||
13 | void snmptest(void) { |
||
14 | |||
15 | |||
16 | if(!mpod) return; |
||
17 | printf("-----------------------------------------------------------------\n"); |
||
18 | |||
19 | double ret; |
||
20 | double voltage; |
||
21 | double vSet=0; |
||
22 | int channel=2; |
||
23 | int iret; |
||
24 | int i, j; |
||
25 | |||
26 | printf("Turning channel %i ON\n", channel); |
||
27 | setMainSwitch(mpod, 1); |
||
28 | Sleep(1000); |
||
29 | printf(".... Turning channel %i ON\n", channel); |
||
30 | setChannelSwitch(mpod, channel, 1); |
||
31 | Sleep(1000); |
||
32 | |||
33 | //Test Channel Status |
||
34 | iret=getChannelSwitch(mpod, channel); |
||
35 | printf("Channel Status = %i\n\n", iret); |
||
36 | |||
37 | |||
38 | |||
39 | //getOutputNumber |
||
40 | iret=getOutputNumber(mpod); |
||
41 | printf("getOutputNumber = %i\n\n", iret); |
||
42 | |||
43 | //getOutputGroups |
||
44 | iret=getOutputGroups(mpod); |
||
45 | printf("getOutputGroups = %i\n\n", iret); |
||
46 | |||
47 | |||
48 | |||
49 | //Test Setting and reading output Voltage |
||
50 | vSet =getOutputVoltage(mpod, channel); |
||
51 | printf("Output Voltage = %f. I will now change it to 24.2\n", vSet); |
||
52 | setOutputVoltage(mpod, channel, 24.2); |
||
53 | vSet =getOutputVoltage(mpod, channel); |
||
54 | printf("Output Voltage = %f. I will now change it to 12.3\n", vSet); |
||
55 | setOutputVoltage(mpod, channel, 12.3); |
||
56 | vSet =getOutputVoltage(mpod, channel); |
||
57 | printf("Output Voltage = %f.\n\n", vSet); |
||
58 | |||
59 | //Test Reading the Sense Measurement |
||
60 | ret = getOutputSenseMeasurement(mpod, channel); |
||
61 | printf("Sense Voltage = %f\n", ret); |
||
62 | Sleep(1000); |
||
63 | ret = getOutputSenseMeasurement(mpod, channel); |
||
64 | printf("Sense Voltage = %f. It the channel is ramping it should have changed.\n\n", ret); |
||
65 | |||
66 | //Test Reading the Current |
||
67 | ret = getCurrentMeasurement(mpod, channel); |
||
68 | printf("Current Measurement = %f\n\n", ret); |
||
69 | |||
70 | //Test the Ramp |
||
71 | ret=getOutputRiseRate(mpod, channel); |
||
72 | printf("Ramp Rate is %f, Let's make it 46.\n", ret); |
||
73 | setOutputRiseRate(mpod, channel, 4.6); |
||
74 | ret=getOutputRiseRate(mpod, channel); |
||
75 | printf("Ramp Rate is %f, Let's make it 100.\n", ret); |
||
76 | setOutputRiseRate(mpod, channel, 10.0); |
||
77 | ret=getOutputRiseRate(mpod, channel); |
||
78 | printf("Ramp Rate is %f.\n\n", ret); |
||
79 | |||
80 | //Test Channel Status |
||
81 | iret=getChannelSwitch(mpod, channel); |
||
82 | printf("Channel Status = %i\n\n", iret); |
||
83 | |||
84 | |||
85 | |||
86 | getMainSwitch(mpod); |
||
87 | //setMainSwitch(mpod, 0); |
||
88 | Sleep(1000); |
||
89 | if (!getMainSwitch(mpod)) { |
||
90 | printf("Crate is now Off\n"); |
||
91 | } |
||
92 | |||
93 | |||
94 | printf("-----------------------------------------------------------------\n"); |
||
95 | |||
96 | |||
97 | } |
||
98 | |||
99 | |||
100 | int main (int argc, char *argv[]) { |
||
101 | if (InitCVIRTE (0, argv, 0) == 0) |
||
102 | return -1; // out of memory |
||
103 | if ((p1h = LoadPanel (0, "mpod_uir.uir", PANEL)) < 0) |
||
104 | return -1; |
||
105 | |||
106 | if(!SnmpInit()) return; // basic init |
||
107 | mpod = SnmpOpen("178.172.43.94"); // open TCP/IP socket |
||
108 | SetCtrlVal(p1h,PANEL_MPODONOFF,1-getMainSwitch(mpod)); |
||
109 | DisplayPanel (p1h); |
||
110 | RunUserInterface (); |
||
111 | DiscardPanel (p1h); |
||
112 | SnmpClose(mpod); |
||
113 | SnmpCleanup(); // finish |
||
114 | return 0; |
||
115 | } |
||
116 | |||
117 | int CVICALLBACK StartCB (int panel, int control, int event, |
||
118 | void *callbackData, int eventData1, int eventData2) { |
||
119 | switch (event) { |
||
120 | case EVENT_COMMIT: |
||
121 | snmptest(); |
||
122 | break; |
||
123 | } |
||
124 | return 0; |
||
125 | } |
||
126 | |||
127 | int CVICALLBACK StopCB (int panel, int control, int event, |
||
128 | void *callbackData, int eventData1, int eventData2) { |
||
129 | switch (event) { |
||
130 | case EVENT_COMMIT: |
||
131 | |||
132 | break; |
||
133 | } |
||
134 | return 0; |
||
135 | } |
||
136 | |||
137 | int CVICALLBACK ExitCB (int panel, int control, int event, |
||
138 | void *callbackData, int eventData1, int eventData2) { |
||
139 | switch (event) { |
||
140 | case EVENT_COMMIT: |
||
141 | QuitUserInterface (0); |
||
142 | break; |
||
143 | } |
||
144 | return 0; |
||
145 | } |
||
146 | |||
147 | |||
148 | int CVICALLBACK MpodOnOffCB (int panel, int control, int event, |
||
149 | void *callbackData, int eventData1, int eventData2) { |
||
150 | int val; |
||
151 | switch (event) { |
||
152 | case EVENT_COMMIT: |
||
153 | GetCtrlVal(panel,control,&val); |
||
154 | getMainSwitch(mpod); |
||
155 | setMainSwitch(mpod, 1-val); |
||
156 | Sleep(100); |
||
157 | if (!getMainSwitch(mpod)) { |
||
158 | printf("Crate is now Off\n"); |
||
159 | } else { |
||
160 | printf("Crate is now On\n"); |
||
161 | } |
||
162 | break; |
||
163 | } |
||
164 | return 0; |
||
165 | } |
||
166 | |||
167 | |||
168 | int CVICALLBACK MpodChannelsOutputVoltageCB (int panel, int control, int event, |
||
169 | void *callbackData, int eventData1, int eventData2) { |
||
170 | double vset,iset; |
||
171 | switch (event) { |
||
172 | case EVENT_COMMIT: |
||
173 | GetCtrlVal(panel,PANEL_VSET,&vset); |
||
174 | GetCtrlVal(panel,PANEL_ISET,&iset); |
||
175 | for( int i = 0; i < 4; i++) { |
||
176 | int j=i*100; |
||
177 | for( int k = 0; k < 8; k++) { |
||
178 | int channel = j+k; |
||
179 | char *cName= getOutputName(mpod, channel); |
||
180 | if (!cName) continue; |
||
181 | if (channel==0) continue; |
||
182 | printf("%d Vset=%f Iset=%f \n", channel, vset,iset); |
||
183 | setOutputVoltage(mpod, channel, vset); |
||
184 | setOutputCurrent(mpod, channel, iset); |
||
185 | |||
186 | } |
||
187 | } |
||
188 | break; |
||
189 | } |
||
190 | return 0; |
||
191 | } |
||
192 | |||
193 | |||
194 | |||
195 | int CVICALLBACK MpodChannelsOnOffCB (int panel, int control, int event, |
||
196 | void *callbackData, int eventData1, int eventData2) { |
||
197 | int val; |
||
198 | switch (event) { |
||
199 | case EVENT_COMMIT: |
||
200 | GetCtrlVal(panel,control,&val); |
||
201 | val=1-val; |
||
202 | for( int i = 0; i < 4; i++) { |
||
203 | int j=i*100; |
||
204 | for( int k = 0; k < 8; k++) { |
||
205 | int channel = j+k; |
||
206 | char *cName= getOutputName(mpod, channel); |
||
207 | if (!cName) continue; |
||
208 | if (channel==0) continue; |
||
209 | int state=getChannelSwitch(mpod, channel); |
||
210 | if (state!= val) setChannelSwitch(mpod, channel, val); |
||
211 | |||
212 | } |
||
213 | } |
||
214 | break; |
||
215 | } |
||
216 | return 0; |
||
217 | } |
||
218 | |||
219 | |||
220 | |||
221 | |||
222 | |||
223 | |||
224 | int CVICALLBACK GetStatus (int panel, int control, int event, |
||
225 | void *callbackData, int eventData1, int eventData2) { |
||
226 | switch (event) { |
||
227 | case EVENT_COMMIT: |
||
228 | // scan MPOD crate, now 4 loops for MPODmini can be changed to 10 for full size crate |
||
229 | for( int i = 0; i < 4; i++) |
||
230 | { |
||
231 | int j=i*100; |
||
232 | for( int k = 0; k < 8; k++) |
||
233 | { |
||
234 | int channel = j+k; |
||
235 | char * cName= getOutputName(mpod, channel); |
||
236 | if (!cName) continue; |
||
237 | |||
238 | int iret=getChannelSwitch(mpod, channel); |
||
239 | double vSet =getOutputVoltage(mpod, channel); |
||
240 | double iSet =getOutputCurrent(mpod, channel); |
||
241 | double vTerminal =getOutputTerminalMeasurement(mpod, channel); |
||
242 | double vSense =getOutputSenseMeasurement(mpod, channel); |
||
243 | double iMon =getCurrentMeasurement(mpod, channel); |
||
244 | double vRpUp =getOutputRiseRate(mpod, channel); |
||
245 | double vRpDown =getOutputFallRate(mpod, channel); |
||
246 | printf("%3i %s\t[%i]\tVset=%g\tIset=%g\tImon=%g\tVmon=%g\tVterm=%g\tRUp=%g\tRDn=%g\n", channel, cName, iret, vSet, iSet, iMon, vSense, vTerminal, vRpUp, vRpDown); |
||
247 | } |
||
248 | } |
||
249 | |||
250 | break; |
||
251 | } |
||
252 | return 0; |
||
253 | } |
||
254 | #endif |