#include "MPOD.h"
#include "HVtest_ui.h"
static int p1h, pID, rID, tfID;
int CVICALLBACK refreshTimer (int panel, int control, int event, void *callbackData,
int eventData1, int eventData2) {
QueueUserEvent (9000, p1h, P1_REFRESHTIMER);
return (0);
}
int __stdcall WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpszCmdLine, int nCmdShow) {
int mainonoff,onoff[4];
int ch=200,mo=2;
int iret;
int i, j;
double ret;
double vset[4],cset[4],vrise[4],vfall[4];
char cret[2000];
char cMainSwitch[2][30]= {"Turn system OFF?","Turn system ON?"};
HSNMP crate1;
if (InitCVIRTE (hInstance, 0, 0) == 0)
return -1; /* out of memory */
MPOD_Start();
MPOD_Open(0,"f9mpod.ijs.si");
crate1 = crateHsnmp[0];
iret=MPOD_GetInt(0,"moduleNumber.0");
printf("Module Number = %i\n", iret
);
strcpy(cret
, MPOD_GetString
(0,"moduleDescription.ma2"));
printf("Module type: %s\n",cret
);
iret=MPOD_GetIntCh(0,"fanNominalSpeed",0);
printf("Fan nominal speed = %i\n", iret
);
if ((p1h = LoadPanel (0, "HVtest_ui.uir", P1)) < 0) return -1;
DisplayPanel (p1h);
//Initial state
mainonoff=getMainSwitch(crate1);
SetCtrlVal (p1h, P1_MSW, mainonoff);
SetCtrlVal (p1h, P1_MSWLED, mainonoff);
iret=getMainStatus(crate1);
SetCtrlVal (p1h, P1_MST, iret);
iret=getFanNominalSpeed(crate1);
SetCtrlVal (p1h, P1_MFS, iret);
if (mainonoff) {
onoff[0]=getChannelSwitch(crate1, ch);
SetCtrlVal (p1h, P1_ONOFF0, onoff[0]);
vset[0]=getOutputVoltage(crate1,ch);
SetCtrlVal (p1h, P1_V0, vset[0]);
cset[0]=1e+6*getOutputCurrent(crate1,ch);
SetCtrlVal (p1h, P1_C0, cset[0]);
vrise[0]=getModuleRampSpeedVoltage(crate1,mo);
SetCtrlVal (p1h, P1_VRI0, vrise[0]);
// vfall[0]=abs(getOutputFallRate(crate1,ch));
// SetCtrlVal (p1h, P1_VFA0, vfall[0]);
}
// QueueUserEvent (1000, p1h, P1_RESET);
QueueUserEvent (9000, p1h, P1_REFRESHTIMER);
do {
GetUserEvent (1, &pID, &rID);
switch (rID) {
case P1_REFRESHTIMER:
mainonoff=getMainSwitch(crate1);
SetCtrlVal (p1h, P1_MSW, mainonoff);
SetCtrlVal (p1h, P1_MSWLED, mainonoff);
iret=getMainStatus(crate1);
SetCtrlVal (p1h, P1_MST, iret);
// ret=getOutputSenseMeasurement(crate1, ch);
ret=getOutputTerminalMeasurement(crate1, ch);
SetCtrlVal (p1h, P1_VD0, ret);
ret=1e+6*getCurrentMeasurement(crate1, ch);
SetCtrlVal (p1h, P1_CD0, ret);
PlotStripChartPoint (p1h, P1_G1, ret);
break;
case P1_MSW:
GetCtrlVal (p1h, P1_MSW, &mainonoff);
if (ConfirmPopup("Main switch!!!", cMainSwitch[mainonoff]))
setMainSwitch(crate1, mainonoff);
if (!mainonoff) break;
// Delay(1);
onoff[0]=getChannelSwitch(crate1, ch);
SetCtrlVal (p1h, P1_ONOFF0, onoff[0]);
vset[0]=getOutputVoltage(crate1,ch);
SetCtrlVal (p1h, P1_V0, vset[0]);
cset[0]=1e+6*getOutputCurrent(crate1,ch);
SetCtrlVal (p1h, P1_C0, cset[0]);
vrise[0]=getModuleRampSpeedVoltage(crate1,mo);
SetCtrlVal (p1h, P1_VRI0, vrise[0]);
// vfall[0]=abs(getOutputFallRate(crate1,ch));
// SetCtrlVal (p1h, P1_VFA0, vfall[0]);
break;
}
if (!mainonoff) continue;
switch (rID) {
case P1_ONOFF0:
GetCtrlVal (p1h, P1_ONOFF0, &onoff[0]);
setChannelSwitch(crate1, ch, onoff[0]);
// Delay(1);
break;
case P1_V0:
GetCtrlVal (p1h, P1_V0, &vset[0]);
setOutputVoltage(crate1, ch, vset[0]);
break;
case P1_C0:
GetCtrlVal (p1h, P1_C0, &cset[0]);
cset[0]/=1e+6; //[uA]
setOutputCurrent(crate1, ch, cset[0]);
break;
case P1_VRI0:
GetCtrlVal (p1h, P1_VRI0, &ret);
setModuleRampSpeedVoltage(crate1, mo, ret);
vrise[0]=getModuleRampSpeedVoltage(crate1,mo);
SetCtrlVal (p1h, P1_VRI0, vrise[0]);
break;
// case P1_VFA0:
// GetCtrlVal (p1h, P1_VFA0, &ret);
// setOutputFallRate(crate1, ch, ret);
// vfall[0]=abs(getOutputFallRate(crate1,ch));
// SetCtrlVal (p1h, P1_VFA0, vfall[0]);
// break;
}
} while ((rID != P1_EXIT));
DiscardPanel (p1h);
MPOD_Close(0);
MPOD_End();
return 0;
}