Subversion Repositories f9daq

Rev

Rev 161 | Rev 163 | 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"
2
#include "HVtest_ui.h"
3
 
161 f9daq 4
#define HVSLOT 3
5
 
159 f9daq 6
static int p1h, pID, rID, tfID;
7
 
8
int CVICALLBACK refreshTimer (int panel, int control, int event, void *callbackData,
9
                              int eventData1, int eventData2) {
10
  QueueUserEvent (9000, p1h, P1_REFRESHTIMER);
11
  return (0);
12
}
13
 
14
int __stdcall WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
15
                       LPSTR lpszCmdLine, int nCmdShow) {
16
 
162 f9daq 17
  const int mo=3;
18
  const int ch0=100*mo;
19
 
20
  int mainonoff,HVonoffall;
21
  int HVonoff[4],HVonoff_rID[4]={P1_HVonoff_0,P1_HVonoff_1,P1_HVonoff_2,P1_HVonoff_3};
22
  int HVvdis_rID[4]={P1_HVvdis_0,P1_HVvdis_1,P1_HVvdis_2,P1_HVvdis_3};
23
  int HVcdis_rID[4]={P1_HVcdis_0,P1_HVcdis_1,P1_HVcdis_2,P1_HVcdis_3};
159 f9daq 24
  int iret;
25
  int i, j;
26
  double ret;
162 f9daq 27
  double HVvset[4],HVcset[4],HVvrise,HVvfall;
28
  double HVvdis[4],HVcdis[4];
159 f9daq 29
  char cret[2000];
30
  char cMainSwitch[2][30]= {"Turn system OFF?","Turn system ON?"};
31
 
32
  HSNMP crate1;
33
 
34
  if (InitCVIRTE (hInstance, 0, 0) == 0)
35
    return -1;    /* out of memory */
36
 
37
  MPOD_Start();
162 f9daq 38
//  MPOD_Open(0,"f9mpod.ijs.si");
161 f9daq 39
  MPOD_Open(0,"arich-mpod1.kek.jp");
159 f9daq 40
  crate1 = crateHsnmp[0];
41
 
162 f9daq 42
//  iret=MPOD_GetInt(0,"moduleNumber.0");
43
//  printf("Module Number = %i\n", iret);
44
//  strcpy(cret, MPOD_GetString(0,"moduleDescription.ma2"));
45
//  printf("Module type: %s\n",cret);
46
//  iret=MPOD_GetIntCh(0,"fanNominalSpeed",0);
47
//  printf("Fan nominal speed = %i\n", iret);
159 f9daq 48
 
49
  if ((p1h = LoadPanel (0, "HVtest_ui.uir", P1)) < 0) return -1;
50
  DisplayPanel (p1h);
51
 
52
//Initial state
53
  mainonoff=getMainSwitch(crate1);
54
  SetCtrlVal (p1h, P1_MSW, mainonoff);
55
  SetCtrlVal (p1h, P1_MSWLED, mainonoff);
56
  iret=getMainStatus(crate1);
57
  SetCtrlVal (p1h, P1_MST, iret);
58
  iret=getFanNominalSpeed(crate1);
59
  SetCtrlVal (p1h, P1_MFS, iret);
60
  if (mainonoff) {
162 f9daq 61
    HVonoffall=0;
62
    for (i=0;i<4;i++) {
63
      HVonoff[i]=getChannelSwitch(crate1, ch0+i);
64
      if (HVonoff[i]) HVonoffall=1;
65
    }
66
    for (i=0;i<4;i++) {
67
      if (!HVonoffall) HVonoff[i]=1;
68
      SetCtrlVal (p1h, HVonoff_rID[i], HVonoff[i]);
69
    }
70
    HVvset[0]=getOutputVoltage(crate1,ch0);
71
    SetCtrlVal (p1h, P1_HVvset, HVvset[0]);
72
    HVcset[0]=1e+6*getOutputCurrent(crate1,ch0);
73
    SetCtrlVal (p1h, P1_HVcset, HVcset[0]);
74
    HVvrise=getModuleRampSpeedVoltage(crate1,mo);
75
    SetCtrlVal (p1h, P1_HVvrise, HVvrise);
159 f9daq 76
//    vfall[0]=abs(getOutputFallRate(crate1,ch));
77
//    SetCtrlVal (p1h, P1_VFA0, vfall[0]);
78
  }
79
//  QueueUserEvent (1000, p1h, P1_RESET);
80
  QueueUserEvent (9000, p1h, P1_REFRESHTIMER);
81
 
82
  do {
83
    GetUserEvent (1, &pID, &rID);
84
    switch (rID) {
85
      case P1_REFRESHTIMER:
86
        mainonoff=getMainSwitch(crate1);
87
        SetCtrlVal (p1h, P1_MSW, mainonoff);
88
        SetCtrlVal (p1h, P1_MSWLED, mainonoff);
89
        iret=getMainStatus(crate1);
90
        SetCtrlVal (p1h, P1_MST, iret);
91
//        ret=getOutputSenseMeasurement(crate1, ch);
162 f9daq 92
        for (i=0;i<4;i++) {
93
          HVvdis[i]=getOutputTerminalMeasurement(crate1, ch0+i);
94
          SetCtrlVal (p1h, HVvdis_rID[i], HVvdis[i]);
95
          HVcdis[i]=1e+6*getCurrentMeasurement(crate1, ch0+i);
96
          SetCtrlVal (p1h, HVcdis_rID[i], HVcdis[i]);
97
          PlotStripChart (p1h, P1_G1, HVcdis, 4, 0, 0, VAL_DOUBLE);
159 f9daq 98
        break;
99
      case P1_MSW:
100
        GetCtrlVal (p1h, P1_MSW, &mainonoff);
101
        if (ConfirmPopup("Main switch!!!", cMainSwitch[mainonoff]))
102
          setMainSwitch(crate1, mainonoff);
162 f9daq 103
        if (mainonoff) {
104
          Delay(5);
105
          HVonoffall=0;
106
          for (i=0; i<4; i++) {
107
            HVonoff[i]=getChannelSwitch(crate1, ch0+i);
108
            if (HVonoff[i]) HVonoffall=1;
109
          }
110
          for (i=0; i<4; i++) {
111
            if (!HVonoffall) HVonoff[i]=1;
112
            SetCtrlVal (p1h, HVonoff_rID[i], HVonoff[i]);
113
          }
114
          HVvset[0]=getOutputVoltage(crate1,ch0);
115
          SetCtrlVal (p1h, P1_HVvset, HVvset[0]);
116
          HVcset[0]=1e+6*getOutputCurrent(crate1,ch0);
117
          SetCtrlVal (p1h, P1_HVcset, HVcset[0]);
118
          HVvrise=getModuleRampSpeedVoltage(crate1,mo);
119
          SetCtrlVal (p1h, P1_HVvrise, HVvrise);
120
        }
159 f9daq 121
        break;
122
    }
123
    if (!mainonoff) continue;
124
    switch (rID) {
162 f9daq 125
      case P1_HVonoff:
126
        GetCtrlVal (p1h, P1_HVonoff, &HVonoffall);
127
        for (i=0;i<4;isetChannelSwitch(crate1, ch, onoff[0]);
159 f9daq 128
        break;
129
      case P1_V0:
130
        GetCtrlVal (p1h, P1_V0, &vset[0]);
131
        setOutputVoltage(crate1, ch, vset[0]);
132
        break;
133
      case P1_C0:
134
        GetCtrlVal (p1h, P1_C0, &cset[0]);
135
        cset[0]/=1e+6; //[uA]
136
        setOutputCurrent(crate1, ch, cset[0]);
137
        break;
138
      case P1_VRI0:
139
        GetCtrlVal (p1h, P1_VRI0, &ret);
140
        setModuleRampSpeedVoltage(crate1, mo, ret);
141
        vrise[0]=getModuleRampSpeedVoltage(crate1,mo);
142
        SetCtrlVal (p1h, P1_VRI0, vrise[0]);
143
        break;
144
//      case P1_VFA0:
145
//        GetCtrlVal (p1h, P1_VFA0, &ret);
146
//        setOutputFallRate(crate1, ch, ret);
147
//        vfall[0]=abs(getOutputFallRate(crate1,ch));
148
//        SetCtrlVal (p1h, P1_VFA0, vfall[0]);
149
//        break;
150
    }
151
  } while ((rID != P1_EXIT));
152
 
153
  DiscardPanel (p1h);
154
 
155
  MPOD_Close(0);
156
  MPOD_End();
157
 
158
  return 0;
159
}