Subversion Repositories f9daq

Rev

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