#include "MPOD.h"
#include "HVtest_ui.h"
#define HVSLOT 3
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) {
const int mo=3;
const int ch0=100*mo;
int mainonoff,HVonoffall;
int HVonoff[4],HVonoff_rID[4]={P1_HVonoff_0,P1_HVonoff_1,P1_HVonoff_2,P1_HVonoff_3};
int HVvdis_rID[4]={P1_HVvdis_0,P1_HVvdis_1,P1_HVvdis_2,P1_HVvdis_3};
int HVcdis_rID[4]={P1_HVcdis_0,P1_HVcdis_1,P1_HVcdis_2,P1_HVcdis_3};
int iret;
int i, j;
double ret;
double HVvset[4],HVcset[4],HVvrise,HVvfall;
double HVvdis[4],HVcdis[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");
MPOD_Open(0,"arich-mpod1.kek.jp");
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) {
HVonoffall=0;
for (i=0;i<4;i++) {
HVonoff[i]=getChannelSwitch(crate1, ch0+i);
if (HVonoff[i]) HVonoffall=1;
}
for (i=0;i<4;i++) {
if (!HVonoffall) HVonoff[i]=1;
SetCtrlVal (p1h, HVonoff_rID[i], HVonoff[i]);
}
HVvset[0]=getOutputVoltage(crate1,ch0);
SetCtrlVal (p1h, P1_HVvset, HVvset[0]);
HVcset[0]=1e+6*getOutputCurrent(crate1,ch0);
SetCtrlVal (p1h, P1_HVcset, HVcset[0]);
HVvrise=getModuleRampSpeedVoltage(crate1,mo);
SetCtrlVal (p1h, P1_HVvrise, HVvrise);
// 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);
for (i=0;i<4;i++) {
HVvdis[i]=getOutputTerminalMeasurement(crate1, ch0+i);
SetCtrlVal (p1h, HVvdis_rID[i], HVvdis[i]);
HVcdis[i]=1e+6*getCurrentMeasurement(crate1, ch0+i);
SetCtrlVal (p1h, HVcdis_rID[i], HVcdis[i]);
PlotStripChart (p1h, P1_G1, HVcdis, 4, 0, 0, VAL_DOUBLE);
break;
case P1_MSW:
GetCtrlVal (p1h, P1_MSW, &mainonoff);
if (ConfirmPopup("Main switch!!!", cMainSwitch[mainonoff]))
setMainSwitch(crate1, mainonoff);
if (mainonoff) {
Delay(5);
HVonoffall=0;
for (i=0; i<4; i++) {
HVonoff[i]=getChannelSwitch(crate1, ch0+i);
if (HVonoff[i]) HVonoffall=1;
}
for (i=0; i<4; i++) {
if (!HVonoffall) HVonoff[i]=1;
SetCtrlVal (p1h, HVonoff_rID[i], HVonoff[i]);
}
HVvset[0]=getOutputVoltage(crate1,ch0);
SetCtrlVal (p1h, P1_HVvset, HVvset[0]);
HVcset[0]=1e+6*getOutputCurrent(crate1,ch0);
SetCtrlVal (p1h, P1_HVcset, HVcset[0]);
HVvrise=getModuleRampSpeedVoltage(crate1,mo);
SetCtrlVal (p1h, P1_HVvrise, HVvrise);
}
break;
}
if (!mainonoff) continue;
switch (rID) {
case P1_HVonoff:
GetCtrlVal (p1h, P1_HVonoff, &HVonoffall);
for (i=0;i<4;isetChannelSwitch(crate1, ch, onoff[0]);
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;
}