V 10
1
LANG:1 8 (NoName)
PANEL,450 98 600 441 N {153,204,153} 0
EEE E E 1 -1 -1 0  210 150
"" 0 1
E"// AUTHORs
/******************************************************************************\\
123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789
|*=====================================-======================================*|
|*                 SCT COOLING SYSTEM CONTROL AND MONITORING                  *|
|*=====================================-======================================*|
|*   AUTHORs:        G.Codispoti - codispoti@cs.infn.it			    		  *|
|*								   Giuseppe.Codispoti@cern.ch			      *|
|*																		      *|
|*   MODIF_HISTORY:  17.03.2003  - first release						      *|
|*																		      *|
\\******************************************************************************/" 0
 2
"CBRef""1"
"EClose"E
""
DISPLAY_LAYER, 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0
LAYER, 0 
1
LANG:1 6 Layer1
30 19
"Frame1"
""
1 310 421 E E E 1 E 1 E N "_3DText" E N "_Transparent" E E
 E E
17 0 0 0 0 0
EE E
1
1
LANG:1 0 
0
E E 0 1 1 0 1 E U  0 E 310 34 581 421
1
LANG:1 119 -microsoft windows-Courier New-normal-r-normal-*-*-110-100-100-*-*-iso8859-1|-12,0,0,0,400,0,0,0,0,3,2,1,49,Courier New
0 ""
1
LANG:1 0 
30 21
"Frame2"
""
1 20 420 E E E 1 E 1 E N "_3DText" E N "_Transparent" E E
 E E
19 0 0 0 0 0
EE E
1
1
LANG:1 0 
0
E E 0 1 1 0 1 E U  0 E 20 35 290 421
1
LANG:1 119 -microsoft windows-Courier New-normal-r-normal-*-*-110-100-100-*-*-iso8859-1|-12,0,0,0,400,0,0,0,0,3,2,1,49,Courier New
0 ""
1
LANG:1 0 
2 22
"Text2"
""
1 113 13 E E E 1 E 1 E N {0,0,0} E N "_Transparent" E E
 E E
20 0 0 0 0 0
EE E
0
1
LANG:1 0 
1
"dashclr"N "_Transparent"
E E 0 1 1 0 1 E U  0 E 115 15 195 38
1 2 0 "s" 0 0 0 192 0 0  115 15
 1
1
LANG:1 107 -microsoft windows-Arial-bold-i-normal-*-*-170-100-100-*-*-iso8859-1|-19,0,0,0,700,255,0,0,0,3,2,1,34,Arial
0 ""
1
LANG:1 6 CREATE
2 23
"Text3"
""
1 405 12 E E E 1 E 1 E N {0,0,0} E N "_Transparent" E E
 E E
21 0 0 0 0 0
EE E
0
1
LANG:1 0 
1
"dashclr"N "_Transparent"
E E 0 1 1 0 1 E U  0 E 407 14 484 37
1 2 0 "s" 0 0 0 192 0 0  407 14
 1
1
LANG:1 107 -microsoft windows-Arial-bold-i-normal-*-*-170-100-100-*-*-iso8859-1|-19,0,0,0,700,255,0,0,0,3,2,1,34,Arial
0 ""
1
LANG:1 6 DELETE
13 10
"Button1"
""
1 40 60 E E E 1 E 1 E N "_3DText" E N {102,204,255} E E
 E E
9 0 0 0 0 0
EE E
0
1
LANG:1 0 
0
1
LANG:1 105 -microsoft windows-Arial-bold-r-normal-*-*-140-100-100-*-*-iso8859-1|-16,0,0,0,700,0,0,0,0,3,2,1,34,Arial
0 ""
38 58 272 122
T 
1
LANG:1 19 Create DPs and DPTs
"// Create DPTs & DPs
/******************************************************************************\\
123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789
|*=====================================-======================================*|
|*			               SCT POWER SUPPLIES MODULES     		              *|
|*=====================================-======================================*|
|*   AUTHORs:        G.Codispoti - codispoti@cs.infn.it			    		  *|
|*								   Giuseppe.Codispoti@cern.ch			      *|
|*																		      *|
|*   DESIGN ISSUEs:  This Script creates the full set of DPTs and DPs needed  *|
|*   				 also loading the correct number of crates from the file  *|
|*   				 \"Cnf_Syst.txt\"	by mean of the function getSyst.		  *|
|*																		      *|
|*   MODIF_HISTORY:  17.03.2003  - first release						      *|
|*																		      *|
\\******************************************************************************/

main()
{
  dyn_dyn_int dpType;
  dyn_dyn_string dpName;
  dyn_string dpAllTypes;
  string chan, LV, HV, num, Crate, UnitMax;
  int i, j, index, count;
  
  setValue(\"\",\"foreCol\",\"Red\");  
  
/******************************************************************************************/ 
//define the datapoint structure and types: ps_data_recv
  dpName[1] = makeDynString(\"ps_data_recv\", \"\");	dpType[1] = makeDynInt(DPEL_STRUCT);
  dpName[2] = makeDynString(\"\", \"Recv\", \"\");		dpType[2] = makeDynInt(0, DPEL_FLOAT);

  //remove the type if exist
  if(dpTypeExists(dpName[1][1]))
  	{
  		deleteDpType(dpName[1][1]);
  	}
  
  //create the above defined type
  dpTypeCreate(dpName, dpType);

  //clear the arrays
  dynClear(dpName);
  dynClear(dpType);

  //create a datapoint of the above defined type
//  dpCreate(\"\", \"ps_data_recv\");
	DebugN(\"ps_data_recv created\");

/******************************************************************************************/ 
//define the datapoint structure and types: ps_data_send
  dpName[1] = makeDynString(\"ps_data_send\", \"\");	dpType[1] = makeDynInt(DPEL_STRUCT);
  dpName[2] = makeDynString(\"\", \"Send\", \"\");		dpType[2] = makeDynInt(0, DPEL_FLOAT);

  //remove the type if exist
  if(dpTypeExists(dpName[1][1]))
  	{
  		deleteDpType(dpName[1][1]);
  	}
  
  //create the above defined type
  dpTypeCreate(dpName, dpType);

  //clear the arrays
  dynClear(dpName);
  dynClear(dpType);

  //create a datapoint of the above defined type
//  dpCreate(\"\", \"ps_data_send\");
	DebugN(\"ps_data_send created\");
/******************************************************************************************/ 
//define the datapoint structure and types: ps_data_dupl
  dpName[1] = makeDynString(\"ps_data_dupl\", \"\");	dpType[1] = makeDynInt(DPEL_STRUCT);
  dpName[2] = makeDynString(\"\", \"Send\", \"\");		dpType[2] = makeDynInt(0, DPEL_FLOAT);
  dpName[3] = makeDynString(\"\", \"Recv\", \"\");		dpType[3] = makeDynInt(0, DPEL_FLOAT);

  //remove the type if exist
  if(dpTypeExists(dpName[1][1]))
  	{
  		deleteDpType(dpName[1][1]);
  	}
  
  //create the above defined type
  dpTypeCreate(dpName, dpType);

  //clear the arrays
  dynClear(dpName);
  dynClear(dpType);

  //create a datapoint of the above defined type
//  dpCreate(\"\", \"ps_data_dupl\");
	DebugN(\"ps_data_dupl created\");
	
/******************************************************************************************/ 
//define the datapoint structure and types: ps_stat_recv
  dpName[1] = makeDynString(\"ps_stat_recv\", \"\");	dpType[1] = makeDynInt(DPEL_STRUCT);
  dpName[2] = makeDynString(\"\", \"Recv\", \"\");		dpType[2] = makeDynInt(0, DPEL_INT);

  //remove the type if exist
  if(dpTypeExists(dpName[1][1]))
  	{
  		deleteDpType(dpName[1][1]);
  	}
  
  //create the above defined type
  dpTypeCreate(dpName, dpType);

  //clear the arrays
  dynClear(dpName);
  dynClear(dpType);

  //create a datapoint of the above defined type
//  dpCreate(\"\", \"ps_stat_recv\");
	DebugN(\"ps_stat_recv created\");

/******************************************************************************************/ 
//define the datapoint structure and types: ps_stat_send
  dpName[1] = makeDynString(\"ps_stat_send\", \"\");	dpType[1] = makeDynInt(DPEL_STRUCT);
  dpName[2] = makeDynString(\"\", \"Send\", \"\");		dpType[2] = makeDynInt(0, DPEL_INT);

  //remove the type if exist
  if(dpTypeExists(dpName[1][1]))
  	{
  		deleteDpType(dpName[1][1]);
  	}
  
  //create the above defined type
  dpTypeCreate(dpName, dpType);

  //clear the arrays
  dynClear(dpName);
  dynClear(dpType);

  //create a datapoint of the above defined type
//  dpCreate(\"\", \"ps_stat_send\");
	DebugN(\"ps_stat_send created\");
/******************************************************************************************/ 
//define the datapoint structure and types: ps_stat_dupl
  dpName[1] = makeDynString(\"ps_stat_dupl\", \"\");	dpType[1] = makeDynInt(DPEL_STRUCT);
  dpName[2] = makeDynString(\"\", \"Send\", \"\");		dpType[2] = makeDynInt(0, DPEL_INT);
  dpName[3] = makeDynString(\"\", \"Recv\", \"\");		dpType[3] = makeDynInt(0, DPEL_INT);

  //remove the type if exist
  if(dpTypeExists(dpName[1][1]))
  	{
  		deleteDpType(dpName[1][1]);
  	}
  
  //create the above defined type
  dpTypeCreate(dpName, dpType);

  //clear the arrays
  dynClear(dpName);
  dynClear(dpType);

  //create a datapoint of the above defined type
//  dpCreate(\"\", \"ps_stat_dupl\");
	DebugN(\"ps_stat_dupl created\"); 


/******************************************************************************************/      
//define the datapoint structure and types: ps_crate
  dpName[1] = makeDynString(\"ps_crate\", \"\");						dpType[1] = makeDynInt(DPEL_STRUCT);
  dpName[2] = makeDynString(\"\", \"CC_Reset\", \"ps_stat_send\", \"\");	dpType[2] = makeDynInt(0, DPEL_TYPEREF);
  dpName[3] = makeDynString(\"\", \"CCch_Set\", \"ps_stat_send\", \"\");	dpType[3] = makeDynInt(0, DPEL_TYPEREF);
  dpName[4] = makeDynString(\"\", \"CCchRead\", \"ps_stat_send\", \"\");	dpType[4] = makeDynInt(0, DPEL_TYPEREF);
  dpName[5] = makeDynString(\"\", \"StartIVCurve\", \"\", \"\");			dpType[5] = makeDynInt(0, DPEL_STRUCT);
  dpName[6] = makeDynString(\"\", \"\", \"Send\", \"\");					dpType[6] = makeDynInt(0, 0, DPEL_INT);
  dpName[7] = makeDynString(\"\", \"NMT\" \"\", \"\");						dpType[7] = makeDynInt(0, DPEL_STRUCT);
  dpName[8] = makeDynString(\"\", \"\", \"Recv\", \"\");					dpType[8] = makeDynInt(0, 0, DPEL_INT);
  dpName[9] = makeDynString(\"\", \"\", \"Send\", \"\");					dpType[9] = makeDynInt(0, 0, DPEL_INT);

  //remove the type if exist
  if(dpTypeExists(dpName[1][1]))
  	{
  		deleteDpType(dpName[1][1]);
  	}
  
  //create the above defined type
  dpTypeCreate(dpName, dpType);

  //clear the arrays
  dynClear(dpName);
  dynClear(dpType);

  //create a datapoint of the above defined type
//  dpCreate(\"\", \"ps_crate\");
	DebugN(\"ps_crate created\");

/******************************************************************************************/ 
//define the datapoint structure and types: ps_alert
  dpName[1] = makeDynString(\"ps_alert\", \"\");		dpType[1] = makeDynInt(DPEL_STRUCT);
  dpName[2] = makeDynString(\"\", \"Message\", \"\");		dpType[2] = makeDynInt(0, DPEL_STRING);
  dpName[3] = makeDynString(\"\", \"CameWent\", \"\");	dpType[3] = makeDynInt(0, DPEL_INT);
  dpName[4] = makeDynString(\"\", \"Counter\", \"\");		dpType[4] = makeDynInt(0, DPEL_INT);
	
  //remove the type if exist
  if(dpTypeExists(dpName[1][1]))
  	{
  		deleteDpType(dpName[1][1]);
  	}
  
  //create the above defined type
  dpTypeCreate(dpName, dpType);

  //clear the arrays
  dynClear(dpName);
  dynClear(dpType);

  //create a datapoint of the above defined type
//  dpCreate(\"\", \"ps_alert\");
	DebugN(\"ps_alert created\");

/******************************************************************************************/       
//define the datapoint structure and types: hv_card
  dpName[1] = makeDynString(\"hv_card\", \"\");							dpType[1] = makeDynInt(DPEL_STRUCT);
  dpName[2] = makeDynString(\"\", \"HVcaStat\", \"ps_stat_recv\", \"\");	dpType[2] = makeDynInt(0, DPEL_TYPEREF);
  dpName[3] = makeDynString(\"\", \"HVcaMask\", \"ps_stat_send\", \"\");	dpType[3] = makeDynInt(0, DPEL_TYPEREF);

  //remove the type if exist
  if(dpTypeExists(dpName[1][1]))
  	{
  		deleteDpType(dpName[1][1]);
  	}
  
  //create the above defined type
  dpTypeCreate(dpName, dpType);

  //clear the arrays
  dynClear(dpName);
  dynClear(dpType);

  //create a datapoint of the above defined type
//  dpCreate(\"\", \"hv_card\");
	DebugN(\"hv_card created\");

/******************************************************************************************/      
//define the datapoint structure and types: lv_card
  dpName[1] = makeDynString(\"lv_card\", \"\");							dpType[1] = makeDynInt(DPEL_STRUCT);
  dpName[2] = makeDynString(\"\", \"LVcaStat\", \"ps_data_recv\", \"\");	dpType[2] = makeDynInt(0, DPEL_TYPEREF);
  dpName[3] = makeDynString(\"\", \"LVcaTemp\", \"ps_data_recv\", \"\");	dpType[3] = makeDynInt(0, DPEL_TYPEREF);
  dpName[4] = makeDynString(\"\", \"LVcaPowr\", \"ps_data_recv\", \"\");	dpType[4] = makeDynInt(0, DPEL_TYPEREF);
  dpName[5] = makeDynString(\"\", \"LVcaTrip\", \"ps_data_send\", \"\");	dpType[5] = makeDynInt(0, DPEL_TYPEREF);
  dpName[6] = makeDynString(\"\", \"LVcaMask\", \"\", \"\");				dpType[6] = makeDynInt(0, DPEL_STRUCT);
  dpName[7] = makeDynString(\"\", \"\", \"Send\", \"\");					dpType[7] = makeDynInt(0, 0, DPEL_INT);
  dpName[8] = makeDynString(\"\", \"\", \"Recv\", \"\");					dpType[8] = makeDynInt(0, 0, DPEL_INT);

  //remove the type if exist
  if(dpTypeExists(dpName[1][1]))
  	{
  		deleteDpType(dpName[1][1]);
  	}
  
  //create the above defined type
  dpTypeCreate(dpName, dpType);

  //clear the arrays
  dynClear(dpName);
  dynClear(dpType);

  //create a datapoint of the above defined type
//  dpCreate(\"\", \"lv_card\");
	DebugN(\"lv_card created\");
/******************************************************************************************/  
i=1;
//define the datapoint structure and types: ps_chan
  dpName[i] = makeDynString(\"ps_chan\", \"\");							dpType[i++] = makeDynInt(DPEL_STRUCT);
  dpName[i] = makeDynString(\"\", \"LVchStat\", \"ps_stat_recv\", \"\");	dpType[i++] = makeDynInt(0, DPEL_TYPEREF);
  dpName[i] = makeDynString(\"\", \"LVch_Vcc\", \"ps_data_dupl\", \"\");	dpType[i++] = makeDynInt(0, DPEL_TYPEREF);
  dpName[i] = makeDynString(\"\", \"LVps_Vcc\", \"ps_data_recv\", \"\");	dpType[i++] = makeDynInt(0, DPEL_TYPEREF);
  dpName[i] = makeDynString(\"\", \"LVretVcc\", \"ps_data_recv\", \"\");	dpType[i++] = makeDynInt(0, DPEL_TYPEREF);
  dpName[i] = makeDynString(\"\", \"LVch_Icc\", \"ps_data_recv\", \"\");	dpType[i++] = makeDynInt(0, DPEL_TYPEREF);
  dpName[i] = makeDynString(\"\", \"LVch_Vdd\", \"ps_data_dupl\", \"\");	dpType[i++] = makeDynInt(0, DPEL_TYPEREF);
  dpName[i] = makeDynString(\"\", \"LVps_Vdd\", \"ps_data_recv\", \"\");	dpType[i++] = makeDynInt(0, DPEL_TYPEREF);
  dpName[i] = makeDynString(\"\", \"LVretVdd\", \"ps_data_recv\", \"\");	dpType[i++] = makeDynInt(0, DPEL_TYPEREF);
  dpName[i] = makeDynString(\"\", \"LVch_Idd\", \"ps_data_recv\", \"\");	dpType[i++] = makeDynInt(0, DPEL_TYPEREF);
  dpName[i] = makeDynString(\"\", \"LVchVCSV\", \"ps_data_dupl\", \"\");	dpType[i++] = makeDynInt(0, DPEL_TYPEREF);
  dpName[i] = makeDynString(\"\", \"LVchVCSI\", \"ps_data_recv\", \"\");	dpType[i++] = makeDynInt(0, DPEL_TYPEREF);
  dpName[i] = makeDynString(\"\", \"LVchPINV\", \"ps_data_dupl\", \"\");	dpType[i++] = makeDynInt(0, DPEL_TYPEREF);
  dpName[i] = makeDynString(\"\", \"LVchPINI\", \"ps_data_recv\", \"\");	dpType[i++] = makeDynInt(0, DPEL_TYPEREF);
  dpName[i] = makeDynString(\"\", \"MOch_Tm0\", \"ps_data_recv\", \"\");	dpType[i++] = makeDynInt(0, DPEL_TYPEREF);
  dpName[i] = makeDynString(\"\", \"MOch_Tm1\", \"ps_data_recv\", \"\");	dpType[i++] = makeDynInt(0, DPEL_TYPEREF);
  dpName[i] = makeDynString(\"\", \"LVchDTrp\", \"ps_data_send\", \"\");	dpType[i++] = makeDynInt(0, DPEL_TYPEREF);
  dpName[i] = makeDynString(\"\", \"LVchCTrp\", \"ps_data_send\", \"\");	dpType[i++] = makeDynInt(0, DPEL_TYPEREF);
  dpName[i] = makeDynString(\"\", \"LVchTLim\", \"ps_data_send\", \"\");	dpType[i++] = makeDynInt(0, DPEL_TYPEREF);
  dpName[i] = makeDynString(\"\", \"LVchTTrp\", \"ps_data_send\", \"\");	dpType[i++] = makeDynInt(0, DPEL_TYPEREF);
  dpName[i] = makeDynString(\"\", \"LVchCLKS\", \"ps_stat_send\", \"\");	dpType[i++] = makeDynInt(0, DPEL_TYPEREF);
  dpName[i] = makeDynString(\"\", \"LVchCLKR\", \"ps_stat_send\", \"\");	dpType[i++] = makeDynInt(0, DPEL_TYPEREF);
  dpName[i] = makeDynString(\"\", \"LVchVOut\", \"ps_stat_send\", \"\");	dpType[i++] = makeDynInt(0, DPEL_TYPEREF);
  dpName[i] = makeDynString(\"\", \"HVchStat\", \"ps_stat_recv\", \"\");	dpType[i++] = makeDynInt(0, DPEL_TYPEREF);
  dpName[i] = makeDynString(\"\", \"HVchVolt\", \"ps_data_dupl\", \"\");	dpType[i++] = makeDynInt(0, DPEL_TYPEREF);
  dpName[i] = makeDynString(\"\", \"HVchCurr\", \"ps_data_recv\", \"\");	dpType[i++] = makeDynInt(0, DPEL_TYPEREF);
  dpName[i] = makeDynString(\"\", \"HVchITrp\", \"ps_data_send\", \"\");	dpType[i++] = makeDynInt(0, DPEL_TYPEREF);
  dpName[i] = makeDynString(\"\", \"HVchRamp\", \"ps_data_send\", \"\");	dpType[i++] = makeDynInt(0, DPEL_TYPEREF);
  dpName[i] = makeDynString(\"\", \"LV_Stat\", \"\", \"\");					dpType[i++] = makeDynInt(0, DPEL_UINT);
  dpName[i] = makeDynString(\"\", \"HV_Stat\", \"\", \"\");					dpType[i++] = makeDynInt(0, DPEL_UINT);
  dpName[i] = makeDynString(\"\", \"WarnMesg\", \"ps_alert\", \"\");		dpType[i++] = makeDynInt(0, DPEL_TYPEREF);
  dpName[i] = makeDynString(\"\", \"FatlMesg\", \"ps_alert\", \"\");		dpType[i++] = makeDynInt(0, DPEL_TYPEREF);
  dpName[i] = makeDynString(\"\", \"IVCurve\", \"\", \"\");					dpType[i++] = makeDynInt(0, DPEL_STRUCT);
  dpName[i] = makeDynString(\"\", \"\", \"HV_Start\", \"\", \"\");			dpType[i++] = makeDynInt(0, 0, DPEL_STRUCT);
  dpName[i] = makeDynString(\"\", \"\", \"\", \"Send\", \"\");				dpType[i++] = makeDynInt(0, 0, 0, DPEL_FLOAT);
  dpName[i] = makeDynString(\"\", \"\", \"HV_Step\", \"\", \"\");				dpType[i++] = makeDynInt(0, 0, DPEL_STRUCT);
  dpName[i] = makeDynString(\"\", \"\", \"\", \"Send\", \"\");				dpType[i++] = makeDynInt(0, 0, 0, DPEL_FLOAT);
  dpName[i] = makeDynString(\"\", \"\", \"HV_Stop\", \"\", \"\");				dpType[i++] = makeDynInt(0, 0, DPEL_STRUCT);
  dpName[i] = makeDynString(\"\", \"\", \"\", \"Send\", \"\");				dpType[i++] = makeDynInt(0, 0, 0, DPEL_FLOAT);
  dpName[i] = makeDynString(\"\", \"\", \"HV_End\", \"\", \"\");				dpType[i++] = makeDynInt(0, 0, DPEL_STRUCT);
  dpName[i] = makeDynString(\"\", \"\", \"\", \"Send\", \"\");				dpType[i++] = makeDynInt(0, 0, 0, DPEL_FLOAT);
  dpName[i] = makeDynString(\"\", \"\", \"Curr_Max\", \"\", \"\");			dpType[i++] = makeDynInt(0, 0, DPEL_STRUCT);
  dpName[i] = makeDynString(\"\", \"\", \"\", \"Send\", \"\");				dpType[i++] = makeDynInt(0, 0, 0, DPEL_FLOAT);
  dpName[i] = makeDynString(\"\", \"\", \"Curr_Warn\", \"\", \"\");			dpType[i++] = makeDynInt(0, 0, DPEL_STRUCT);
  dpName[i] = makeDynString(\"\", \"\", \"\", \"Send\", \"\");				dpType[i++] = makeDynInt(0, 0, 0, DPEL_FLOAT);
  dpName[i] = makeDynString(\"\", \"\", \"StartIVCurve\", \"\", \"\");		dpType[i++] = makeDynInt(0, 0, DPEL_STRUCT);
  dpName[i] = makeDynString(\"\", \"\", \"\", \"Send\", \"\");				dpType[i++] = makeDynInt(0, 0, 0, DPEL_FLOAT);
  dpName[i] = makeDynString(\"\", \"\", \"Status\", \"\", \"\");				dpType[i++] = makeDynInt(0, 0, DPEL_STRUCT);
  dpName[i] = makeDynString(\"\", \"\", \"\", \"Recv\", \"\");				dpType[i++] = makeDynInt(0, 0, 0, DPEL_FLOAT);
  dpName[i] = makeDynString(\"\", \"\", \"StartTime\", \"\", \"\");			dpType[i++] = makeDynInt(0, 0, DPEL_TIME);
  dpName[i] = makeDynString(\"\", \"\", \"TimeWait\", \"\", \"\");			dpType[i++] = makeDynInt(0, 0, DPEL_STRUCT);
  dpName[i] = makeDynString(\"\", \"\", \"\", \"Send\", \"\");				dpType[i++] = makeDynInt(0, 0, 0, DPEL_FLOAT);


  //remove the type if exist
  if(dpTypeExists(dpName[1][1]))
  	{
  		deleteDpType(dpName[1][1]);
  	}
  
  //create the above defined type
  dpTypeCreate(dpName, dpType);

  //clear the arrays
  dynClear(dpName);
  dynClear(dpType);

  //create a datapoint of the above defined type
//  dpCreate(\"\", \"ps_chan\");
	DebugN(\"ps_chan created\");	
	
/******************************************************************************************/ 
//define the datapoint structure and types: MPS_Settings
  dpName[1] = makeDynString(\"MPS_Settings\", \"\");	dpType[1] = makeDynInt(DPEL_STRUCT);
  dpName[2] = makeDynString(\"\", \"Name\", \"\");		dpType[2] = makeDynInt(0, DPEL_STRING);
  dpName[3] = makeDynString(\"\", \"Indx\", \"\");		dpType[3] = makeDynInt(0, DPEL_INT);
  dpName[4] = makeDynString(\"\", \"Stat\", \"\");		dpType[4] = makeDynInt(0, DPEL_UINT);
  dpName[5] = makeDynString(\"\", \"Data\", \"\");		dpType[5] = makeDynInt(0, DPEL_FLOAT);
  dpName[6] = makeDynString(\"\", \"Numb\", \"\");		dpType[6] = makeDynInt(0, DPEL_INT);

  //remove the type if exist
  if(dpTypeExists(dpName[1][1]))
  	{
  		deleteDpType(dpName[1][1]);
  	}
  
  //create the above defined type
  dpTypeCreate(dpName, dpType);

  //clear the arrays
  dynClear(dpName);
  dynClear(dpType);

  //create a datapoint of the above defined type
  dpCreate(\"LVch\", \"MPS_Settings\");
  dpCreate(\"LVch_max\", \"MPS_Settings\");
  dpCreate(\"HVch\", \"MPS_Settings\");
  dpCreate(\"HVch_max\", \"MPS_Settings\");
  dpCreate(\"LVca_max\", \"MPS_Settings\");
  dpCreate(\"HVca\", \"MPS_Settings\");
  dpCreate(\"HVca_max\", \"MPS_Settings\");
  dpCreate(\"Crate\", \"MPS_Settings\");
  dpCreate(\"CRpa_max\", \"MPS_Settings\");
  dpCreate(\"Rack\", \"MPS_Settings\");
  dpCreate(\"Info\", \"MPS_Settings\");
  dpCreate(\"IVtrigger\", \"MPS_Settings\");
  dpCreate(\"Test\", \"MPS_Settings\");
  dpCreate(\"IVfile\", \"MPS_Settings\");

  DebugN(\"MPS_Settings created\");

/******************************************************************************************/    
  //define the datapoint structure and types: IVCurve
  dpName[1]  = makeDynString(\"IVCurve\", \"\", \"\");                  dpType[1] = makeDynInt(DPEL_STRUCT);
  dpName[2]  = makeDynString(\"\", \"Crate\", \"ps_stat_send\", \"\");    dpType[2] = makeDynInt(0, DPEL_TYPEREF);
  dpName[3]  = makeDynString(\"\", \"Channel\", \"ps_stat_send\", \"\");  dpType[3] = makeDynInt(0, DPEL_TYPEREF);
  dpName[4]  = makeDynString(\"\", \"HV_Start\", \"ps_data_send\", \"\"); dpType[4] = makeDynInt(0, DPEL_TYPEREF);
  dpName[5]  = makeDynString(\"\", \"HV_Step\", \"ps_data_send\", \"\");  dpType[5] = makeDynInt(0, DPEL_TYPEREF);
  dpName[6]  = makeDynString(\"\", \"HV_Stop\", \"ps_data_send\", \"\");  dpType[6] = makeDynInt(0, DPEL_TYPEREF);
  dpName[7]  = makeDynString(\"\", \"HV_End\", \"ps_data_send\", \"\");   dpType[7] = makeDynInt(0, DPEL_TYPEREF);
  dpName[8]  = makeDynString(\"\", \"Curr_Max\", \"ps_data_send\", \"\"); dpType[8] = makeDynInt(0, DPEL_TYPEREF);
  dpName[9]  = makeDynString(\"\", \"TimeWait\", \"ps_stat_send\", \"\"); dpType[9] = makeDynInt(0, DPEL_TYPEREF);
  dpName[10] = makeDynString(\"\", \"StartIVCurve\", \"ps_stat_send\", \"\"); 
  dpType[10] = makeDynInt(0, DPEL_TYPEREF);
  dpName[11] = makeDynString(\"\", \"Status\", \"ps_stat_recv\", \"\");  dpType[11] = makeDynInt(0, DPEL_TYPEREF);
  dpName[12] = makeDynString(\"\", \"StartTime\", \"\");               dpType[12] = makeDynInt(0, DPEL_TIME);
  
  //remove the type if exist
  if(dpTypeExists(dpName[1][1]))
  	{
  		deleteDpType(dpName[1][1]);
  	}
  
  //create the above defined type
  dpTypeCreate(dpName, dpType);

  //clear the arrays
  dynClear(dpName);
  dynClear(dpType);

  //create a datapoint of the above defined type
  dpCreate(\"IVCurve\", \"IVCurve\");
  DebugN(\"IVCurve created\");
  
/******************************************************************************************/  
  //define the datapoint structure and types: DCS_IVCurve
  dpName[1] = makeDynString(\"DCS_IVCurve\");      dpType[1] = makeDynInt(DPEL_STRUCT);
  dpName[2] = makeDynString(\"\", \"Name01\");       dpType[2] = makeDynInt(0, DPEL_STRING);
  dpName[3] = makeDynString(\"\", \"Name02\");       dpType[3] = makeDynInt(0, DPEL_STRING);
  dpName[4] = makeDynString(\"\", \"Name03\");       dpType[4] = makeDynInt(0, DPEL_STRING);
  dpName[5] = makeDynString(\"\", \"Name04\");       dpType[5] = makeDynInt(0, DPEL_STRING);
  dpName[6] = makeDynString(\"\", \"Name05\");       dpType[6] = makeDynInt(0, DPEL_STRING);
  dpName[7] = makeDynString(\"\", \"Name06\");       dpType[7] = makeDynInt(0, DPEL_STRING);
  dpName[8] = makeDynString(\"\", \"Name07\");       dpType[8] = makeDynInt(0, DPEL_STRING);
  dpName[9] = makeDynString(\"\", \"Name08\");       dpType[9] = makeDynInt(0, DPEL_STRING);

  
  //remove the type if exist
  if(dpTypeExists(dpName[1][1]))
  	{
  		deleteDpType(dpName[1][1]);
  	}
  
  //create the above defined type
  dpTypeCreate(dpName, dpType);

  //clear the arrays
  dynClear(dpName);
  dynClear(dpType);

  //create a datapoint of the above defined type
  dpCreate(\"IVCurve01\", \"DCS_IVCurve\");
  
  //create the DdcCommand: requestIVCurve (if it does not exist)
  if(!dpExists(\"requestIVCurve\", \"DCS_IVCurve\"))
  	{
  		dpCreate(\"requestIVCurve\", \"DCS_IVCurve\");
  	}
  		DebugN(\"DCS_IVCurve created\");
  		
/******************************************************************************************/   		
  //define the datapoint structure and types: DCS_Cooling
  dpName[1] = makeDynString(\"DCS_Cooling\", \"\");			dpType[1] = makeDynInt(DPEL_STRUCT);
  dpName[2] = makeDynString(\"\", \"Crate_Ramp_Off\");		dpType[2] = makeDynInt(0,DPEL_FLOAT);
  
  //remove the type if exist
  if(dpTypeExists(dpName[1][1]))
  	{
  		deleteDpType(dpName[1][1]);
  	}
  
  //create the above defined type
  dpTypeCreate(dpName, dpType);

  //clear the arrays
  dynClear(dpName);
  dynClear(dpType);

  //create a datapoint of the above defined type
  dpCreate(\"Monitor\", \"DCS_Cooling\");
	DebugN(\"DCS_Cooling created\");

//******************************************************************************************/ 
//define the datapoint structure and types: DCS_Hist
index=1;
  dpName[index] = makeDynString(\"DCS_Hist\",\"\");		dpType[index++] = makeDynInt(DPEL_STRUCT);
for(i=0; i<=8; i++)
	{
	sprintf(num, \"%02d\", i);
	dpName[index] = makeDynString(\"\",\"Name\" + num);   dpType[index++] = makeDynInt(0, DPEL_STRING);
	dpName[index] = makeDynString(\"\",\"Bins\" + num);   dpType[index++] = makeDynInt(0, DPEL_INT);
	dpName[index] = makeDynString(\"\",\"Hour\" + num);   dpType[index++] = makeDynInt(0, DPEL_INT);
	}
 
  //remove the type if exist
  if(dpTypeExists(dpName[1][1]))
  	{
  		deleteDpType(dpName[1][1]);
  	}

  //create the above defined type
  dpTypeCreate(dpName, dpType);

  //clear the arrays
  dynClear(dpName);
  dynClear(dpType);

  //create a datapoint of the above defined type
  for(i=1; i<=16; i++)  {
	sprintf(num, \"%02d\", i);
	dpCreate(\"Hist\" + num, \"DCS_Hist\");
	}
	DebugN(\"DCS_Hist created\");
 
//******************************************************************************************/ 
//define the datapoint structure and types: DCS_Settings
  dpName[1] = makeDynString(\"DCS_Settings\", \"\");	dpType[1] = makeDynInt(DPEL_STRUCT);
  dpName[2] = makeDynString(\"\", \"Name\");			dpType[2] = makeDynInt(0, DPEL_STRING);
  dpName[3] = makeDynString(\"\", \"Indx\");			dpType[3] = makeDynInt(0, DPEL_INT);
  dpName[4] = makeDynString(\"\", \"Stat\");			dpType[4] = makeDynInt(0, DPEL_UINT);
  dpName[5] = makeDynString(\"\", \"Data\");			dpType[5] = makeDynInt(0, DPEL_FLOAT);
  dpName[6] = makeDynString(\"\", \"Numb\");			dpType[6] = makeDynInt(0, DPEL_UINT);
	
  //remove the type if exist
  if(dpTypeExists(dpName[1][1]))
  	{
  		deleteDpType(dpName[1][1]);
  	}

  //create the above defined type
  dpTypeCreate(dpName, dpType);

  //clear the arrays
  dynClear(dpName);
  dynClear(dpType);

  //create a datapoint of the above defined type
	dpCreate(\"Func\", \"DCS_Settings\");
	dpCreate(\"Quer\", \"DCS_Settings\");
	dpCreate(\"Sgot\", \"DCS_Settings\");
	dpCreate(\"Sput\", \"DCS_Settings\");
	dpCreate(\"Arch\", \"DCS_Settings\");
	dpCreate(\"Busy\", \"DCS_Settings\");
	dpCreate(\"Eror\", \"DCS_Settings\");
	dpCreate(\"Hist\", \"DCS_Settings\");
	dpCreate(\"HVol\", \"DCS_Settings\");
	dpCreate(\"LVol\", \"DCS_Settings\");
	dpCreate(\"Mang\", \"DCS_Settings\");
	dpCreate(\"Moni\", \"DCS_Settings\");
	dpCreate(\"Next\", \"DCS_Settings\");
	dpCreate(\"Plot\", \"DCS_Settings\");
	dpCreate(\"Syst\", \"DCS_Settings\");
	dpCreate(\"Alrm\", \"DCS_Settings\");
	dpCreate(\"Chan\", \"DCS_Settings\");
	dpCreate(\"Cmax\", \"DCS_Settings\");
	dpCreate(\"Curv\", \"DCS_Settings\");
	dpCreate(\"Eout\", \"DCS_Settings\");
	dpCreate(\"Fatl\", \"DCS_Settings\");
	dpCreate(\"Find\", \"DCS_Settings\");
	dpCreate(\"Indi\", \"DCS_Settings\");
	dpCreate(\"Hmax\", \"DCS_Settings\");
	dpCreate(\"Host\", \"DCS_Settings\");
	dpCreate(\"Iinp\", \"DCS_Settings\");
	dpCreate(\"Iout\", \"DCS_Settings\");
	dpCreate(\"Lmax\", \"DCS_Settings\");
	dpCreate(\"Nmax\", \"DCS_Settings\");
	dpCreate(\"Node\", \"DCS_Settings\");
	dpCreate(\"Norm\", \"DCS_Settings\");
	dpCreate(\"Para\", \"DCS_Settings\");
	dpCreate(\"Pmax\", \"DCS_Settings\");
	dpCreate(\"Pmon\", \"DCS_Settings\");
	dpCreate(\"Port\", \"DCS_Settings\");
	dpCreate(\"Scan\", \"DCS_Settings\");
	dpCreate(\"Srun\", \"DCS_Settings\");
	dpCreate(\"Umax\", \"DCS_Settings\");
	dpCreate(\"Unit\", \"DCS_Settings\");
	dpCreate(\"Warn\", \"DCS_Settings\");
	dpCreate(\"LVch\", \"DCS_Settings\");
	dpCreate(\"LVch_max\", \"DCS_Settings\");
	dpCreate(\"HVch\", \"DCS_Settings\");
	dpCreate(\"HVch_max\", \"DCS_Settings\");
	dpCreate(\"LVca_max\", \"DCS_Settings\");
	dpCreate(\"HVca\", \"DCS_Settings\");
	dpCreate(\"HVca_max\", \"DCS_Settings\");
	dpCreate(\"Crate\", \"DCS_Settings\");
	dpCreate(\"CRpa_max\", \"DCS_Settings\");
	
	DebugN(\"DCS_Settings created\");	

//******************************************************************************************/ 
//define the datapoint structure and types:	DCS_Limi
  dpName[1] = makeDynString(\"DCS_Limi\", \"\");	dpType[1] = makeDynInt(DPEL_STRUCT);
  dpName[2] = makeDynString(\"\", \"Name\");		dpType[2] = makeDynInt(0, DPEL_STRING);
  dpName[3] = makeDynString(\"\", \"Delt\");		dpType[3] = makeDynInt(0, DPEL_FLOAT);
  dpName[4] = makeDynString(\"\", \"AlrL\");		dpType[4] = makeDynInt(0, DPEL_FLOAT);
  dpName[5] = makeDynString(\"\", \"WarL\");		dpType[5] = makeDynInt(0, DPEL_FLOAT);
  dpName[6] = makeDynString(\"\", \"Norm\");		dpType[6] = makeDynInt(0, DPEL_FLOAT);
  dpName[7] = makeDynString(\"\", \"WarH\");		dpType[7] = makeDynInt(0, DPEL_FLOAT);
  dpName[8] = makeDynString(\"\", \"AlrH\");		dpType[8] = makeDynInt(0, DPEL_FLOAT);
  	
  //remove the type if exist
  if(dpTypeExists(dpName[1][1]))
  	{
  		deleteDpType(dpName[1][1]);
  	}

  //create the above defined type
  dpTypeCreate(dpName, dpType);

  //clear the arrays
  dynClear(dpName);
  dynClear(dpType);

  //create a datapoint of the above defined type
  for(i=0; i<=16; i++)
  	{
	sprintf(num, \"%02d\", i);
	dpCreate(\"Limi\" + num, \"DCS_Limi\");
	}
	DebugN(\"DCS_Limi created\");
	
//******************************************************************************************/ 
//define the datapoint structure and types:	DdcCommand
  dpName[1]  = makeDynString(\"DdcCommand\", \"\");	dpType[1]  = makeDynInt(DPEL_STRUCT);
  dpName[2]  = makeDynString(\"\", \"trigger\");	dpType[2]  = makeDynInt(0, DPEL_BOOL);
  dpName[3]  = makeDynString(\"\", \"parameters\");	dpType[3]  = makeDynInt(0, DPEL_STRING);
  dpName[4]  = makeDynString(\"\", \"response\");	dpType[4]  = makeDynInt(0, DPEL_INT);
  dpName[5]  = makeDynString(\"\", \"Hold\");		dpType[5]  = makeDynInt(0, DPEL_UINT);
  dpName[6]  = makeDynString(\"\", \"Req1\");		dpType[6]  = makeDynInt(0, DPEL_UINT);
  dpName[7]  = makeDynString(\"\", \"Req2\");		dpType[7]  = makeDynInt(0, DPEL_UINT);
  dpName[8]  = makeDynString(\"\", \"Req3\");		dpType[8]  = makeDynInt(0, DPEL_UINT);
  dpName[9]  = makeDynString(\"\", \"Req4\");		dpType[9]  = makeDynInt(0, DPEL_UINT);
  dpName[10] = makeDynString(\"\", \"Next\");		dpType[10] = makeDynInt(0, DPEL_UINT);
 	
  //remove the type if exist
  if(dpTypeExists(dpName[1][1]))
  	{
  		deleteDpType(dpName[1][1]);
  	}

  //create the above defined type
  dpTypeCreate(dpName, dpType);

  //clear the arrays
  dynClear(dpName);
  dynClear(dpType);

  //create a datapoint of the above defined type
	dpCreate(\"SendData\", \"DdcCommand\");
	dpCreate(\"SendRequ\", \"DdcCommand\");
	dpCreate(\"SendStat\", \"DdcCommand\");
	dpCreate(\"TakeStat\", \"DdcCommand\");
	dpCreate(\"example\", \"DdcCommand\");
	dpCreate(\"ChangeState\", \"DdcCommand\");
	dpCreate(\"IVcurve\", \"DdcCommand\");
	dpCreate(\"setTestData\", \"DdcCommand\");
	dpCreate(\"requestIVCurve\", \"DdcCommand\");

	DebugN(\"DdcCommand created\");

//******************************************************************************************/ 
//define the datapoint structure and types:	DCS_Plot
index=1;
  dpName[index] = makeDynString(\"DCS_Plot\",\"\");			dpType[index++] = makeDynInt(DPEL_STRUCT);
 
  for(i=0; i<=16; i++) {
	sprintf(num, \"%02d\", i);
	dpName[index] = makeDynString(\"\",\"Name\" + num);		dpType[index++] = makeDynInt(0, DPEL_STRING);
	}
  for(i=1; i<=5; i++)
	{
	sprintf(num, \"%d\", i);
	dpName[index] = makeDynString(\"\",\"NameL\" + num);	dpType[index++] = makeDynInt(0, DPEL_STRING);
	dpName[index] = makeDynString(\"\",\"IndxL\" + num);	dpType[index++] = makeDynInt(0, DPEL_INT);
	}
	dpName[index] = makeDynString(\"\",\"File\");			dpType[index++] = makeDynInt(0, DPEL_INT);
 	
  //remove the type if exist
  if(dpTypeExists(dpName[1][1]))
  	{
  		deleteDpType(dpName[1][1]);
  	}

  //create the above defined type
  dpTypeCreate(dpName, dpType);

  //clear the arrays
  dynClear(dpName);
  dynClear(dpType);

  //create a datapoint of the above defined type
  for(i=0; i<=16; i++)
	{
	sprintf(num, \"%02d\", i);
	dpCreate(\"Plot\" + num, \"DCS_Plot\");
	}
	DebugN(\"DCS_Plot created\");


//******************************************************************************************/ 
//define the datapoint structure and types:	DCS_Indi

index=1;
  dpName[index] = makeDynString(\"DCS_Indi\",\"\");			dpType[index++] = makeDynInt(DPEL_STRUCT);
 
  for(i=0; i<=48; i++)
	{
	sprintf(num, \"%02d\", i);
	dpName[index] = makeDynString(\"\",\"Name\" + num);		dpType[index++] = makeDynInt(0, DPEL_STRING);
	}
  for(i=1; i<=5; i++)
 	{
	sprintf(num, \"%d\", i);
	dpName[index] = makeDynString(\"\",\"NameL\" + num);	dpType[index++] = makeDynInt(0, DPEL_STRING);
	dpName[index] = makeDynString(\"\",\"IndxL\" + num);	dpType[index++] = makeDynInt(0, DPEL_INT);
	}
	dpName[index] = makeDynString(\"\",\"File\");			dpType[index++] = makeDynInt(0, DPEL_INT);
 	
  //remove the type if exist
  if(dpTypeExists(dpName[1][1]))
  	{
  		deleteDpType(dpName[1][1]);
  	}

  //create the above defined type
  dpTypeCreate(dpName, dpType);

  //clear the arrays
  dynClear(dpName);
  dynClear(dpType);

  //create a datapoint of the above defined type
  for(i=0; i<=16; i++)
	{
	sprintf(num, \"%02d\", i);
	dpCreate(\"Indi\" + num, \"DCS_Indi\");
	}
	DebugN(\"DCS_Indi created\");


//******************************************************************************************/ 
//define the datapoint structure and types:	gp_chan
  dpName[1]  = makeDynString(\"gp_chan\", \"\");	dpType[1]  = makeDynInt(DPEL_STRUCT);
  dpName[2]  = makeDynString(\"\", \"Stat\");		dpType[2]  = makeDynInt(0, DPEL_UINT);
  dpName[3]  = makeDynString(\"\", \"Name\");		dpType[3]  = makeDynInt(0, DPEL_STRING);
  dpName[4]  = makeDynString(\"\", \"Iden\");		dpType[4]  = makeDynInt(0, DPEL_STRING);
  dpName[5]  = makeDynString(\"\", \"Data\");		dpType[5]  = makeDynInt(0, DPEL_FLOAT);
  dpName[6]  = makeDynString(\"\", \"RawV\");		dpType[6]  = makeDynInt(0, DPEL_INT);
  dpName[7]  = makeDynString(\"\", \"CalA\");		dpType[7]  = makeDynInt(0, DPEL_FLOAT);
  dpName[8]  = makeDynString(\"\", \"CalB\");		dpType[8]  = makeDynInt(0, DPEL_FLOAT);
  dpName[9]  = makeDynString(\"\", \"CalC\");		dpType[9]  = makeDynInt(0, DPEL_FLOAT);
  dpName[10] = makeDynString(\"\", \"CalD\");		dpType[10] = makeDynInt(0, DPEL_FLOAT);
  dpName[11] = makeDynString(\"\", \"CalE\");		dpType[11] = makeDynInt(0, DPEL_FLOAT);
  dpName[12] = makeDynString(\"\", \"CalR\");		dpType[12] = makeDynInt(0, DPEL_FLOAT);
  dpName[13] = makeDynString(\"\", \"Conv\");		dpType[13] = makeDynInt(0, DPEL_FLOAT);
  dpName[14] = makeDynString(\"\", \"Cref\");		dpType[14] = makeDynInt(0, DPEL_FLOAT);
  dpName[15] = makeDynString(\"\", \"Limi\");		dpType[15] = makeDynInt(0, DPEL_FLOAT);
	 	
  //remove the type if exist
  if(dpTypeExists(dpName[1][1]))
  	{
  		deleteDpType(dpName[1][1]);
  	}

  //create the above defined type
  dpTypeCreate(dpName, dpType); 

  //clear the arrays
  dynClear(dpName);
  dynClear(dpType);

  //create a datapoint of the above defined type
//	dpCreate(\"\", \"gp_chan\");
	DebugN(\"gp_chan created\");
	
//******************************************************************************************/ 
//define the datapoint structure and types:	gp_port
  dpName[1] = makeDynString(\"gp_port\", \"\");	dpType[1] = makeDynInt(DPEL_STRUCT);
  dpName[2] = makeDynString(\"\", \"Stat\");	dpType[2] = makeDynInt(0, DPEL_UINT);
  dpName[3] = makeDynString(\"\", \"Name\");	dpType[3] = makeDynInt(0, DPEL_STRING);
  dpName[4] = makeDynString(\"\", \"Iden\");	dpType[4] = makeDynInt(0, DPEL_STRING);
  dpName[5] = makeDynString(\"\", \"Baud\");	dpType[5] = makeDynInt(0, DPEL_INT);

  //remove the type if exist
  if(dpTypeExists(dpName[1][1]))
  	{
  		deleteDpType(dpName[1][1]);
  	}

  //create the above defined type
  dpTypeCreate(dpName, dpType);

  //clear the arrays
  dynClear(dpName);
  dynClear(dpType);

  //create a datapoint of the above defined type
//	dpCreate(\"\", \"gp_port\");
	DebugN(\"gp_port created\");
	
//******************************************************************************************/ 
//define the datapoint structure and types:	gp_node
  dpName[1] = makeDynString(\"gp_node\", \"\");				dpType[1] = makeDynInt(DPEL_STRUCT);
  dpName[2] = makeDynString(\"\", \"Port00\", \"gp_port\");	dpType[2] = makeDynInt(0, DPEL_TYPEREF);
  dpName[3] = makeDynString(\"\", \"Port01\", \"gp_port\");	dpType[3] = makeDynInt(0, DPEL_TYPEREF);
  dpName[4] = makeDynString(\"\", \"Stat\", \"\");			dpType[4] = makeDynInt(0, DPEL_UINT);
  dpName[5] = makeDynString(\"\", \"Name\", \"\");			dpType[5] = makeDynInt(0, DPEL_STRING);
  dpName[6] = makeDynString(\"\", \"Iden\", \"\");			dpType[6] = makeDynInt(0, DPEL_STRING);
  dpName[7] = makeDynString(\"\", \"Queu\", \"\");			dpType[7] = makeDynInt(0, DPEL_INT);
  dpName[8] = makeDynString(\"\", \"Tout\", \"\");			dpType[8] = makeDynInt(0, DPEL_INT);

  //remove the type if exist
  if(dpTypeExists(dpName[1][1]))
  	{
  		deleteDpType(dpName[1][1]);
  	}

  //create the above defined type
  dpTypeCreate(dpName, dpType);

  //clear the arrays
  dynClear(dpName);
  dynClear(dpType);

  //create a datapoint of the above defined type
//	dpCreate(\"\", \"gp_node\");
	DebugN(\"gp_node created\");
	
//******************************************************************************************/ 
//define the datapoint structure and types:	DCS_Host
  dpName[1] = makeDynString(\"DCS_Host\", \"\");			dpType[1] = makeDynInt(DPEL_STRUCT);
  dpName[2] = makeDynString(\"\", \"Node00\", \"gp_node\");	dpType[2] = makeDynInt(0, DPEL_TYPEREF);
  dpName[3] = makeDynString(\"\", \"Stat\", \"\");			dpType[3] = makeDynInt(0, DPEL_UINT);
  dpName[4] = makeDynString(\"\", \"Name\", \"\");			dpType[4] = makeDynInt(0, DPEL_STRING);
  dpName[5] = makeDynString(\"\", \"Iden\", \"\");			dpType[5] = makeDynInt(0, DPEL_STRING);
  dpName[6] = makeDynString(\"\", \"Pmon\", \"\");			dpType[6] = makeDynInt(0, DPEL_INT);
  dpName[7] = makeDynString(\"\", \"Scan\", \"\");			dpType[7] = makeDynInt(0, DPEL_INT);
  dpName[8] = makeDynString(\"\", \"Simu\", \"\");			dpType[8] = makeDynInt(0, DPEL_INT);
  dpName[9] = makeDynString(\"\", \"Tout\", \"\");			dpType[9] = makeDynInt(0, DPEL_INT);
  
   //remove the type if exist
  if(dpTypeExists(dpName[1][1]))
  	{
  		deleteDpType(dpName[1][1]);
  	}

  //create the above defined type
  dpTypeCreate(dpName, dpType);

  //clear the arrays
  dynClear(dpName);
  dynClear(dpType);

  //create a datapoint of the above defined type
	dpCreate(\"Host01\", \"DCS_Host\");
	DebugN(\"DCS_Host created\"); 
  
//******************************************************************************************/ 
//define the datapoint structure and types:	DCS_Unit

  index=1;
  dpName[index] = makeDynString(\"DCS_Unit\", \"\");				dpType[index++] = makeDynInt(DPEL_STRUCT);
  
  for(i=0; i<=47; i++)
	{
	sprintf(num, \"%02d\", i);
	dpName[index] = makeDynString(\"\",\"Chan\" + num, \"gp_chan\");	dpType[index++] = makeDynInt(0, DPEL_TYPEREF);
	}
	dpName[index] = makeDynString(\"\",\"Chan99\", \"gp_chan\");		dpType[index++] = makeDynInt(0, DPEL_TYPEREF);
	dpName[index] = makeDynString(\"\",\"Stat\");					dpType[index++] = makeDynInt(0, DPEL_UINT);
	dpName[index] = makeDynString(\"\",\"Name\");					dpType[index++] = makeDynInt(0, DPEL_STRING);
	dpName[index] = makeDynString(\"\",\"Iden\");					dpType[index++] = makeDynInt(0, DPEL_STRING);
	dpName[index] = makeDynString(\"\",\"Vadc\");					dpType[index++] = makeDynInt(0, DPEL_FLOAT);
	
   //remove the type if exist
  if(dpTypeExists(dpName[1][1]))
  	{
 		deleteDpType(dpName[1][1]);
  	}

  //create the above defined type
  dpTypeCreate(dpName, dpType);

  //clear the arrays
  dynClear(dpName);
  dynClear(dpType);

  //create a datapoint of the above defined type
//	dpCreate(\"\", \"DCS_Unit\");
	DebugN(\"DCS_Unit created\"); 	

//******************************************************************************************/ 
//define the datapoint structure and types:	ErrorMesg
  dpName[1] = makeDynString(\"ErrorMesg\", \"\");	dpType[1] = makeDynInt(DPEL_STRUCT);

   //remove the type if exist
  if(dpTypeExists(dpName[1][1]))
  	{
 		deleteDpType(dpName[1][1]);
  	}

  //create the above defined type
  dpTypeCreate(dpName, dpType);

  //clear the arrays
  dynClear(dpName);
  dynClear(dpType);

  //create a datapoint of the above defined type
	dpCreate(\"INFO\", \"ErrorMesg\");
	DebugN(\"ErrorMesg created\");
	
//******************************************************************************************/ 
//define the datapoint structure and types:	ps_iv_send
  dpName[1] = makeDynString(\"ps_iv_send\", \"\");	dpType[1] = makeDynInt(DPEL_STRUCT);
  dpName[2] = makeDynString(\"\", \"Stat\");		dpType[2] = makeDynInt(0, DPEL_INT);
  dpName[3] = makeDynString(\"\", \"Start\");		dpType[3] = makeDynInt(0, DPEL_INT);
  dpName[4] = makeDynString(\"\", \"Stop\");		dpType[4] = makeDynInt(0, DPEL_INT);
  dpName[5] = makeDynString(\"\", \"Step\");		dpType[5] = makeDynInt(0, DPEL_INT);
  dpName[6] = makeDynString(\"\", \"End\");			dpType[6] = makeDynInt(0, DPEL_INT);
  dpName[7] = makeDynString(\"\", \"Imax\");		dpType[7] = makeDynInt(0, DPEL_INT);
  dpName[8] = makeDynString(\"\", \"Iwarn\");		dpType[8] = makeDynInt(0, DPEL_INT);
  dpName[9] = makeDynString(\"\", \"Twait\");		dpType[9] = makeDynInt(0, DPEL_INT);

   //remove the type if exist
  if(dpTypeExists(dpName[1][1]))
  	{
 		deleteDpType(dpName[1][1]);
  	}

  //create the above defined type
  dpTypeCreate(dpName, dpType);

  //clear the arrays
  dynClear(dpName);
  dynClear(dpType);

  //create a datapoint of the above defined type
	dpCreate(\"INFO\", \"ps_iv_send\");
	DebugN(\"ps_iv_send created\");
	


//******************************************************************************************/ 
//define the datapoint structure and types:	MPS_Testing
  dpName[1]  = makeDynString(\"MPS_Testing\", \"\");	dpType[1]  = makeDynInt(DPEL_STRUCT);
  dpName[2]  = makeDynString(\"\", \"Vcc\", \"\");		dpType[2]  = makeDynInt(0, DPEL_STRUCT);
  dpName[3]  = makeDynString(\"\", \"\", \"Low\");		dpType[3]  = makeDynInt(0, 0, DPEL_FLOAT);
  dpName[4]  = makeDynString(\"\", \"\", \"High\");		dpType[4]  = makeDynInt(0, 0, DPEL_FLOAT);
  dpName[5]  = makeDynString(\"\", \"Vdd\", \"\");		dpType[5]  = makeDynInt(0, DPEL_STRUCT);
  dpName[6]  = makeDynString(\"\", \"\", \"Low\");		dpType[6]  = makeDynInt(0, 0, DPEL_FLOAT);
  dpName[7]  = makeDynString(\"\", \"\", \"High\");		dpType[7]  = makeDynInt(0, 0, DPEL_FLOAT);
  dpName[8]  = makeDynString(\"\", \"VCSL\", \"\");		dpType[8]  = makeDynInt(0, DPEL_STRUCT);
  dpName[9]  = makeDynString(\"\", \"\", \"Low\");		dpType[9]  = makeDynInt(0, 0, DPEL_FLOAT);
  dpName[10] = makeDynString(\"\", \"\", \"High\");		dpType[10] = makeDynInt(0, 0, DPEL_FLOAT);
  dpName[11] = makeDynString(\"\", \"PINV\", \"\");		dpType[11] = makeDynInt(0, DPEL_STRUCT);
  dpName[12] = makeDynString(\"\", \"\", \"Low\");		dpType[12] = makeDynInt(0, 0, DPEL_FLOAT);
  dpName[13] = makeDynString(\"\", \"\", \"High\");		dpType[13] = makeDynInt(0, 0, DPEL_FLOAT);
  dpName[14] = makeDynString(\"\", \"HV\", \"\");			dpType[14] = makeDynInt(0, DPEL_STRUCT);
  dpName[15] = makeDynString(\"\", \"\", \"Low\");		dpType[15] = makeDynInt(0, 0, DPEL_FLOAT);
  dpName[16] = makeDynString(\"\", \"\", \"High\");		dpType[16] = makeDynInt(0, 0, DPEL_FLOAT);

   //remove the type if exist
  if(dpTypeExists(dpName[1][1]))
  	{
 		deleteDpType(dpName[1][1]);
  	}

  //create the above defined type
  dpTypeCreate(dpName, dpType);

  //clear the arrays
  dynClear(dpName);
  dynClear(dpType);

  //create a datapoint of the above defined type
	dpCreate(\"LTT\", \"MPS_Testing\");
	DebugN(\"MPS_Testing created\");


/******************************************************************************************/      
//define the datapoint structure and types: MPS_Crates
  index=1;
  count=0;
  dpName[index] = makeDynString(\"MPS_Crates\", \"\");						dpType[index++] = makeDynInt(DPEL_STRUCT);
  for (i=0; i<6; i++) 
  	{
	for (j=0; j<=7; j++)
		{
		sprintf(chan, \"Channel%02d\", count);
		dpName[index] = makeDynString(\"\", chan, \"ps_chan\", \"\");			dpType[index++] = makeDynInt(0, DPEL_TYPEREF);
  		DebugN(chan);
		count++;
		}
	sprintf(LV, \"LV_card%02d\", 2*i);
	dpName[index] = makeDynString(\"\", LV, \"lv_card\", \"\");				dpType[index++] = makeDynInt(0, DPEL_TYPEREF);
    DebugN(LV);
	sprintf(HV, \"HV_card%02d\", i);
	dpName[index] = makeDynString(\"\", HV, \"hv_card\", \"\");				dpType[index++] = makeDynInt(0, DPEL_TYPEREF);
	DebugN(HV);
	sprintf(LV, \"LV_card%02d\", 2*i+1);
	dpName[index] = makeDynString(\"\", LV, \"lv_card\", \"\");				dpType[index++] = makeDynInt(0, DPEL_TYPEREF);	
    DebugN(LV);
	}
  dpName[index] = makeDynString(\"\", \"Controller\", \"ps_crate\",\"\");	dpType[index++] = makeDynInt(0, DPEL_TYPEREF);
  dpName[index] = makeDynString(\"\", \"Stat\", \"\", \"\");					dpType[index++] = makeDynInt(0, DPEL_UINT);
  dpName[index] = makeDynString(\"\", \"WarnMesg\", \"ps_alert\", \"\");		dpType[index++] = makeDynInt(0, DPEL_TYPEREF);
  dpName[index] = makeDynString(\"\", \"FatlMesg\", \"ps_alert\", \"\");		dpType[index++] = makeDynInt(0, DPEL_TYPEREF);
  
  //remove the type if exist
  if(dpTypeExists(dpName[1][1]))
  	{
  		deleteDpType(dpName[1][1]);
  	}
  
  //create the above defined type
  dpTypeCreate(dpName, dpType);

  //clear the arrays
  dynClear(dpName);
  dynClear(dpType);

// Getting the number of crates 
	getSyst(UnitMax);

  //create a datapoint of the above defined type
 for(i=0; i<UnitMax; i++)
	{
	sprintf(Crate, \"Crate%02d\", i);
	dpCreate(Crate, \"MPS_Crates\");
	}
  
	DebugN(\"MPS_Crates created\");


	
	  setValue(\"\",\"foreCol\",\"\");
}
/****************************************END*******************************\\  
\\**************************************************************************/

/****************************************************************************\\
|* This function gets info about the system from the file Cnf_Syst.txt		*|
|* for the moment we are only using the Max number of crates UnitMax		*|
\\****************************************************************************/
int getSyst(int & UnitMax)
{
int err, Index, HostMax, NodeMax, PortMax, ChanMax,	LVparaMax,
		HVparaMax, lvCAparaMax, hvCAparaMax, CRparaMax, LimiMax;
file syst;
string raw, path, Comment, sys;

sys = getSystemName();

  /* open Cnf_Syst.txt file */
	path = getPath(PANELS_REL_PATH, \"Cnf_Syst.txt\");
	syst = fopen(path,\"r\");
	fgets( raw, 300, syst );

  /* detecting the number of the crates: UnitMax*/
	DebugN(\"Reading Cnf_Syst.txt file. *-*-*-*-*-*-*-*-*-*-*-*\");
	fgets( raw, 300, syst );
	sscanf(raw, \"%d %d %d %d %d %d %d %d %d %d %d %d %s \",
				Index, HostMax, NodeMax, PortMax, UnitMax, ChanMax, LVparaMax,
				HVparaMax, lvCAparaMax, hvCAparaMax, CRparaMax, LimiMax, Comment);

     dpSet(sys+\"Hmax.Numb:_original.._value\", HostMax);
     dpSet(sys+\"Nmax.Numb:_original.._value\", NodeMax);
     dpSet(sys+\"Pmax.Numb:_original.._value\", PortMax);
     dpSet(sys+\"Umax.Numb:_original.._value\", UnitMax);
     dpSet(sys+\"Cmax.Numb:_original.._value\", ChanMax);
     dpSet(sys+\"LVch_max.Numb:_original.._value\", LVparaMax);
     dpSet(sys+\"HVch_max.Numb:_original.._value\", HVparaMax);
     dpSet(sys+\"LVca_max.Numb:_original.._value\", lvCAparaMax);
     dpSet(sys+\"HVca_max.Numb:_original.._value\", hvCAparaMax);
     dpSet(sys+\"CRpa_max.Numb:_original.._value\", CRparaMax);
     dpSet(sys+\"Lmax.Numb:_original.._value\", LimiMax);

  /* close Cnf_Syst.txt file */
	err=ferror(syst); // export error
	fclose(syst); // close file
	if (err!=0) 
		{
		DebugN(\"Error no. \",err,\" occurred\");
		return 0;
		}
  return 1;
}

//this subroutine check the existence of a given type
bool dpTypeExists(string dpType)
{
  int index;
  dyn_string dpAllTypes;
  
  //get all types
  dpAllTypes = dpTypes();
  
  //check the existence of the given type 
  for(index=1; index<=dynlen(dpAllTypes); index++)
  	{
  		if(dpAllTypes[index] == dpType) return 1;
  	}
  
  return 0;
}

//this subroutine deletes a given type. to do so, it deletes all the datapoint of this type
//then delete the type
deleteDpType(string dpType)
{
  int index;
  dyn_string dpAllNames;
  
  //get all datapoint of the given type
  dpAllNames = dpNames(\"*\", dpType);
  
  //delete all the datapoint of the given type
  for(index=1; index<=dynlen(dpAllNames); index++)
  	{
  		dpDelete(dpAllNames[index]);
  	}
  
  //delete the type
  dpTypeDelete(dpType);
}" 0
 E E E
13 27
"Button2"
""
1 40 200 E E E 1 E 1 E N "_3DText" E N {102,204,255} E E
 E E
23 0 0 0 0 0
EE E
0
1
LANG:1 0 
0
1
LANG:1 105 -microsoft windows-Arial-bold-r-normal-*-*-140-100-100-*-*-iso8859-1|-16,0,0,0,700,0,0,0,0,3,2,1,34,Arial
0 ""
38 198 272 262
T 
1
LANG:1 11 Load Alerts
"//Load Alerts
/******************************************************************************\\
123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789
|*=====================================-======================================*|
|*			               SCT POWER SUPPLIES MODULES     		              *|
|*=====================================-======================================*|
|*   AUTHORs:        G.Codispoti - codispoti@cs.infn.it			    		  *|
|*								   Giuseppe.Codispoti@cern.ch			      *|
|*																		      *|
|*   DESIGN ISSUEs:  This Script add DPe alerts loading them from several 	  *|
|*   				 configuration files and set conversions using	 		  *|
|*   				 the function \"Conversion\".								  *|
|*																		      *|
|*   MODIF_HISTORY:  17.03.2003  - first release						      *|
|*																		      *|
\\******************************************************************************/
main()
{
file crate, card, par;
int err, i, Index, HostMax, NodeMax, PortMax, UnitMax, ChanMax, LVparaMax,
	HVparaMax, lvCAparaMax, hvCAparaMax, CRparaMax, LimiMax;
string raw, path, status, Comment;

status = \"off\";
setValue(\"\",\"foreCol\",\"Red\");

  /* use Cnf_Syst.txt file */
	UnitMax = 0;
	getSyst(UnitMax);
	if (!UnitMax)
		{
		DebugN(\"Error! Unknown Number of Crates\");
		return;
		}
	
  /* setting conversion for all crates */ 
	getConversion(UnitMax);
	DebugN(\"Setting Conversions...\");
	
  /* open Cnf_Crate.txt file */
	path = getPath(PANELS_REL_PATH, \"Cnf_Crate.txt\");
	crate = fopen(path,\"r\");
	err=ferror(crate); // export error
	if (err!=0) DebugN(\"Error no. \",err,\" occurred\");

  /* open Cnf_Card.txt file */
	path = getPath(PANELS_REL_PATH, \"Cnf_Card.txt\");
	card = fopen(path,\"r\");
	err=ferror(card); // export error
	if (err!=0) DebugN(\"Error no. \",err,\" occurred\");

  /* open Cnf_Para.txt file */	
	path = getPath(PANELS_REL_PATH, \"Cnf_Para.txt\");
	par = fopen(path,\"r\");
	err=ferror(par); // export error
	if (err!=0) DebugN(\"Error no. \",err,\" occurred\");

  /* excluding first line of both files */
	fgets( raw, 300, crate );
	fgets( raw, 300, card );
	fgets( raw, 300, par );

  /* setting crate alerts */
	DebugN(\"Reading Cnf_Crate.txt file. *-*-*-*-*-*-*-*-*-*-*-*\");
	while( fgets( raw, 300, crate))
	  {
	  strreplace( raw, \"\\\"\", \"\");
	  strreplace( raw, \"\\t\", \" \");
	//  DebugN(raw);
	  crateSet( raw, status, UnitMax );
	  }

  /* setting card alerts */
	DebugN(\"Reading Cnf_Card.txt file. *-*-*-*-*-*-*-*-*-*-*-*\");
	while( fgets( raw, 300, card))
	  {
	  strreplace( raw, \"\\\"\", \"\");
	  strreplace( raw, \"\\t\", \" \");
	//  DebugN(raw);
	  cardSet( raw, status, UnitMax );
	  }
	
  /* setting channel alerts */
	DebugN(\"Reading Cnf_Para.txt file. *-*-*-*-*-*-*-*-*-*-*-*\");
	while( fgets( raw, 300, par) )  
	{
	  strreplace( raw, \"\\\"\", \"\");
	  strreplace( raw, \"\\t\", \" \");
	//  DebugN(raw);
	  channelSet( raw, status, UnitMax );
	}

/* close files */
fclose(crate);
fclose(card);
fclose(par);
setValue(\"\",\"foreCol\",\"\");
}


/**************************************************************************\\
|* The following function splits the string from the Cnf_Crate.txt file   *|
|* giving back the setting values for every crate.                        *|
\\**************************************************************************/
void crateSet(string raw, string status, int UnitMax)
{
int ID,	Rack, Crate, Host, Node, Port, Unit;
string Para, EoN, EoA, EoO, EoS, Comment, dpName, module,
        s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13,
        s14, s15, s16, s17, s18, s19, s20, s21, s22;
float FatlL_Off, WarnL_Off,	Norm_Off, WarnH_Off, FatlH_Off,
	  FatlL_Stb, WarnL_Stb, Norm_Stb, WarnH_Stb, FatlH_Stb,
	  FatlL_On,	 WarnL_On,	Norm_On,  WarnH_On,	 FatlH_On;

sscanf(raw,
       \"%s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s\",
        s1, s2, s3, Para, EoN, s4, s5, s6, s7, EoA, s8, s9, s10, s11, s12, EoO,
        s13, s14, s15, s16, s17, EoS, s18, s19, s20, s21, s22, Comment);

sscanf(s1,  \"%d\", ID);
sscanf(s2,  \"%d\", Rack);
sscanf(s3,  \"%d\", Crate);
sscanf(s4,  \"%d\", Host);
sscanf(s5,  \"%d\", Node);
sscanf(s6,  \"%d\", Port);
sscanf(s7,  \"%d\", Unit);
sscanf(s8,  \"%f\", FatlL_Off);
sscanf(s9, \"%f\", WarnL_Off);
sscanf(s10, \"%f\", Norm_Off);
sscanf(s11, \"%f\", WarnH_Off);
sscanf(s12, \"%f\", FatlH_Off);
sscanf(s13, \"%f\", FatlL_Stb);
sscanf(s14, \"%f\", WarnL_Stb);
sscanf(s15, \"%f\", Norm_Stb);
sscanf(s16, \"%f\", WarnH_Stb);
sscanf(s17, \"%f\", FatlH_Stb);
sscanf(s18, \"%f\", FatlL_On);
sscanf(s19, \"%f\", WarnL_On);
sscanf(s20, \"%f\", Norm_On);
sscanf(s21, \"%f\", WarnH_On);
sscanf(s22, \"%f\", FatlH_On);

/*  DebugN(s1, s2, s3, Para, EoN, s4, s5, s6, s7, EoA, s8, s9, s10, s11, s12, EoO,
        s13, s14, s15, s16, s17, EoS, s18, s19, s20, s21, s22, Comment);
	DebugN(ID,	Rack,	Crate,	Para,	EoN,	Host,	Node,	Port,	Unit,	EoA,
		FatlL_Off,	WarnL_Off,	Norm_Off,	WarnH_Off,	FatlH_Off,	EoO,
		FatlL_Stb,	WarnL_Stb,	Norm_Stb,	WarnH_Stb,	FatlH_Stb,	EoS,
		FatlL_On,	WarnL_On,	Norm_On,	WarnH_On,	FatlH_On,	Comment);
	DebugN(\"----------------------------------------\");*/
 
Crate--; // The crate Number stars from zero!

if ( consistency(Rack, Crate, UnitMax) ) return;

  sprintf( module, \"Crate%02d.Controller.\", Crate);

// Scanning for Moni
  if (Comment == \"Moni\")
	{
	dpName = getSystemName() + module + Para + \".Recv\";
	if ( dpExists(dpName) )
		{
		switch(status) // setting values related to actual status
			{
			case \"on\"  :  setAlerts( dpName, FatlL_On,	WarnL_On,	WarnH_On,	FatlH_On );  break;
			case \"off\" :  setAlerts( dpName, FatlL_Off,	WarnL_Off,	WarnH_Off,	FatlH_Off ); break;
			case \"stb\" :  setAlerts( dpName, FatlL_Stb,	WarnL_Stb,	WarnH_Stb,	FatlH_Stb ); break;
			default	 :  DebugN(\"Error in reading! No status available for \",dpName,\".\");
			}
	 	}
	else DebugN(\"Error in reading!\" , dpName, \" doesn't exist.\");
	} 
// Scanning for Command	
  else if (Comment == \"Comm\") {
    dpName = getSystemName() + module + Para + \".Send\";
    if ( dpExists(dpName) )
    	{
		switch(status) // setting values related to actual status
			{
			case \"on\"  :  setAlerts( dpName, FatlL_On,	WarnL_On,	WarnH_On,	FatlH_On );  break;
			case \"off\" :  setAlerts( dpName, FatlL_Off,	WarnL_Off,	WarnH_Off,	FatlH_Off ); break;
			case \"stb\" :  setAlerts( dpName, FatlL_Stb,	WarnL_Stb,	WarnH_Stb,	FatlH_Stb ); break;
			default	 :  DebugN(\"Error in reading! No status available for \",dpName,\".\");
			}
		}	
	else DebugN(\"Error in reading!\" , dpName, \" doesn't exist.\");		
	}
  else DebugN(\"Error in reading! No type available for \", getSystemName() + module + Para);
}



/**************************************************************************\\
|* The following function splits the string from the Cnf_Card.txt file    *|
|* giving back the setting values for every card.                         *|
\\**************************************************************************/
void cardSet(string raw, string status, int UnitMax)
{
int ID,	Rack,	Crate,	Card, Host,	Node,	Port,	Unit;
string Para, EoN, EoA, EoO, EoS, Comment, LV_HV, dpName, module,
        s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13,
        s14, s15, s16, s17, s18, s19, s20, s21, s22, s23;
float FatlL_Off, WarnL_Off,	Norm_Off, WarnH_Off, FatlH_Off,
	  FatlL_Stb, WarnL_Stb, Norm_Stb, WarnH_Stb, FatlH_Stb,
	  FatlL_On,	 WarnL_On,	Norm_On,  WarnH_On,	 FatlH_On;
bool stat = FALSE;

sscanf(raw,
       \"%s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s\",
        s1, s2, s3, s4, Para, EoN, s5, s6, s7, s8, EoA, s9, s10, s11, s12, s13, EoO,
        s14, s15, s16, s17, s18, EoS, s19, s20, s21, s22, s23, LV_HV, Comment);

sscanf(s1,  \"%d\", ID);
sscanf(s2,  \"%d\", Rack);
sscanf(s3,  \"%d\", Crate);
sscanf(s4,  \"%d\", Card);
sscanf(s5,  \"%d\", Host);
sscanf(s6,  \"%d\", Node);
sscanf(s7,  \"%d\", Port);
sscanf(s8,  \"%d\", Unit);
sscanf(s9,  \"%f\", FatlL_Off);
sscanf(s10, \"%f\", WarnL_Off);
sscanf(s11, \"%f\", Norm_Off);
sscanf(s12, \"%f\", WarnH_Off);
sscanf(s13, \"%f\", FatlH_Off);
sscanf(s14, \"%f\", FatlL_Stb);
sscanf(s15, \"%f\", WarnL_Stb);
sscanf(s16, \"%f\", Norm_Stb);
sscanf(s17, \"%f\", WarnH_Stb);
sscanf(s18, \"%f\", FatlH_Stb);
sscanf(s19, \"%f\", FatlL_On);
sscanf(s20, \"%f\", WarnL_On);
sscanf(s21, \"%f\", Norm_On);
sscanf(s22, \"%f\", WarnH_On);
sscanf(s23, \"%f\", FatlH_On);

/*  DebugN(s1, s2, s3, s4, Para, EoN, s5, s6, s7, s8, EoA, s9, s10, s11, s12, s13, EoO,
        s14, s15, s16, s17, s18, EoS, s19, s20, s21, s22, s23, LV_HV, Comment);
	DebugN(ID,	Rack,	Crate,	Card,	Para,	EoN,	Host,	Node,	Port,	Unit,	EoA,
		FatlL_Off,	WarnL_Off,	Norm_Off,	WarnH_Off,	FatlH_Off,	EoO,
		FatlL_Stb,	WarnL_Stb,	Norm_Stb,	WarnH_Stb,	FatlH_Stb,	EoS,
		FatlL_On,	WarnL_On,	Norm_On,	WarnH_On,	FatlH_On,	LV_HV, Comment);
	DebugN(\"----------------------------------------\");*/

Crate--; // The crate Number stars from zero!

if ( consistency(Rack, Crate, UnitMax) ) return;

  switch(Card)
	{
	case 0  : break;
	case 1  : Card = 0; if (LV_HV != \"LV\") stat = TRUE; break; //LV_card00
	case 2  : Card = 0; if (LV_HV != \"HV\") stat = TRUE; break; //HV_card00
	case 3  : Card = 1; if (LV_HV != \"LV\") stat = TRUE; break; //LV_card01
	case 4  : Card = 2; if (LV_HV != \"LV\") stat = TRUE; break; //LV_card02
	case 5  : Card = 1; if (LV_HV != \"HV\") stat = TRUE; break; //HV_card01
	case 6  : Card = 3; if (LV_HV != \"LV\") stat = TRUE; break; //LV_card03
	case 7  : Card = 4; if (LV_HV != \"LV\") stat = TRUE; break; //LV_card04
	case 8  : Card = 2; if (LV_HV != \"HV\") stat = TRUE; break; //HV_card02
	case 9  : Card = 5; if (LV_HV != \"LV\") stat = TRUE; break; //LV_card05
	case 10 : Card = 6; if (LV_HV != \"LV\") stat = TRUE; break; //LV_card06
	case 11 : Card = 3; if (LV_HV != \"HV\") stat = TRUE; break; //HV_card03
	case 12 : Card = 7; if (LV_HV != \"LV\") stat = TRUE; break; //LV_card07
	default : DebugN(\"Error! Card\", Card, \"doesn't exist!\"); return;
	}

  if ( stat )
	{
	DebugN(\"Error! Consistency Error for Card\", Card);
	return;
	}

  sprintf( module, \"Crate%02d.\" + LV_HV + \"_card%02d.\", Crate, Card );

// Scanning for Moni
  if (Comment == \"Moni\")
	{
	dpName = getSystemName() + module + Para + \".Recv\";
	if ( dpExists(dpName) )
		{
		switch(status) // setting values related to actual status
			{
			case \"on\"  :  setAlerts( dpName, FatlL_On,	WarnL_On,	WarnH_On,	FatlH_On );  break;
			case \"off\" :  setAlerts( dpName, FatlL_Off,	WarnL_Off,	WarnH_Off,	FatlH_Off ); break;
			case \"stb\" :  setAlerts( dpName, FatlL_Stb,	WarnL_Stb,	WarnH_Stb,	FatlH_Stb ); break;
			default	 :  DebugN(\"Error in reading! No status available for \",dpName,\".\");
			}
	 	}
	else DebugN(\"Error in reading!\" , dpName, \" doesn't exist.\");
	} 
// Scanning for Command	
  else if (Comment == \"Comm\") {
    dpName = getSystemName() + module + Para + \".Send\";
    if ( dpExists(dpName) )
    	{
		switch(status) // setting values related to actual status
			{
			case \"on\"  :  setAlerts( dpName, FatlL_On,	WarnL_On,	WarnH_On,	FatlH_On );  break;
			case \"off\" :  setAlerts( dpName, FatlL_Off,	WarnL_Off,	WarnH_Off,	FatlH_Off ); break;
			case \"stb\" :  setAlerts( dpName, FatlL_Stb,	WarnL_Stb,	WarnH_Stb,	FatlH_Stb ); break;
			default	 :  DebugN(\"Error in reading! No status available for \",dpName,\".\");
			}
		}	
	else DebugN(\"Error in reading!\" , dpName, \" doesn't exist.\");		
	}
  else DebugN(\"Error in reading! No type available for \", getSystemName() + module + Para);
}


/**************************************************************************\\
|* The following function splits the string from the Cnf_Para.txt file    *|
|* giving back the setting values for every channel.                      *|
\\**************************************************************************/
void channelSet(string raw, string status, int UnitMax)
{
int i, ID,	Mod, Crate; 
string Para, EoO, EoS, Comment, EoP, LV_HV, dpName, module, type,
		s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13, s14, s15, s16, s17;
float FatlL_Off, WarnL_Off,	Norm_Off, WarnH_Off, FatlH_Off,
	  FatlL_Stb, WarnL_Stb, Norm_Stb, WarnH_Stb, FatlH_Stb,
	  FatlL_On,	 WarnL_On,	Norm_On,  WarnH_On,	 FatlH_On;

  sscanf(raw, \"%s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s\",
			   s1, s2, Para, EoP, s3, s4, s5, s6, s7, EoO, s8, s9, s10, s11, s12,
			   EoS, s13, s14, s15, s16, s17, Comment);

sscanf(s1,  \"%d\", ID);
sscanf(s2,  \"%d\", Mod);
sscanf(s3,  \"%f\", FatlL_Off);
sscanf(s4,  \"%f\", WarnL_Off);
sscanf(s5,  \"%f\", Norm_Off);
sscanf(s6,  \"%f\", WarnH_Off);
sscanf(s7,  \"%f\", FatlH_Off);
sscanf(s8,  \"%f\", FatlL_Stb);
sscanf(s9,  \"%f\", WarnL_Stb);
sscanf(s10, \"%f\", Norm_Stb);
sscanf(s11, \"%f\", WarnH_Stb);
sscanf(s12, \"%f\", FatlH_Stb);
sscanf(s13, \"%f\", FatlL_On);
sscanf(s14, \"%f\", WarnL_On);
sscanf(s15, \"%f\", Norm_On);
sscanf(s16, \"%f\", WarnH_On);
sscanf(s17, \"%f\", FatlH_On);

/*  DebugN(s1, s2, Para, EoP, s3, s4, s5, s6, s7, EoO, s8, s9, s10, s11, s12,
			   EoS, s13, s14, s15, s16, s17, Comment);		
	DebugN(ID,	Mod, Para, EoP, 
		FatlL_Off,	WarnL_Off,	Norm_Off,	WarnH_Off,	FatlH_Off,	EoO,
		FatlL_Stb,	WarnL_Stb,	Norm_Stb,	WarnH_Stb,	FatlH_Stb,	EoS,
		FatlL_On,	WarnL_On,	Norm_On,	WarnH_On,	FatlH_On,	Comment);*/

Crate = 1; 
Crate--; // The crate Number stars from zero!
if ( consistency(1, Crate, UnitMax) ) return;

Mod--; // The channel Number stars from zero!
if (Mod > 48)
	{
	DebugN(\"Error! Channel\", Mod, \"doesn't exist!\");
	return;
	}

  sprintf( module, \"Crate%02d.Channel%02d.\", Crate, Mod );
  
// Scanning for Moni
  if (Comment == \"Moni\")
  	{
    dpName = getSystemName() + module + Para + \".Recv\";
    if ( dpExists(dpName) )
    	{
		switch(status) // setting values related to actual status
			{
			case \"on\"  :  setAlerts( dpName, FatlL_On,	WarnL_On,	WarnH_On,	FatlH_On );  break;
			case \"off\" :  setAlerts( dpName, FatlL_Off,	WarnL_Off,	WarnH_Off,	FatlH_Off ); break;
			case \"stb\" :  setAlerts( dpName, FatlL_Stb,	WarnL_Stb,	WarnH_Stb,	FatlH_Stb ); break;
			default	 :  DebugN(\"Error in reading! No status available for \",dpName,\".\");
		    }
		}
	else DebugN(\"Error in reading!\" , dpName, \" doesn't exist.\");		
    }
// Scanning for Command	  
  else if (Comment == \"Comm\")
  	{
    dpName = getSystemName() + module + Para + \".Send\";
    if ( dpExists(dpName) )
    	{
		switch(status) // setting values related to actual status
			{
	  		case \"on\"  :  setAlerts( dpName, FatlL_On,	WarnL_On,	WarnH_On,	FatlH_On );  break;
  	  		case \"off\" :  setAlerts( dpName, FatlL_Off,	WarnL_Off,	WarnH_Off,	FatlH_Off ); break;
      		case \"stb\" :  setAlerts( dpName, FatlL_Stb,	WarnL_Stb,	WarnH_Stb,	FatlH_Stb ); break;
	  		default	 :  DebugN(\"Error in reading! No status available for \",dpName,\".\");	  
		  	}
		}
	else DebugN(\"Error in reading!\" , dpName, \" doesn't exist.\");		
	}
// Scanning for read&write Parameters
  else if (Comment == \"MoniComm\")
  	{
  	for(i=1; i<=2; i++)
		{
		switch(i)
			{
			case 1 : type = \".Send\"; break;
			case 2 : type = \".Recv\"; break;
			}
	    dpName = getSystemName() + module + Para + type;
	    if ( dpExists(dpName) )
	    	{
	    	switch(status) // setting values related to actual status
	    		{
				case \"on\"  :  setAlerts( dpName, FatlL_On,	WarnL_On,	WarnH_On,	FatlH_On );  break;
				case \"off\" :  setAlerts( dpName, FatlL_Off,	WarnL_Off,	WarnH_Off,	FatlH_Off ); break;
				case \"stb\" :  setAlerts( dpName, FatlL_Stb,	WarnL_Stb,	WarnH_Stb,	FatlH_Stb ); break;
				default	 :  DebugN(\"Error in reading! No status available for \",dpName,\".\");
				}
			}
		else DebugN(\"Error in reading!\" , dpName, \" doesn't exist.\");		
	    }
	}
  else DebugN(\"Error in reading! No type available for \",getSystemName() + module + Para); 
  }

/************************************************************************\\
|* The following function sets alert config for the datapoint element	*| 
|* dpeName with the five alert ranges neighbouring            			*|
|* Fatal_low, Warn_low, Warn_high and Fatal_high 						*|
\\************************************************************************/
 setAlerts(string dpeName, float Fatal_low, float Warn_low,
                                float Warn_high, float Fatal_high)
{
	string prefix = dpeName+\":_alert_hdl.\";
	dyn_errClass err;
	int rc, type;
	bool ok;
	dyn_string rangeTexts   = makeDynString (\"Data is fatal Low\", \"Data is warn. Low\", \"Data is Normal\",
															\"Data is warn. High\", \"Data is fatal High\");
	dyn_string rangeClasses = makeDynString (\"alert.\", \"warning.\", \"\", \"warning.\", \"alert.\");

if ( !( (Fatal_low < Warn_low) && (Warn_low < Warn_high) && (Warn_high < Fatal_high) ) )
	{
	DebugN(\"Error! Invalid limits for\", dpeName, \" : \", Fatal_low, Warn_low, Warn_high, Fatal_high);
	return; 
	}
//	DebugN(dpeName, \" : \", Fatal_low, Warn_low, Warn_high, Fatal_high);
	
	// check if the alarm already exists
	rc = dpGet (prefix+\"._type\", type);
	err = getLastError ();	
	if (rc | dynlen(err)) {
		DebugN(\"Failed to check whether alarm already exists for dpe: \"+dpeName+\" : \"+rc);
		throwError (err);
		return;
	}

	// if it exists, deactivate the alarm handling (so we can change it)
	if (type != DPCONFIG_NONE) {
		dpDeactivateAlert (dpeName, ok);		
		if ( ! ok) {
			DebugN(\"Failed to deactivate alarm on dpe: \"+dpeName);
			return;
		}
	}
	
	// configure the alarm
	rc = dpSetWait (prefix+\"._type\", DPCONFIG_ALERT_NONBINARYSIGNAL, // equal to 13!

					prefix+\"1._type\", DPDETAIL_RANGETYPE_MINMAX, // equal to 4!
					prefix+\"1._u_limit\", Fatal_low,
					prefix+\"1._l_incl\", TRUE,
					prefix+\"1._u_incl\", FALSE,
					prefix+\"1._text\",  rangeTexts [1],
					prefix+\"1._class\", rangeClasses [1],

					prefix+\"2._type\", DPDETAIL_RANGETYPE_MINMAX,
					prefix+\"2._l_limit\", Fatal_low,
					prefix+\"2._u_limit\", Warn_low,
					prefix+\"2._l_incl\", TRUE,
					prefix+\"2._u_incl\", FALSE,
					prefix+\"2._text\", rangeTexts [2],
					prefix+\"2._class\", rangeClasses [2],

					prefix+\"3._type\", DPDETAIL_RANGETYPE_MINMAX,
					prefix+\"3._l_limit\", Warn_low,
					prefix+\"3._u_limit\", Warn_high,
					prefix+\"3._l_incl\", TRUE,
					prefix+\"3._u_incl\", FALSE,
					prefix+\"3._text\", rangeTexts [3],
					prefix+\"3._class\", rangeClasses [3],

					prefix+\"4._type\", DPDETAIL_RANGETYPE_MINMAX,
					prefix+\"4._l_limit\", Warn_high,
					prefix+\"4._u_limit\", Fatal_high,
					prefix+\"4._l_incl\", TRUE,
					prefix+\"4._u_incl\", FALSE,
					prefix+\"4._text\", rangeTexts [4],
					prefix+\"4._class\", rangeClasses [4],

					prefix+\"5._type\", DPDETAIL_RANGETYPE_MINMAX,
					prefix+\"5._l_limit\", Fatal_high,
					prefix+\"5._l_incl\", TRUE,
					prefix+\"5._u_incl\", FALSE,
					prefix+\"5._text\", rangeTexts [5],
					prefix+\"5._class\", rangeClasses [5],
					prefix+\"._orig_hdl\", TRUE);
			
	err = getLastError ();	
	if (rc | dynlen(err)) {
		DebugN(\"Failed to set alarm on dpe: \"+dpeName+\" : \"+rc);
		throwError (err);
		return;
	}

	//activate the alarm handling
	dpActivateAlert (dpeName, ok);		
	if ( ! ok) {
		DebugN(\"Failed to activate alarm on dpe: \"+dpeName);
		return;
	//Acknoledge Alerts		
	dpSetWait(dpeName+\":_alert_hdl.._ack\", DPATTR_ACKTYPE_MULTIPLE);
	}
}

																			
/****************************************************************************\\
|* This function gets info about the system from the file Cnf_Syst.txt		*|
\\****************************************************************************/
int getSyst(int & UnitMax)
{
int err, Index, HostMax, NodeMax, PortMax, ChanMax,	LVparaMax,
		HVparaMax, lvCAparaMax, hvCAparaMax, CRparaMax, LimiMax;
file syst;
string raw, path, Comment, sys;

sys = getSystemName();

  /* open Cnf_Syst.txt file */
	path = getPath(PANELS_REL_PATH, \"Cnf_Syst.txt\");
	syst = fopen(path,\"r\");
	fgets( raw, 300, syst );

  /* detecting the number of the crates: UnitMax*/
	DebugN(\"Reading Cnf_Syst.txt file. *-*-*-*-*-*-*-*-*-*-*-*\");
	fgets( raw, 300, syst );
	sscanf(raw, \"%d %d %d %d %d %d %d %d %d %d %d %d %s \",
				Index, HostMax, NodeMax, PortMax, UnitMax, ChanMax, LVparaMax,
				HVparaMax, lvCAparaMax, hvCAparaMax, CRparaMax, LimiMax, Comment);

     dpSet(sys+\"Hmax.Numb:_original.._value\", HostMax);
     dpSet(sys+\"Nmax.Numb:_original.._value\", NodeMax);
     dpSet(sys+\"Pmax.Numb:_original.._value\", PortMax);
     dpSet(sys+\"Umax.Numb:_original.._value\", UnitMax);
     dpSet(sys+\"Cmax.Numb:_original.._value\", ChanMax);
     dpSet(sys+\"LVch_max.Numb:_original.._value\", LVparaMax);
     dpSet(sys+\"HVch_max.Numb:_original.._value\", HVparaMax);
     dpSet(sys+\"LVca_max.Numb:_original.._value\", lvCAparaMax);
     dpSet(sys+\"HVca_max.Numb:_original.._value\", hvCAparaMax);
     dpSet(sys+\"CRpa_max.Numb:_original.._value\", CRparaMax);
     dpSet(sys+\"Lmax.Numb:_original.._value\", LimiMax);

  /* close Cnf_Syst.txt file */
	err=ferror(syst); // export error
	fclose(syst); // close file
	if (err!=0) 
		{
		DebugN(\"Error no. \",err,\" occurred\");
		return 0;
		}
  return 1;
}

//this subroutine check the existence of a given type
bool dpTypeExists(string dpType)
{
  int index;
  dyn_string dpAllTypes;
  
  //get all types
  dpAllTypes = dpTypes();
  
  //check the existence of the given type 
  for(index=1; index<=dynlen(dpAllTypes); index++)
  	{
  		if(dpAllTypes[index] == dpType) return 1;
  	}
  
  return 0;
}


int consistency (int Rack, int Crate, int UnitMax)
{
  if (Rack == 99)
	{
	DebugN(\"Error!\", Rack, \"is an invalid Rack number!\");
	return 1;
	}
  if ( (Crate >= UnitMax) | (Crate  < 0) )
	{
	DebugN(\"Error! Crate\", Crate, \"doesn't exist!\");
	return 1;
	}
return 0;
}

void getConversion(int UnitMax)
{
int i, crat;
string 	Bus, Crate, prefix, dpeName;

setValue(\"\",\"foreCol\",\"Red\");
		
for ( crat = 0; crat < UnitMax; crat++ )
	{
	sprintf( Crate, \"Crate%02d\", crat);
	sprintf( Bus, \"Bus%02d\", 0 );
	
	/* Channels Conversion *******************************************/
		for(i=0; i<48; i++)
		{
		sprintf( prefix, getSystemName() + Crate + \".Channel%02d.\", i );
//		DebugN(\" Setting Conversion for Crate \", Crate, \", Channel \", i);
				
		dpeName		= \"LVch_Vcc.Send\";
		Conversion(prefix + dpeName, \"OUT\", 0.0, 1000.0 / 20.0);

		dpeName 	= \"LVch_Vdd.Send\";
		Conversion(prefix + dpeName, \"OUT\", 0.0, 1000.0 / 20.0);

		dpeName 	= \"LVchVCSV.Send\";
		Conversion(prefix + dpeName, \"OUT\", 0.0, 1000.0 / 40.0);
		
		dpeName 	= \"LVchPINV.Send\";
		Conversion(prefix + dpeName, \"OUT\", 0.0, 1000.0 / 50.0);
		
		dpeName		= \"LVchDTrp.Send\";
		Conversion(prefix + dpeName, \"OUT\", 0.0, 1.0 / 2.0);
		
		dpeName 	= \"LVchCTrp.Send\";
		Conversion(prefix + dpeName, \"OUT\", 0.0, 1.0 / 2.0);

		dpeName 	= \"LVchTLim.Send\";
		Conversion(prefix + dpeName, \"OUT\", 128.0, 1.0);

		dpeName 	= \"LVchTTrp.Send\";
		Conversion(prefix + dpeName, \"OUT\", 128.0, 1.0);

		dpeName 	= \"HVchITrp.Send\";
		Conversion(prefix + dpeName, \"OUT\", 0.0, 1.0);

		dpeName 	= \"HVchRamp.Send\";
		Conversion(prefix + dpeName, \"OUT\", 0.0, 1.0);
			
		dpeName 	= \"LVch_Vcc.Recv\";
		Conversion(prefix + dpeName, \"IN\", 0.0, 20.0 / 1000.0);
	
		dpeName 	= \"LVps_Vcc.Recv\";
		Conversion(prefix + dpeName, \"IN\", 0.0, 50.0 / 1000.0);

		dpeName 	= \"LVretVcc.Recv\";
		Conversion(prefix + dpeName, \"IN\", 0.0, 20.0 / 1000.0);

		dpeName 	= \"LVch_Icc.Recv\";
		Conversion(prefix + dpeName, \"IN\", 0.0, 10.0);

		dpeName		= \"LVch_Vdd.Recv\";
		Conversion(prefix + dpeName, \"IN\", 0.0, 20.0 / 1000.0);

		dpeName		= \"LVps_Vdd.Recv\";
		Conversion(prefix + dpeName, \"IN\", 0.0, 50.0 / 1000.0);

		dpeName 	= \"LVretVdd.Recv\";
		Conversion(prefix + dpeName, \"IN\", 0.0, 20.0 / 1000.0);

		dpeName 	= \"LVch_Idd.Recv\";
		Conversion(prefix + dpeName, \"IN\", 0.0, 10.0);

		dpeName 	= \"LVchVCSV.Recv\";
		Conversion(prefix + dpeName, \"IN\", 0.0, 40.0 / 1000.0);

		dpeName 	= \"LVchVCSI.Recv\";
		Conversion(prefix + dpeName, \"IN\", 0.0, 1.0 / 25.0);

		dpeName 	=  \"LVchPINV.Recv\";
		Conversion(prefix + dpeName, \"IN\", 0.0, 50.0 / 1000.0);

		dpeName 	= \"LVchPINI.Recv\";
		Conversion(prefix + dpeName, \"IN\", 0.0, 1.0 / 100.0);

//		dpeName 	= \"MOch_Tm0.Recv\";
//		Conversion(prefix + dpeName, \"IN\", 0.0, 1.0);

//		dpeName 	= \"MOch_Tm1.Recv\";
//		Conversion(prefix + dpeName, \"IN\", 0.0, 1.0);

		dpeName 	= \"HVchVolt.Recv\";
		Conversion(prefix + dpeName, \"IN\", 0.0, 1.0 / 8.0);

		dpeName 	= \"HVchCurr.Recv\";
		Conversion(prefix + dpeName, \"IN\", 0.0, 1.0);
		}

	/* LVs cards Conversion *******************************************/
	  for(i=0; i<8; i++)
	  	{
		sprintf( prefix, getSystemName() + Crate + \".LV_card%02d.\", i);
//		DebugN(\" Setting Conversion for Crate \", Crate, \", LV Card \", i);

		dpeName		= \"LVcaTemp.Recv\";
		Conversion(prefix + dpeName, \"IN\", 0.0, 1.0);

		dpeName		= \"LVcaPowr.Recv\";
		Conversion(prefix + dpeName, \"IN\", 0.0, 1.0 / 2.5);

		dpeName		= \"LVcaTrip.Send\";
		Conversion(prefix + dpeName, \"OUT\", 0.0, 2.5);
		}
	}
}


/****************************************************************************\\
|* This function sets conversions for the datapoint element dpeName   		*|
\\****************************************************************************/
 Conversion(string dpeName, string Direction, float Alfa, float Beta)
{
  dyn_errClass err;

  switch(Direction)
	{
	case \"IN\":                            // Monitored value conversion
		dpSetWait(
			dpeName+\":_msg_conv.._type\", 33, //Coversion from raw to physical
			dpeName+\":_msg_conv.1._type\", 2, //Polynomial 4th degree conversion
			dpeName+\":_msg_conv.1._poly_grade\", 1,  //Take only: y = a + b*x
			dpeName+\":_msg_conv.1._poly_a\", Alfa,
			dpeName+\":_msg_conv.1._poly_b\", Beta); break;
	case \"OUT\":                           // Controled value conversion
		dpSetWait(
			dpeName+\":_cmd_conv.._type\", 36, //Coversion from raw to physical
			dpeName+\":_cmd_conv.1._type\", 2, //Polynomial 4th degree conversion
			dpeName+\":_cmd_conv.1._poly_grade\", 1,  //Take only: y = a + b*x
			dpeName+\":_cmd_conv.1._poly_a\", Alfa,
			dpeName+\":_cmd_conv.1._poly_b\", Beta); break;
	default: DebugN(\"Error! Not able to set the direction\", Direction, \"for\", dpeName); return;	
	}//end of switch(...)
	err = getLastError();
	if(dynlen(err) > 0) 
		{
		throwError(err);
		}
}
" 0
 E E E
13 28
"Button3"
""
1 330 130 E E E 1 E 1 E N "_3DText" E N {255,128,64} E E
 E E
24 0 0 0 0 0
EE E
0
1
LANG:1 0 
0
1
LANG:1 105 -microsoft windows-Arial-bold-r-normal-*-*-140-100-100-*-*-iso8859-1|-16,0,0,0,700,0,0,0,0,3,2,1,34,Arial
0 ""
328 128 562 192
T 
1
LANG:1 9 DPT-Clean
"//DPT Clean
/******************************************************************************\\
123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789
|*=====================================-======================================*|
|*                 SCT COOLING SYSTEM CONTROL AND MONITORING                  *|
|*=====================================-======================================*|
|*   AUTHORs:        G.Codispoti - codispoti@cs.infn.it			    		  *|
|*								   Giuseppe.Codispoti@cern.ch			      *|
|*																		      *|
|*   DESIGN ISSUEs:  This Script deletes all the DPTs and DPs.			      *|
|*																		      *|
|*   MODIF_HISTORY:  17.03.2003  - first release						      *|
|*																		      *|
\\******************************************************************************/

main()
{
  int index, dpIndex, count;
  dyn_string dptNames, dpAllNames; 
  string dpType;
  
  setValue(\"\",\"foreCol\",\"Red\");

count = 1;
while( count ) 
  {
  DebugN(dynlen( dpTypes() ));
  count = 0;
  dptNames = dpTypes();

  for(index=1; index<=dynlen(dptNames); index++)
  	{
	  if (strpos (dptNames[index], \"_\")) 
	    {
	    count++;
  	    DebugN( dptNames[index], \" in position \", strpos (dptNames[index], \"_\") );

   	    //get all datapoint of the given type
	    dpAllNames = dpNames(\"*\", dptNames[index]);
  
	    //delete all the datapoint of the given type
	    for(dpIndex=1; dpIndex<=dynlen(dpAllNames); dpIndex++)
	  	  {
		  	dpDelete(dpAllNames[dpIndex]);
	  	  }
  
  	    //delete the type
	    dpTypeDelete(dptNames[index]);
	    } 
     }
  }
  setValue(\"\",\"foreCol\",\"\");
}" 0
 E E E
13 30
"Button9"
""
1 309 560 E E E 1 E 1 E N "_3DText" E N {102,204,255} E E
 E E
25 0 0 0 0 0
EE E
0
1
LANG:1 0 
0
1
LANG:1 105 -microsoft windows-Arial-bold-r-normal-*-*-140-100-100-*-*-iso8859-1|-16,0,0,0,700,0,0,0,0,3,2,1,34,Arial
0 ""
38 128 272 192
T 
1
LANG:1 16 Create Addresses
"//Create Address
/******************************************************************************\\
123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789
|*=====================================-======================================*|
|*			               SCT POWER SUPPLIES MODULES     		              *|
|*=====================================-======================================*|
|*   AUTHORs:        G.Codispoti - codispoti@cs.infn.it			    		  *|
|*								   Giuseppe.Codispoti@cern.ch			      *|
|*																		      *|
|*   DESIGN ISSUEs:  This Script add DPe address loading them from			  *|
|*   				 the text file \"OPCsettings.cfg\" and create the file	  *|
|*   				 \"OPCCanServer.cfg\".									  *|
|*																		      *|
|*   MODIF_HISTORY:  17.03.2003  - first release						      *|
|*																		      *|
\\******************************************************************************/

main()
{
file cfg, opc;
string path, strn, Crate, Bus, driver, port, baudrate, dpeName, plus;
string PDO_ID, PDOnum, PDOdir, PDOnum2, PDOnum3, date;
int err, nbus, i, index, count, count2, LVCard, HVCard, n;
dyn_int num;
dyn_string byte, OPCItem, type, card, value;
time tm;
bool ok = TRUE;

setValue(\"\",\"foreCol\",\"Red\");
DebugN(getCurrentTime());  
Crate = \"Crate01\";
Bus = \"Bus00\";
index = 0;

// Check if the opc configuration is already stored in the PVSS datapoint
if (!dpExists(\"_CANopen\"))
	{ 
    dpCreate(\"_CANopen\", \"_OPCServer\"); 
    dpSet(\"_CANopen.StateTimer:_original.._value\", 10);
    dpSet(\"_CANopen.ReconnectTimer:_original.._value\", 10);
    DebugN(\"OPC DP created!\");
    setOPCGroup(\"Comm\", 1000, \"Device\", FALSE); 
	setOPCGroup(\"Moni\",  100, \"Cache\" , TRUE);
	}


/* Opening configuration database */
path = getPath(PANELS_REL_PATH, \"OPCsettings.cfg\");
cfg = fopen(path,\"r\");
err = ferror(cfg); // export error
if (err)
	{ 
	DebugN(\"Error no. \",err,\" occurred: not able to open file:\", path);
	return;
	}

/* open new file for OPC configuration */
DebugN(\"Creating file C:/OPCCanServer_giuseppe.cfg\");
tm = getCurrentTime();
date = formatTime(\"%d%m%y\", tm);
//look at other files created in the same day
n = dynlen (getFileNames(\"C://\", \"OPCCanServer_\" 
														+ date + \"*.cfg\"));
//if there are previos files with same date, add a (n)
if (n!=0) sprintf(plus, date + \"(%d)\", n);
else plus = date;
DebugN(n, plus);
// copy the old file in a new *_date or *_date(n) file
ok = copyFile(\"C://OPCCanServer.cfg\",
		 \"C://OPCCanServer_\" + plus + \".cfg\");
if(!ok)
	{
	DebugN(\"Error in moving old OPCCanServer.cfg. Creating file in the panels directory\");
	//if the rename faults, the file will be created in the panel directory
	path = strrtrim(path, \"OPCsettings.cfg\") + \"OPCCanServer.cfg\";
	}
else path = \"C://OPCCanServer.cfg\";
opc = fopen(path,\"w\");
err = ferror(opc); // export error
if (err)
	{ 
	DebugN(\"Error no. \",err,\" occurred: not able to create file:\", path);
	fclose(cfg);
	return;
	}

//get general info
fgets(strn, 300, cfg);
fgets(strn, 300, cfg);
sscanf( strn, \"Bus	%d\", nbus );
fgets(strn, 300, cfg);
sscanf( strn, \"Driver	%s\", driver);
fgets(strn, 300, cfg);
sscanf( strn, \"Port	%s\", port);
fgets(strn, 300, cfg);
sscanf( strn, \"Baudrate	%s\", baudrate);
fgets(strn, 300, cfg);


fputs(\"[CANBUS]\\n\" + Bus + \" = \" + driver + \" \" + port + \" \" + baudrate
					+ \"\\n\\n[DEVICE]\\n\"
					 + Crate + \" = \" + Bus + \" 1 NG\\n\\n[SDOItem]\\n\", opc);

// Get SDO Channel Items
DebugN(\"Setting Channel SDO's...\");
DebugN(strn);
while(1)
	{
	fgets( strn, 300, cfg);
	if( strpos (strn, \"[\") != -1) break;
	sscanf( strn, \"%s %x %s %s\", OPCItem[++index], num[index], byte[index], type[index] );
	}

for (i=0; i<48; i++)
	{
	for (index = 1; index <= dynlen(num); index++)
		{
		fprintf( opc, 
				Crate + \"_\" + OPCItem[index] + \"%d  = \" + Crate + \"  %x \"
				 + byte[index] + \" IO \" + type[index] + \"\\n\",
													i, num[index] + i );
		SDOAddress(OPCItem[index], type[index], Bus, Crate, i, \"Channel\");
		}
	}

// Get SDO Card Items
DebugN(\"Setting Card SDO's...\");
num = makeDynString(\"\");
byte = OPCItem = type = makeDynInt(0);
LVCard = HVCard = count = 0;
index = 0;
while(1)
	{
	fgets( strn, 300, cfg);
	if( strpos (strn, \"[\") != -1) break;
	sscanf( strn, \"%s %x %s %s\",
			OPCItem[++index], num[index], byte[index], type[index] );
	}
	
for (index = 1; index <= dynlen(num); index++)
	{
	if ( strpos (OPCItem[index], \"LV\") != -1) count++;
	}

for (i=0; i<6; i++)
	{
	for (index = 1; index <= count; index++)
		{
		fprintf( opc, 
				Crate + \"_\" + OPCItem[index] + \"%d  = \" + Crate + \"  %x \"
				 + byte[index] + \" IO \" + type[index] + \"\\n\",
													LVCard, num[index] + LVCard );
		SDOAddress(OPCItem[index], type[index], Bus, Crate, i, \"LV_card\");
		}
	LVCard++;
	for (index = count+1; index <= dynlen(num); index++)
		{
		fprintf( opc, 
				Crate + \"_\" + OPCItem[index] + \"%d  = \" + Crate + \"  %x \"
				 + byte[index] + \" IO \" + type[index] + \"\\n\",
												HVCard, num[index] + HVCard );
		SDOAddress(OPCItem[index], type[index], Bus, Crate, i, \"HV_card\");
			}
	HVCard++;
	for (index = 1; index <= count; index++)
		{
		fprintf( opc, 
					Crate + \"_\" + OPCItem[index] + \"%d  = \" + Crate + \"  %x \"
					 + byte[index] + \" IO \" + type[index] + \"\\n\",
														LVCard, num[index] + LVCard );
		SDOAddress(OPCItem[index], type[index], Bus, Crate, i, \"LV_card\");
		}
	LVCard++;
	}

// Get SDO for IVCurve 
DebugN(\"Setting Channel IVCurve SDO's...\");
num = makeDynString(\"\");
byte = OPCItem = type = makeDynInt(0);
index = 0;

while(1)
	{
	fgets( strn, 300, cfg);
	if( strpos (strn, \"[\") != -1) break;
	sscanf( strn, \"%s %x %s %s\", OPCItem[++index], num[index], byte[index], type[index] );
	}

for (i=0; i<48; i++)
	{
	for (index = 1; index <= dynlen(num); index++)
		{
		fprintf( opc, 
				Crate + \"_\" + OPCItem[index] + \"%d  = \" + Crate + \"  %x \"
				 + byte[index] + \" IO \" + type[index] + \"\\n\",
													i, num[index] + i );
		SDOIVAddress(OPCItem[index], type[index], Bus, Crate, i, \"Channel\");
		}
	}

// Get PDO Values 
DebugN(\"Setting PDO's values...\");
fputs(\"\\n\\n[PDO]\\n\", opc);
num = makeDynString(\"\");
byte = OPCItem = type = makeDynInt(0);
index = 0;
while(1)
	{
	fgets( strn, 300, cfg);
	if( strpos (strn, \"[\") != -1) break;
	strreplace( strn, \"\\t\", \" \");
	sscanf( strn, \"%s %s %s %s %s\", PDO_ID, PDOnum, PDOdir, PDOnum2, PDOnum3 );
	if ( PDOdir == \"IN\" )
		fputs( PDO_ID + \" = \" + Bus + \" \" + PDOnum + \" \" + PDOdir + \" \" + PDOnum2
				 									+ \" \" + PDOnum3 + \"\\n\", opc );
	else if ( PDOdir == \"OUT\" )
		fputs( PDO_ID + \" = \" + Bus + \" \" + PDOnum + \" \" + PDOdir + \"\\n\", opc );
	else
		{
		fclose(cfg);
		fclose(opc);
		DebugN(\"Error in Reading PDO direction:\", PDOdir);
		return;
		}
	}

// Get PDO Channel Items 
DebugN(\"Setting Channel PDO's...\");
fputs(\"\\n\\n[PDOItem]\\n\", opc);
num = makeDynString(\"\");
byte = OPCItem = type = makeDynInt(0);
index = 0;
while(1)
	{
	fgets( strn, 300, cfg);
	if( strpos (strn, \"[\") != -1) break;
	sscanf( strn, \"%s %d %s %s %s\", OPCItem[1], num[1], type[1], byte[1], card[1] );
	fprintf( opc, 
				Crate + \"_\" + OPCItem[1] + \"   = \" + Crate + \" %d \" + 
				type[1] + \" \" + card[1] + \" \" + byte[1] + \"\\n\",  num[1] );	
	PDOChanAddress(OPCItem[1], type[1], Bus, Crate);
	}

// Get PDO Card Items 
DebugN(\"Setting Card PDO's...\");
num = makeDynString(\"\");
byte = OPCItem = type = makeDynInt(0);
index = 0;
LVCard = 0;
HVCard = 0;
while(1)
	{
	fgets( strn, 300, cfg);
	if( strpos (strn, \"[\") != -1) break;
	sscanf( strn, \"%s %d %s %s\", OPCItem[++index], num[index], type[index], byte[index] );
	}

count = 0;	
	for (index = 1; index <= dynlen(num); index++)
		{
		if ( strpos (OPCItem[index], \"LV\") != -1) count++;
		}

LVCard = HVCard = count2 = 0;		
	for( i=0; i<6; i++)
		{
		for (index = 1; index <= count; index++)
			{
			fprintf( opc, 
					Crate + \"_\" + OPCItem[index] + \"%d  = \" + Crate + \" %d \"
						+ type[index] + \" %d \" + byte[index] + \"\\n\",
													LVCard, num[index], count2 );
		PDOAddress(OPCItem[index], type[index], Bus, Crate, LVCard, \"LV_card\");
			}
		count2++; LVCard++;
		for (index = count+1; index <= dynlen(num); index++)
			{
			fprintf( opc, 
					Crate + \"_\" + OPCItem[index] + \"%d  = \" + Crate + \" %d \"
						+ type[index] + \" %d \" + byte[index] + \"\\n\",
													HVCard, num[index], count2 );
		PDOAddress(OPCItem[index], type[index], Bus, Crate, HVCard, \"HV_card\");
			}
		count2++; HVCard++;
		for (index = 1; index <= count; index++)
			{
			fprintf( opc, 
					Crate + \"_\" + OPCItem[index] + \"%d  = \" + Crate + \" %d \"
						+ type[index] + \" %d \" + byte[index] + \"\\n\",
													LVCard, num[index], count2 );
		PDOAddress(OPCItem[index], type[index], Bus, Crate, LVCard, \"LV_card\");
			}
		count2++; LVCard++;
		}

// Get PDO Items for Crate Controller 
DebugN(\"Setting Crate Controller PDO's...\");
num = makeDynString(\"\");
byte = OPCItem = type = makeDynInt(0);
index = 0;
while(1)
	{
	fgets( strn, 300, cfg);
	if( strpos (strn, \"[\") != -1) break;
	sscanf( strn, \"%s %d %s %s\", OPCItem[++index], num[index], type[index], byte[index] );
	}

	for (index = 1; index <= dynlen(num); index++)
		{
		fprintf( opc, 
				Crate + \"_\" + OPCItem[index] + \"\\t\\t     = \" + Crate + \"  %d \"
				 + type[index] + \" \" + byte[index] + \"\\n\",
														num[index] );
		PDOCCAddress(OPCItem[index], type[index], Bus, Crate, \"Controller\");
		}

// Setting NMT Crate Controller Item
OPCItem[1] = Bus + \".\" + Crate + \".\" + \"NMT\";
dpeName = getSystemName() + Crate + \".Controller.NMT.\";
OPCAddress( dpeName + \"Recv\", \"Moni\", OPCItem[1], \"VT_UI1\" );
OPCAddress( dpeName + \"Send\", \"Comm\", OPCItem[1], \"VT_UI1\" );

// Get INIT Items
DebugN(\"Setting INIT Items...\");
fputs(\"\\n\\n[INIT]\\n\", opc);
num = makeDynString(\"\");
byte = OPCItem = type = makeDynInt(0);
index = 0;
while(1)
	{
	fgets( strn, 300, cfg);
	if( strpos (strn, \"[\") != -1) break;
	sscanf( strn, \"%s %s\", OPCItem[++index], value[index]);
	}

	for (index = 1; index <= dynlen(value); index++)
		{
		fprintf( opc, Bus + \".\" + OPCItem[index] + \"\\t     = \" + value[index] + \"\\n\", num[index] );
		}

//Get more Items
fputs(\"\\n\\n[ITEM]\\n\", opc);
DebugN(\"Loading Additional Items...\"); 
while(1)
	{
	fgets( strn, 300, cfg);
	DebugN(strn);
	if( strpos (strn, \"[END]\") != -1) break;
	fputs(strn, opc);
	ITEMAddress(strn);
	}

fclose(cfg);
fclose(opc);

DebugN(getCurrentTime());  
setValue(\"\",\"foreCol\",\"\");
}

/****************************************************************************\\
|* Settings for other addresses			*|
\\****************************************************************************/
void ITEMAddress(string strn)
{
string OPCItemName, dpeName;
int i;

if( strpos (strn, \"Bus00_Crate01_MOch_Tm0_RecvChan\") != -1) 
	{
	for(i=0; i<48; i++)
		{
		sprintf(OPCItemName, \"Bus00_Crate01_MOch_Tm0_RecvChan%d\", i);
		sprintf(dpeName, getSystemName() + \"Crate01.Channel%02d.MOch_Tm0.Recv\", i);
		}
	}

if( strpos (strn, \"Bus00_Crate01_MOch_Tm1_RecvChan\") != -1)
	{
	for(i=0; i<48; i++)
		{
		sprintf(OPCItemName, \"Bus00_Crate01_MOch_Tm0_RecvChan%d\", i);
		sprintf(dpeName, getSystemName() + \"Crate01.Channel%02d.MOch_Tm1.Recv\", i);
		}
	}

if( strpos (strn, \"Cooling_emergency_rampdown\") != -1)
	{
	OPCItemName = \"Cooling_emergency_rampdown\";
	dpeName = getSystemName() + \"Monitor.Crate_Ramp_Off\";
	}
	
OPCAddress( dpeName, \"Moni\", OPCItemName, \"VT_FLOAT8\" );
}



/****************************************************************************\\
|* This function sets the address values for the SDO OPCItems.				*|
\\****************************************************************************/
void SDOAddress(string OPCItem, string dpeType, string Bus, string Crate, int num, string type)
{
bool ok;
string prefix, OPCItemName, dpeName;

ok = TRUE;
prefix = OPCItem;
switch(type)
	{
	case \"Channel\" : strreplace(prefix, \"_SendChan\", \".Send\"); break;
	case \"LV_card\" : strreplace(prefix, \"_SendCard\", \".Send\"); break;
	case \"HV_card\" : strreplace(prefix, \"_SendCard\", \".Send\"); break;
	default : ok = FALSE; break;
	}
if (!ok)
	{
	DebugN(\"Error! Invalid unit:\", prefix);
	return;
	}
	
if( strpos (prefix, \"IV\") != -1) prefix = \"IVCurve.\" + prefix;

sprintf (OPCItemName, Bus + \".\" + Crate+ \".\" + Crate + \"_\" + OPCItem + \"%d\", num);
sprintf( dpeName, getSystemName() + Crate + \".\" + type + \"%02d.\" + prefix, num );

// Set Address
OPCAddress( dpeName, \"Comm\", OPCItemName, dpeType );
}

/****************************************************************************\\
|* This function sets the address values only for the IVCurve SDO.			*|
\\****************************************************************************/
void SDOIVAddress(string OPCItem, string dpeType, string Bus, string Crate, int num, string type)
{
string prefix, OPCItemName, dpeName;
bool ok = TRUE;

switch( OPCItem )
	{
	case \"IVchStrt_SendChan\" : prefix = \"IVCurve.HV_Start.Send\"; break;
	case \"IVchStop_SendChan\" : prefix = \"IVCurve.HV_Stop.Send\"; break;
	case \"IVchStep_SendChan\" : prefix = \"IVCurve.HV_Step.Send\"; break;
	case \"IVchVend_SendChan\" : prefix = \"IVCurve.HV_End.Send\"; break;
	case \"IVchImax_SendChan\" : prefix = \"IVCurve.Curr_Max.Send\"; break;
	case \"IVchIwar_SendChan\" : prefix = \"IVCurve.Curr_Warn.Send\"; break;
	case \"IVchWait_SendChan\" : prefix = \"IVCurve.TimeWait.Send\"; break;
	default : ok = FALSE; break;
	}
if (!ok)
	{
	DebugN(\"Error! There are not IV Datapoint ending with\", prefix);
	return;
	}
	
sprintf (OPCItemName, Bus + \".\" + Crate+ \".\" + Crate + \"_\" + OPCItem + \"%d\", num);
sprintf( dpeName, getSystemName() + Crate + \".\" + type + \"%02d.\" + prefix, num );

// Set Address
OPCAddress( dpeName, \"Comm\", OPCItemName, dpeType );
}

/****************************************************************************\\
|* This function sets the address for PDO's									*|
\\****************************************************************************/
void PDOAddress(string OPCItem, string dpeType, string Bus, string Crate, int num, string type)
{
bool ok;
string prefix, OPCItemName, dpeName;

ok = TRUE;
prefix = OPCItem;

switch(type)
	{
	case \"Channel\" : strreplace(prefix, \"_RecvChan\", \".Recv\"); break;
	case \"LV_card\" : strreplace(prefix, \"_RecvCard\", \".Recv\"); break;
	case \"HV_card\" : strreplace(prefix, \"_RecvCard\", \".Recv\"); break;
	case \"Controller\" : break;
	default : ok = FALSE; break;
	}
if (!ok)
	{
	DebugN(\"Error! Invalid unit:\", prefix);
	return;
	}

sprintf (OPCItemName, Bus + \".\" + Crate + \".\" + Crate + \"_\" + OPCItem + \"%d\", num);
sprintf( dpeName, getSystemName() + Crate + \".\" + type + \"%02d.\" + prefix, num );

// Set Address
OPCAddress( dpeName, \"Moni\", OPCItemName, dpeType );
}

/****************************************************************************\\
|* This function sets the address for channel PDO's							*|
\\****************************************************************************/
void PDOChanAddress(string OPCItem, string dpeType, string Bus, string Crate)
{
int direction, intDpeType, rc, type, Chan;
string prefix, OPCItemName, dpeName;

prefix = OPCItem;
strreplace(prefix, \"_RecvChan\", \".Recv\");

for(Chan = 0; Chan <48; Chan++)
	{
	sprintf (OPCItemName, Bus + \".\" + Crate+ \".\" + Crate + \"_\" + OPCItem + \"%d\", Chan);
	if( strpos (prefix, \"IV\") != -1)
		sprintf( dpeName, getSystemName() + Crate + \".Channel%02d.IVCurve.Status.Recv\", Chan );
	else
		sprintf( dpeName, getSystemName() + Crate + \".Channel%02d.\" + prefix, Chan );
	
	// Set Address
	OPCAddress( dpeName, \"Moni\", OPCItemName, dpeType );
	}
}


/****************************************************************************\\
|* This function sets the address values only for the Crate Controller. 	*|
\\****************************************************************************/
void PDOCCAddress(string OPCItem, string dpeType, string Bus, string Crate, string type)
{
string prefix, OPCItemName, dpeName;
bool ok = TRUE;

switch( OPCItem )
	{
	case \"Set\"		: prefix = \"CCch_Set.Send\"; break;
	case \"Read\" 	: prefix = \"CCchRead.Send\"; break;
	case \"IVcurve\"	: prefix = \"StartIVCurve.Send\"; break;
	default : ok = FALSE; break;
	}
if (!ok)
	{
	DebugN(\"Error! There are not OPCItem\", OPCItem);
	return;
	}
	
	OPCItemName = Bus + \".\" + Crate + \".\" + Crate + \"_\" + OPCItem;
	dpeName = getSystemName() + Crate + \".\" + type + \".\" + prefix;

// Set Address
OPCAddress( dpeName, \"Comm\", OPCItemName, dpeType );
}
	
/****************************************************************************\\
|* This function sets the address for datapoint dpeName						*|
\\****************************************************************************/
OPCAddress(string dpeName, string OPCGroup, string OPCItemName, string dpeType )
{
string reference;
int direction, intDpeType, rc, type;
dyn_errClass err;
bool ok;
 
ok = TRUE;
// check if the datapoint exists
if (!dpExists (dpeName))
	{
	DebugN(\"Error! Datapoint\", dpeName, \"doesn't exist!\");
	return;
	}

// check if the address already exists
rc = dpGet (dpeName+\":_address.._type\", type);
err = getLastError ();	
if (rc | dynlen(err))
	{
	DebugN(\"Failed to check whether address already exists for dpe: \"+dpeName+\" : \"+rc);
	return;
	}
// if it exists, deactivate the alarm handling (so we can change it)
if (type != DPCONFIG_NONE)
	{
	dpSetWait(dpeName + \":_address.._type\", DPCONFIG_NONE);  // delete previous address
	}

//Values for intDpeType:
switch(dpeType)
	{
	case \"VT_UI1\":    intDpeType = 0;    break;  //uint8
	case \"VT_UI2\":    intDpeType = 488;  break;  //uint16
	case \"VT_UI4\":    intDpeType = 489;  break;  //uint32
	case \"VT_I1\":     intDpeType = 0;    break;  //int8
	case \"VT_I2\":     intDpeType = 481;	 break;  //int16
	case \"VT_I4\":     intDpeType = 482;	 break;  //int32
	case \"VT_FLOAT4\": intDpeType = 484;  break;  //float32
	case \"VT_FLOAT8\": intDpeType = 485;  break;  //float64
	case \"VT_BOOL\":   intDpeType = 486;  break;  //Bool
	case \"VT_STRING\": intDpeType = 487;  break;  //string
	case \"default\":   intDpeType = 0;    break;  //default
	default: ok = FALSE;
	}

if (!ok)
	{
	DebugN(\"Error! The element type \", dpeType, \"is invalid for OPC server\");
	return;
	}

	if(OPCGroup == \"Comm\") 
		direction = DPATTR_ADDR_MODE_OUTPUT_SINGLE;	//output for single queries
	else if(OPCGroup == \"Moni\") 
		direction = DPATTR_ADDR_MODE_INPUT_SPONT;	//input for spontaneous data
	else
		{
		DebugN(\"Error! Invalid group:\", OPCGroup);
		return;
		}

	reference = \"CANopen$\" + OPCGroup + \"$\" + OPCItemName; 

   dpSetWait(dpeName + \":_distrib.._type\", DPCONFIG_DISTRIBUTION_INFO, 
             dpeName + \":_distrib.._driver\", 1);               //driver number 1

   dpSetWait(dpeName + \":_address.._type\", DPCONFIG_PERIPH_ADDR_MAIN, // general peripheral address
             dpeName + \":_address.._reference\", reference,
             dpeName + \":_address.._datatype\" , intDpeType,
             dpeName + \":_address.._mode\"     , direction,
             dpeName + \":_address.._drv_ident\", \"OPCCLIENT\");
/*           
DebugN(dpeName);
DebugN(reference);
DebugN(\"---------\");*/
} 
setOPCGroup(string groupName, int  UpdateRate, string DataSource,
                            					bool   enableCallBack)
{
bool DataSourceDevice;
	
     //rename groupName just the internal name form
   groupName = \"_\" + groupName;
     //create groupName datapoint if it does not already exist 
  if (!dpExists(groupName))
	{ //create groupName datapoint of type _OPCGroup (PVSS internal type)
	dpCreate(groupName, \"_OPCGroup\"); 
	}
     //set some of the groupName datapoint elements
  dpSet(groupName+\".UpdateRateReq:_original.._value\", UpdateRate);
  if(DataSource == \"Device\")
	{
	DataSourceDevice = TRUE;
	}
  else
	{
	DataSourceDevice =FALSE;
	}

  dpSet(groupName+\".DataSourceDevice:_original.._value\", DataSourceDevice);
  dpSet(groupName+\".Active:_original.._value\", TRUE);
  dpSet(groupName+\".EnableCallback:_original.._value\", enableCallBack);
}
" 0
 E E E
13 31
"Button5"
""
1 244 490 E E E 1 E 1 E N "_3DText" E N {102,204,255} E E
 E E
26 0 0 0 0 0
EE E
0
1
LANG:1 0 
0
1
LANG:1 105 -microsoft windows-Arial-bold-r-normal-*-*-140-100-100-*-*-iso8859-1|-16,0,0,0,700,0,0,0,0,3,2,1,34,Arial
0 ""
38 338 272 402
T 
1
LANG:1 20 Create OPC Conf file
"//Create OPC File
/******************************************************************************\\
123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789
|*=====================================-======================================*|
|*			               SCT POWER SUPPLIES MODULES     		              *|
|*=====================================-======================================*|
|*   AUTHORs:        G.Codispoti - codispoti@cs.infn.it			    		  *|
|*								   Giuseppe.Codispoti@cern.ch			      *|
|*																		      *|
|*   DESIGN ISSUEs:  This Script create the file \"OPCCanServer.cfg\".		  *|
|*																		      *|
|*   MODIF_HISTORY:  17.03.2003  - first release						      *|
|*																		      *|
\\******************************************************************************/
main()
{
file cfg, opc;
string path, strn, Crate, Bus, driver, port, baudrate, dpeName, plus;
string PDO_ID, PDOnum, PDOdir, PDOnum2, PDOnum3, date;
int err, nbus, i, index, count, count2, LVCard, HVCard, n;
dyn_int num;
dyn_string byte, OPCItem, type, card, value;
time tm;
bool ok = TRUE;

setValue(\"\",\"foreCol\",\"Red\");
DebugN(getCurrentTime());  
Crate = \"Crate00\";
Bus = \"Bus00\";
index = 0;

// Check if the opc configuration is already stored in the PVSS datapoint
if (!dpExists(\"_CANopen\"))
	{ 
    dpCreate(\"_CANopen\", \"_OPCServer\"); 
    dpSet(\"_CANopen.StateTimer:_original.._value\", 10);
    dpSet(\"_CANopen.ReconnectTimer:_original.._value\", 10);
    DebugN(\"OPC DP created!\");
    setOPCGroup(\"Comm\", 1000, \"Device\", FALSE); 
	setOPCGroup(\"Moni\",  100, \"Cache\" , TRUE);
	}


/* Opening configuration database */
path = getPath(PANELS_REL_PATH, \"OPCsettings.cfg\");
cfg = fopen(path,\"r\");
err = ferror(cfg); // export error
if (err)
	{ 
	DebugN(\"Error no. \",err,\" occurred: not able to open file:\", path);
	return;
	}

/* open new file for OPC configuration */
DebugN(\"Creating file C:/ETM/OPCCANopenserver/OPCCanServer.cfg\");
tm = getCurrentTime();
date = formatTime(\"%d%m%y\", tm);
//look at other files created in the same day
n = dynlen (getFileNames(\"C://ETM//OPCCANopenserver//\", \"OPCCanServer_\" 
														+ date + \"*.cfg\"));
//if there are previos files with same date, add a (n)
if (n!=0) sprintf(plus, date + \"(%d)\", n);
else plus = date;
DebugN(n, plus);
// copy the old file in a new *_date or *_date(n) file
ok = copyFile(\"C://ETM//OPCCANopenserver//OPCCanServer.cfg\",
		 \"C://ETM//OPCCANopenserver//OPCCanServer_\" + plus + \".cfg\");
if(!ok)
	{
	DebugN(\"Error in moving old OPCCanServer.cfg. Creating file in the panels directory\");
	//if the rename faults, the file will be created in the panel directory
	path = strrtrim(path, \"OPCsettings.cfg\") + \"OPCCanServer.cfg\";
	}
else path = \"C://ETM//OPCCANopenserver//OPCCanServer.cfg\";
opc = fopen(path,\"w\");
err = ferror(opc); // export error
if (err)
	{ 
	DebugN(\"Error no. \",err,\" occurred: not able to create file:\", path);
	fclose(cfg);
	return;
	}


//get general info
fgets(strn, 300, cfg);
fgets(strn, 300, cfg);
sscanf( strn, \"Bus	%d\", nbus );
fgets(strn, 300, cfg);
sscanf( strn, \"Driver	%s\", driver);
fgets(strn, 300, cfg);
sscanf( strn, \"Port	%s\", port);
fgets(strn, 300, cfg);
sscanf( strn, \"Baudrate	%s\", baudrate);
fgets(strn, 300, cfg);


fputs(\"[CANBUS]\\n\" + Bus + \" = \" + driver + \" \" + port + \" \" + baudrate
					+ \"\\n\\n[DEVICE]\\n\"
					 + Crate + \" = \" + Bus + \" 1 NG\\n\\n[SDOItem]\\n\", opc);

// Get SDO Channel Items
DebugN(\"Setting Channel SDO's...\");
while(1)
	{
	fgets( strn, 300, cfg);
	if( strpos (strn, \"[\") != -1) break;
	sscanf( strn, \"%s %x %s %s\", OPCItem[++index], num[index], byte[index], type[index] );
	}

for (i=0; i<48; i++)
	{
	for (index = 1; index <= dynlen(num); index++)
		{
		fprintf( opc, 
				Crate + \"_\" + OPCItem[index] + \"%d  = \" + Crate + \"  %x \"
				 + byte[index] + \" IO \" + type[index] + \"\\n\",
													i, num[index] + i );
		}
	}

// Get SDO Card Items
DebugN(\"Setting Card SDO's...\");
num = makeDynString(\"\");
byte = OPCItem = type = makeDynInt(0);
LVCard = HVCard = count = 0;
index = 0;
while(1)
	{
	fgets( strn, 300, cfg);
	if( strpos (strn, \"[\") != -1) break;
	sscanf( strn, \"%s %x %s %s\",
			OPCItem[++index], num[index], byte[index], type[index] );
	}
	
for (index = 1; index <= dynlen(num); index++)
	{
	if ( strpos (OPCItem[index], \"LV\") != -1) count++;
	}

for (i=0; i<6; i++)
	{
	for (index = 1; index <= count; index++)
		{
		fprintf( opc, 
				Crate + \"_\" + OPCItem[index] + \"%d  = \" + Crate + \"  %x \"
				 + byte[index] + \" IO \" + type[index] + \"\\n\",
													LVCard, num[index] + LVCard );
		}
	LVCard++;
	for (index = count+1; index <= dynlen(num); index++)
		{
		fprintf( opc, 
				Crate + \"_\" + OPCItem[index] + \"%d  = \" + Crate + \"  %x \"
				 + byte[index] + \" IO \" + type[index] + \"\\n\",
												HVCard, num[index] + HVCard );
			}
	HVCard++;
	for (index = 1; index <= count; index++)
		{
		fprintf( opc, 
					Crate + \"_\" + OPCItem[index] + \"%d  = \" + Crate + \"  %x \"
					 + byte[index] + \" IO \" + type[index] + \"\\n\",
														LVCard, num[index] + LVCard );
		}
	LVCard++;
	}

// Get SDO for IVCurve 
DebugN(\"Setting Channel IVCurve SDO's...\");
num = makeDynString(\"\");
byte = OPCItem = type = makeDynInt(0);
index = 0;

while(1)
	{
	fgets( strn, 300, cfg);
	if( strpos (strn, \"[\") != -1) break;
	sscanf( strn, \"%s %x %s %s\", OPCItem[++index], num[index], byte[index], type[index] );
	}

for (i=0; i<48; i++)
	{
	for (index = 1; index <= dynlen(num); index++)
		{
		fprintf( opc, 
				Crate + \"_\" + OPCItem[index] + \"%d  = \" + Crate + \"  %x \"
				 + byte[index] + \" IO \" + type[index] + \"\\n\",
													i, num[index] + i );
		}
	}

// Get PDO Values 
DebugN(\"Setting PDO's values...\");
fputs(\"\\n\\n[PDO]\\n\", opc);
num = makeDynString(\"\");
byte = OPCItem = type = makeDynInt(0);
index = 0;
while(1)
	{
	fgets( strn, 300, cfg);
	if( strpos (strn, \"[\") != -1) break;
	strreplace( strn, \"\\t\", \" \");
	sscanf( strn, \"%s %s %s %s %s\", PDO_ID, PDOnum, PDOdir, PDOnum2, PDOnum3 );
	if ( PDOdir == \"IN\" )
		fputs( PDO_ID + \" = \" + Bus + \" \" + PDOnum + \" \" + PDOdir + \" \" + PDOnum2
				 									+ \" \" + PDOnum3 + \"\\n\", opc );
	else if ( PDOdir == \"OUT\" )
		fputs( PDO_ID + \" = \" + Bus + \" \" + PDOnum + \" \" + PDOdir + \"\\n\", opc );
	else
		{
		fclose(cfg);
		fclose(opc);
		DebugN(\"Error in Reading PDO direction:\", PDOdir);
		return;
		}
	}

// Get PDO Channel Items 
DebugN(\"Setting Channel PDO's...\");
fputs(\"\\n\\n[PDOItem]\\n\", opc);
num = makeDynString(\"\");
byte = OPCItem = type = makeDynInt(0);
index = 0;
while(1)
	{
	fgets( strn, 300, cfg);
	if( strpos (strn, \"[\") != -1) break;
	sscanf( strn, \"%s %d %s %s %s\", OPCItem[1], num[1], type[1], byte[1], card[1] );
	fprintf( opc, 
				Crate + \"_\" + OPCItem[1] + \"   = \" + Crate + \" %d \" + 
				type[1] + \" \" + card[1] + \" \" + byte[1] + \"\\n\",  num[1] );	
	}

// Get PDO Card Items 
DebugN(\"Setting Card PDO's...\");
num = makeDynString(\"\");
byte = OPCItem = type = makeDynInt(0);
index = 0;
LVCard = 0;
HVCard = 0;
while(1)
	{
	fgets( strn, 300, cfg);
	if( strpos (strn, \"[\") != -1) break;
	sscanf( strn, \"%s %d %s %s\", OPCItem[++index], num[index], type[index], byte[index] );
	}

count = 0;	
	for (index = 1; index <= dynlen(num); index++)
		{
		if ( strpos (OPCItem[index], \"LV\") != -1) count++;
		}

LVCard = HVCard = count2 = 0;		
	for( i=0; i<6; i++)
		{
		for (index = 1; index <= count; index++)
			{
			fprintf( opc, 
					Crate + \"_\" + OPCItem[index] + \"%d  = \" + Crate + \" %d \"
						+ type[index] + \" %d \" + byte[index] + \"\\n\",
													LVCard, num[index], count2 );
			}
		count2++; LVCard++;
		for (index = count+1; index <= dynlen(num); index++)
			{
			fprintf( opc, 
					Crate + \"_\" + OPCItem[index] + \"%d  = \" + Crate + \" %d \"
						+ type[index] + \" %d \" + byte[index] + \"\\n\",
													HVCard, num[index], count2 );
			}
		count2++; HVCard++;
		for (index = 1; index <= count; index++)
			{
			fprintf( opc, 
					Crate + \"_\" + OPCItem[index] + \"%d  = \" + Crate + \" %d \"
						+ type[index] + \" %d \" + byte[index] + \"\\n\",
													LVCard, num[index], count2 );
			}
		count2++; LVCard++;
		}

// Get PDO Items for Crate Controller 
DebugN(\"Setting Crate Controller PDO's...\");
num = makeDynString(\"\");
byte = OPCItem = type = makeDynInt(0);
index = 0;
while(1)
	{
	fgets( strn, 300, cfg);
	if( strpos (strn, \"[\") != -1) break;
	sscanf( strn, \"%s %d %s %s\", OPCItem[++index], num[index], type[index], byte[index] );
	}

	for (index = 1; index <= dynlen(num); index++)
		{
		fprintf( opc, 
				Crate + \"_\" + OPCItem[index] + \"\\t\\t     = \" + Crate + \"  %d \"
				 + type[index] + \" \" + byte[index] + \"\\n\",
														num[index] );
		}

// Get INIT Items
DebugN(\"Setting INIT Items...\");
fputs(\"\\n\\n[INIT]\\n\", opc);
num = makeDynString(\"\");
byte = OPCItem = type = makeDynInt(0);
index = 0;
while(1)
	{
	fgets( strn, 300, cfg);
	if( strpos (strn, \"[\") != -1) break;
	sscanf( strn, \"%s %s\", OPCItem[++index], value[index]);
	}

	for (index = 1; index <= dynlen(value); index++)
		{
		fprintf( opc, Bus + \".\" + OPCItem[index] + \"\\t     = \" + value[index] + \"\\n\", num[index] );
		}

//Get more Items
fputs(\"\\n\\n[ITEM]\\n\", opc);
DebugN(\"Loading Additional Items...\"); 
while(1)
	{
	fgets( strn, 300, cfg);
	DebugN(strn);
	if( strpos (strn, \"[END]\") != -1) break;
	fputs(strn, opc);
	}

fclose(cfg);
fclose(opc);

DebugN(getCurrentTime());  
setValue(\"\",\"foreCol\",\"\");
}" 0
 E E E
13 32
"Button4"
""
1 330 60 E E E 1 E 1 E N "_3DText" E N {255,128,64} E E
 E E
26 0 0 0 0 0
EE E
0
1
LANG:1 0 
0
1
LANG:1 105 -microsoft windows-Arial-bold-r-normal-*-*-140-100-100-*-*-iso8859-1|-16,0,0,0,700,0,0,0,0,3,2,1,34,Arial
0 ""
328 58 562 122
T 
1
LANG:1 19 Delete DPs and DPTs
"//Delete DPs & DPTs
//DPT Clean
/******************************************************************************\\
123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789
|*=====================================-======================================*|
|*                 SCT COOLING SYSTEM CONTROL AND MONITORING                  *|
|*=====================================-======================================*|
|*   AUTHORs:        G.Codispoti - codispoti@cs.infn.it			    		  *|
|*								   Giuseppe.Codispoti@cern.ch			      *|
|*																		      *|
|*   DESIGN ISSUEs:  This Script deletes only the DPTs foreseen for MoPS      *|
|*					 and related DPs.									      *|
|*																		      *|
|*   MODIF_HISTORY:  17.03.2003  - first release						      *|
|*																		      *|
\\******************************************************************************/

main()
{
  dyn_dyn_int dpType;
  dyn_dyn_string dpName;
  dyn_string dpAllTypes;
  string chan, LV, HV;
  int i, j, index, count, lengh;
  dyn_string Send, Recv, Send2, Recv2;

 
  setValue(\"\",\"foreCol\",\"Red\");


   if(dpTypeExists(makeDynString(\"MPS_Crates\")))
  	{
  	// Deleting Configs before DP!
	DebugN(getCurrentTime(), \": Start Deleting Configs (Alert, Addresses & Co.)\");
	
	Send  = dpNames(\"*.*.*.Send\", \"MPS_Crates\");
	Recv  = dpNames(\"*.*.*.Recv\", \"MPS_Crates\");
	Send2 = dpNames(\"*.*.*.*.Send\", \"MPS_Crates\");
	Recv2 = dpNames(\"*.*.*.*.Recv\", \"MPS_Crates\");
	
	if (dynlen(Send) < dynlen(Recv)) 	lengh = dynlen(Recv);
	else 								lengh = dynlen(Send);
	
	for(i=1; i<=lengh; i++)
		{
		if(i <= dynlen(Send))  confDel(Send[i]);
		if(i <= dynlen(Recv))  confDel(Recv[i]);
		if(i <= dynlen(Send2)) confDel(Send2[i]);
		if(i <= dynlen(Recv2)) confDel(Recv2[i]);
		}
	DebugN(getCurrentTime(), \": Configs Deleted!\");

  	deleteDpType(makeDynString(\"MPS_Crates\"));
	DebugN(\"MPS_Crates deleted\");
}
//*************************************************************************/  
  if(dpTypeExists(makeDynString(\"ps_chan\")))
  	{
  		deleteDpType(makeDynString(\"ps_chan\"));
  		  DebugN(\"ps_chan deleted\" );
  	}
//*************************************************************************/    
  if(dpTypeExists(makeDynString(\"ps_crate\")))
  	{
  		deleteDpType(makeDynString(\"ps_crate\"));
		DebugN(\"ps_crate deleted\");
  	}
//*************************************************************************/ 
  //remove the type if exist
  if(dpTypeExists(makeDynString(\"ps_alert\")))
  	{
  		deleteDpType(makeDynString(\"ps_alert\"));
  DebugN(\"ps_alert deleted\");
  	}
//*************************************************************************/       
  if(dpTypeExists(makeDynString(\"hv_card\")))
  	{
  		deleteDpType(makeDynString(\"hv_card\"));
  DebugN(\"hv_card deleted\");
  	}
//*************************************************************************/      
  if(dpTypeExists(makeDynString(\"lv_card\")))
  	{
  		deleteDpType(makeDynString(\"lv_card\"));
  DebugN(\"lv_card deleted\");
  	}
//*************************************************************************/      
  if(dpTypeExists(makeDynString(\"MPS_Settings\")))
  	{
  		deleteDpType(makeDynString(\"MPS_Settings\"));
  DebugN(\"MPS_Settings deleted\");
  	}
//*************************************************************************/ 
  if(dpTypeExists(makeDynString(\"IVCurve\")))
  	{
  		deleteDpType(makeDynString(\"IVCurve\"));
  DebugN(\"IVCurve deleted\");
  	}
//*************************************************************************/  
  if(dpTypeExists(makeDynString(\"DCS_IVCurve\")))
  	{
  		deleteDpType(makeDynString(\"DCS_IVCurve\"));
  DebugN(\"DCS_IVCurve deleted\");
  	}
/**************************************************************************/   		
  if(dpTypeExists(makeDynString(\"DCS_Cooling\")))
  	{
  		deleteDpType(makeDynString(\"DCS_Cooling\"));
  DebugN(\"DCS_Cooling deleted\");
  	}
/**************************************************************************/   
  if(dpTypeExists(makeDynString(\"ps_data_recv\")))
  	{
  		deleteDpType(makeDynString(\"ps_data_recv\"));
  DebugN(\"ps_data_recv deleted\");
  	}
//*************************************************************************/ 
  if(dpTypeExists(makeDynString(\"ps_data_send\")))
  	{
  		deleteDpType(makeDynString(\"ps_data_send\"));
  DebugN(\"ps_data_send deleted\");
  	}
//*************************************************************************/ 
  if(dpTypeExists(makeDynString(\"ps_data_dupl\")))
  	{
  		deleteDpType(makeDynString(\"ps_data_dupl\"));
   DebugN(\"ps_data_dupl deleted\");
  	}
//*************************************************************************/ 
  if(dpTypeExists(makeDynString(\"ps_stat_recv\")))
  	{
  		deleteDpType(makeDynString(\"ps_stat_recv\"));
 		 DebugN(\"ps_stat_recv deleted\");
  	}
//*************************************************************************/ 
  if(dpTypeExists(makeDynString(\"ps_stat_send\")))
  	{
  		deleteDpType(makeDynString(\"ps_stat_send\"));
  DebugN(\"ps_stat_send deleted\");
  	}
//*************************************************************************/ 
  if(dpTypeExists(makeDynString(\"ps_stat_dupl\")))
  	{
  		deleteDpType(makeDynString(\"ps_stat_dupl\"));
  DebugN(\"ps_stat_dupl deleted\");
  	}
//*************************************************************************/ 
  if(dpTypeExists(makeDynString(\"DCS_Hist\")))
  	{
  		deleteDpType(makeDynString(\"DCS_Hist\"));
  DebugN(\"DCS_Hist deleted\");
  	}
//*************************************************************************/ 
  if(dpTypeExists(makeDynString(\"DCS_Settings\")))
  	{
  		deleteDpType(makeDynString(\"DCS_Settings\"));
	DebugN(\"DCS_Settings deleted\");	
  	}
//*************************************************************************/ 
  if(dpTypeExists(makeDynString(\"DCS_Limi\")))
  	{
  		deleteDpType(makeDynString(\"DCS_Limi\"));
		DebugN(\"DCS_Limi deleted\");
  	}
//*************************************************************************/ 
  if(dpTypeExists(makeDynString(\"DdcCommand\")))
  	{
  		deleteDpType(makeDynString(\"DdcCommand\"));
 	DebugN(\"DdcCommand deleted\");
  	}
//*************************************************************************/ 
  if(dpTypeExists(makeDynString(\"DCS_Plot\")))
  	{
  		deleteDpType(makeDynString(\"DCS_Plot\"));
	DebugN(\"DCS_Plot deleted\");
  	}
//*************************************************************************/ 
  if(dpTypeExists(makeDynString(\"DCS_Indi\")))
  	{
  		deleteDpType(makeDynString(\"DCS_Indi\"));
	DebugN(\"DCS_Indi deleted\");
  	}
//*************************************************************************/ 
  if(dpTypeExists(makeDynString(\"DCS_Host\")))
  	{
 		deleteDpType(makeDynString(\"DCS_Host\"));
	DebugN(\"DCS_Host deleted\"); 
  	}
//*************************************************************************/ 
  if(dpTypeExists(makeDynString(\"DCS_Unit\")))
  	{
 		deleteDpType(makeDynString(\"DCS_Unit\"));
	DebugN(\"DCS_Unit deleted\");
  	}
//*************************************************************************/ 
  if(dpTypeExists(makeDynString(\"gp_node\")))
  	{
  		deleteDpType(makeDynString(\"gp_node\"));
	DebugN(\"gp_node deleted\");
  	}
//*************************************************************************/ 
  if(dpTypeExists(makeDynString(\"gp_port\")))
  	{
 		deleteDpType(makeDynString(\"gp_port\"));
	DebugN(\"gp_port deleted\");
  	}
//*************************************************************************/ 
  if(dpTypeExists(makeDynString(\"gp_chan\")))
  	{
  		deleteDpType(makeDynString(\"gp_chan\"));
	DebugN(\"gp_chan deleted\");
  	}
//*************************************************************************/ 
  if(dpTypeExists(makeDynString(\"ErrorMesg\")))
  	{
 		deleteDpType(makeDynString(\"ErrorMesg\"));
	DebugN(\"ErrorMesg deleted\");
  	}	
//*************************************************************************/ 
  if(dpTypeExists(makeDynString(\"ps_iv_send\")))
  	{
 		deleteDpType(makeDynString(\"ps_iv_send\"));
	DebugN(\"ps_iv_send deleted\");
  	}
//*************************************************************************/ 
  if(dpTypeExists(makeDynString(\"MPS_Testing\")))
  	{
 		deleteDpType(makeDynString(\"MPS_Testing\"));
	DebugN(\"MPS_Testing deleted\");
  	}

    setValue(\"\",\"foreCol\",\"\");
}
/****************************************END*******************************\\  
\\**************************************************************************/

//this subroutine check the existence of a given type
bool dpTypeExists(string dpType)
{
  int index;
  dyn_string dpAllTypes;
  
  //get all types
  dpAllTypes = dpTypes();
  
  //check the existence of the given type 
  for(index=1; index<=dynlen(dpAllTypes); index++)
  	{
  		if(dpAllTypes[index] == dpType) return 1;
  	}
  
  return 0;
}

//this subroutine deletes a given type. to do so, it deletes all 
//the datapoint of this type then delete the type
deleteDpType(string dpType)
{
  int index;
  dyn_string dpAllNames;

  //get all datapoint of the given type
  dpAllNames = dpNames(\"*\", dpType);
  
  //delete all the datapoint of the given type
  for(index=1; index<=dynlen(dpAllNames); index++)
  	{
  		dpDelete(dpAllNames[index]);
  	}
  
  //delete the type
  dpTypeDelete(dpType);
}

confDel(string dpeName)
{
int direction, intDpeType, rc, type;
dyn_errClass err;
bool ok;

//DebugN(dpeName);

dpSetWait(dpeName + \":_address.._type\",  DPCONFIG_NONE);
dpSetWait(dpeName + \":_msg_conv.._type\", DPCONFIG_NONE);
dpSetWait(dpeName + \":_cmd_conv.._type\", DPCONFIG_NONE);

// check if the alarm already exists
rc = dpGet (dpeName+\":_alert_hdl.._type\", type);
err = getLastError ();	
if (rc | dynlen(err))
	{
	DebugN(\"Failed to check whether alarm already exists for dpe: \"+dpeName+\" : \"+rc);
	throwError (err);
	return;
	}

// if it exists, deactivate the alarm handling (so we can change it)
if (type != DPCONFIG_NONE)
	{
	dpDeactivateAlert (dpeName, ok);		
	if ( ! ok)
		{
		DebugN(\"Failed to deactivate alarm on dpe: \"+dpeName);
		return;
		}
	dpSetWait(dpeName+\":_alert_hdl.._ack\",  DPATTR_ACKTYPE_MULTIPLE);
	dpSetWait(dpeName+\":_alert_hdl.._type\", DPCONFIG_NONE);
	}
}" 0
 E E E
13 33
"Button6"
""
1 330 200 E E E 1 E 1 E N "_3DText" E N {255,128,64} E E
 E E
26 0 0 0 0 0
EE E
0
1
LANG:1 0 
0
1
LANG:1 105 -microsoft windows-Arial-bold-r-normal-*-*-140-100-100-*-*-iso8859-1|-16,0,0,0,700,0,0,0,0,3,2,1,34,Arial
0 ""
328 198 562 262
T 
1
LANG:1 17 Acknoledge Alerts
"//Acknoledge Alerts
//DPT Clean
/******************************************************************************\\
123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789
|*=====================================-======================================*|
|*                 SCT COOLING SYSTEM CONTROL AND MONITORING                  *|
|*=====================================-======================================*|
|*   AUTHORs:        G.Codispoti - codispoti@cs.infn.it			    		  *|
|*								   Giuseppe.Codispoti@cern.ch			      *|
|*																		      *|
|*   DESIGN ISSUEs:  This Script aknoledge Alerts avoiding error messages     *|
|*					 at the project start-up.							      *|
|*																		      *|
|*   MODIF_HISTORY:  17.03.2003  - first release						      *|
|*																		      *|
\\******************************************************************************/

main()
{
int i, lengh;
dyn_string Send, Recv, Send2, Recv2;

setValue(\"\",\"foreCol\",\"Red\");

DebugN(getCurrentTime(), \": Start Deactivate Alerts\");

Send = dpNames(\"*.*.*.Send\", \"MPS_Crates\");
Recv = dpNames(\"*.*.*.Recv\", \"MPS_Crates\");
Send2 = dpNames(\"*.*.*.*.Send\", \"MPS_Crates\");
Recv2 = dpNames(\"*.*.*.*.Recv\", \"MPS_Crates\");

if (dynlen(Send) < dynlen(Recv))
		lengh = dynlen(Recv);
else lengh = dynlen(Send);

for(i=1; i<=lengh; i++)
	{
	if(i <= dynlen(Send)) confDel(Send[i]);
	if(i <= dynlen(Recv)) confDel(Recv[i]);
	if(i <= dynlen(Send2)) confDel(Send2[i]);
	if(i <= dynlen(Recv2)) confDel(Recv2[i]);
	}
DebugN(getCurrentTime(), \": Alerts Deactivated!\");

  setValue(\"\",\"foreCol\",\"\");
}

confDel(string dpeName)
{
int direction, intDpeType, rc, type;
dyn_errClass err;
bool ok;

//DebugN(dpeName);

	// check if the alarm already exists
	rc = dpGet (dpeName+\":_alert_hdl.._type\", type);
	err = getLastError ();	
	if (rc | dynlen(err))
		{
		DebugN(\"Failed to check whether alarm already exists for dpe: \"+dpeName+\" : \"+rc);
		throwError (err);
		return;
		}

	// if it exists, deactivate the alarm handling (so we can change it)
	if (type != DPCONFIG_NONE)
		{
		dpSetWait(dpeName+\":_alert_hdl.._ack\", DPATTR_ACKTYPE_MULTIPLE);
/*		dpDeactivateAlert (dpeName, ok);		
		if ( ! ok)
			{
			DebugN(\"Failed to deactivate alarm on dpe: \"+dpeName);
			return;
			}*/
		}

}" 0
 E E E
13 34
"Button7"
""
1 177 460 E E E 1 E 1 E N "_3DText" E N {102,204,255} E E
 E E
26 0 0 0 0 0
EE E
0
1
LANG:1 0 
0
1
LANG:1 105 -microsoft windows-Arial-bold-r-normal-*-*-140-100-100-*-*-iso8859-1|-16,0,0,0,700,0,0,0,0,3,2,1,34,Arial
0 ""
38 268 272 332
T 
1
LANG:1 14 Set Conversion
"//Set Conversions
/******************************************************************************\\
123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789
|*=====================================-======================================*|
|*			               SCT POWER SUPPLIES MODULES     		              *|
|*=====================================-======================================*|
|*   AUTHORs:        G.Codispoti - codispoti@cs.infn.it			    		  *|
|*								   Giuseppe.Codispoti@cern.ch			      *|
|*																		      *|
|*   DESIGN ISSUEs:  This Script add DPe conversions using	 			      *|
|*					 the function \"Conversion\".								  *|
|*																		      *|
|*   MODIF_HISTORY:  17.03.2003  - first release						      *|
|*																		      *|
\\******************************************************************************/
main()
{
string 	prefix, Crate, dpeName;
int i, crat, UnitMax;

UnitMax = 1;
setValue(\"\",\"foreCol\",\"Red\");
		
for ( crat = 0; crat < UnitMax; crat++ )
	{
	DebugN(\" Setting Conversion for Crate \", Crate);
	sprintf( Crate, \"Crate%02d\", crat);

	/* Channels Conversion *******************************************/
		for(i=0; i<48; i++)
		{
		sprintf( prefix, getSystemName() + Crate + \".Channel%02d.\", i );
	
		dpeName		= \"LVch_Vcc.Send\";
		Conversion(prefix + dpeName, \"OUT\", 0.0, 1000.0 / 20.0);

		dpeName 	= \"LVch_Vdd.Send\";
		Conversion(prefix + dpeName, \"OUT\", 0.0, 1000.0 / 20.0);

		dpeName 	= \"LVchVCSV.Send\";
		Conversion(prefix + dpeName, \"OUT\", 0.0, 1000.0 / 40.0);
		
		dpeName 	= \"LVchPINV.Send\";
		Conversion(prefix + dpeName, \"OUT\", 0.0, 1000.0 / 50.0);
		
		dpeName		= \"LVchDTrp.Send\";
		Conversion(prefix + dpeName, \"OUT\", 0.0, 1.0 / 2.0);
		
		dpeName 	= \"LVchCTrp.Send\";
		Conversion(prefix + dpeName, \"OUT\", 0.0, 1.0 / 2.0);

		dpeName 	= \"LVchTLim.Send\";
		Conversion(prefix + dpeName, \"OUT\", 128.0, 1.0);

		dpeName 	= \"LVchTTrp.Send\";
		Conversion(prefix + dpeName, \"OUT\", 128.0, 1.0);

		dpeName 	= \"HVchITrp.Send\";
		Conversion(prefix + dpeName, \"OUT\", 0.0, 1.0);

		dpeName 	= \"HVchRamp.Send\";
		Conversion(prefix + dpeName, \"OUT\", 0.0, 1.0);
			
		dpeName 	= \"LVch_Vcc.Recv\";
		Conversion(prefix + dpeName, \"IN\", 0.0, 20.0 / 1000.0);
	
		dpeName 	= \"LVps_Vcc.Recv\";
		Conversion(prefix + dpeName, \"IN\", 0.0, 50.0 / 1000.0);

		dpeName 	= \"LVretVcc.Recv\";
		Conversion(prefix + dpeName, \"IN\", 0.0, 20.0 / 1000.0);

		dpeName 	= \"LVch_Icc.Recv\";
		Conversion(prefix + dpeName, \"IN\", 0.0, 10.0);

		dpeName		= \"LVch_Vdd.Recv\";
		Conversion(prefix + dpeName, \"IN\", 0.0, 20.0 / 1000.0);

		dpeName		= \"LVps_Vdd.Recv\";
		Conversion(prefix + dpeName, \"IN\", 0.0, 50.0 / 1000.0);

		dpeName 	= \"LVretVdd.Recv\";
		Conversion(prefix + dpeName, \"IN\", 0.0, 20.0 / 1000.0);

		dpeName 	= \"LVch_Idd.Recv\";
		Conversion(prefix + dpeName, \"IN\", 0.0, 10.0);

		dpeName 	= \"LVchVCSV.Recv\";
		Conversion(prefix + dpeName, \"IN\", 0.0, 40.0 / 1000.0);

		dpeName 	= \"LVchVCSI.Recv\";
		Conversion(prefix + dpeName, \"IN\", 0.0, 1.0 / 25.0);

		dpeName 	=  \"LVchPINV.Recv\";
		Conversion(prefix + dpeName, \"IN\", 0.0, 50.0 / 1000.0);

		dpeName 	= \"LVchPINI.Recv\";
		Conversion(prefix + dpeName, \"IN\", 0.0, 1.0 / 100.0);

		dpeName 	= \"MOch_Tm0.Recv\";
		Conversion(prefix + dpeName, \"IN\", 0.0, 1.0);

		dpeName 	= \"MOch_Tm1.Recv\";
		Conversion(prefix + dpeName, \"IN\", 0.0, 1.0);

		dpeName 	= \"HVchVolt.Recv\";
		Conversion(prefix + dpeName, \"IN\", 0.0, 1.0 / 8.0);

		dpeName 	= \"HVchCurr.Recv\";
		Conversion(prefix + dpeName, \"IN\", 0.0, 1.0);
		}

	/* LVs cards Conversion *******************************************/
	  for(i=0; i<8; i++)
	  	{
		sprintf( prefix, getSystemName() + Crate + \".LV_card%02d.\", i);

		dpeName		= \"LVcaTemp.Recv\";
		Conversion(prefix + dpeName, \"IN\", 0.0, 1.0);

		dpeName		= \"LVcaPowr.Recv\";
		Conversion(prefix + dpeName, \"IN\", 0.0, 1.0 / 2.5);

		dpeName		= \"LVcaTrip.Send\";
		Conversion(prefix + dpeName, \"OUT\", 0.0, 2.5);
		}
	DebugN(\" Conversion Set for Crate \", Crate);
	}
setValue(\"\",\"foreCol\",\"\");
}


/****************************************************************************\\
|* This function sets conversions for the datapoint element dpeName   		*|
\\****************************************************************************/
 Conversion(string dpeName, string Direction, float Alfa, float Beta)
{
  dyn_errClass err;

  switch(Direction)
	{
	case \"IN\":                            // Monitored value conversion
		dpSetWait(
			dpeName+\":_msg_conv.._type\", 33, //Coversion from raw to physical
			dpeName+\":_msg_conv.1._type\", 2, //Polynomial 4th degree conversion
			dpeName+\":_msg_conv.1._poly_grade\", 1,  //Take only: y = a + b*x
			dpeName+\":_msg_conv.1._poly_a\", Alfa,
			dpeName+\":_msg_conv.1._poly_b\", Beta); break;
	case \"OUT\":                           // Controled value conversion
		dpSetWait(
			dpeName+\":_cmd_conv.._type\", 36, //Coversion from raw to physical
			dpeName+\":_cmd_conv.1._type\", 2, //Polynomial 4th degree conversion
			dpeName+\":_cmd_conv.1._poly_grade\", 1,  //Take only: y = a + b*x
			dpeName+\":_cmd_conv.1._poly_a\", Alfa,
			dpeName+\":_cmd_conv.1._poly_b\", Beta); break;
	default: DebugN(\"Error! Not able to set the direction\", Direction, \"for\", dpeName); return;	
	}//end of switch(...)
	err = getLastError();
	if(dynlen(err) > 0) 
		{
		throwError(err);
		}
}" 0
 E E E
13 35
"Button8"
""
1 710 580 E E E 1 E 1 E N "_3DText" E N {255,128,64} E E
 E E
27 0 0 0 0 0
EE E
0
1
LANG:1 0 
0
1
LANG:1 105 -microsoft windows-Arial-bold-r-normal-*-*-140-100-100-*-*-iso8859-1|-16,0,0,0,700,0,0,0,0,3,2,1,34,Arial
0 ""
328 268 562 332
T 
1
LANG:1 16 Unset Conversion
"//Unset Conversion
/******************************************************************************\\
123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789
|*=====================================-======================================*|
|*			               SCT POWER SUPPLIES MODULES     		              *|
|*=====================================-======================================*|
|*   AUTHORs:        G.Codispoti - codispoti@cs.infn.it			    		  *|
|*								   Giuseppe.Codispoti@cern.ch			      *|
|*																		      *|
|*   DESIGN ISSUEs:  This Script unset DPe conversions.						  *|
|*																		      *|
|*   MODIF_HISTORY:  17.03.2003  - first release						      *|
|*																		      *|
\\******************************************************************************/

main()
{
int i, lengh;
dyn_string Send, Recv, Send2, Recv2;

setValue(\"\",\"foreCol\",\"Red\");

DebugN(getCurrentTime(), \": Start Deleting Configs (Alert, Addresses & Co.)\");

Send = dpNames(\"*.*.*.Send\", \"MPS_Crates\");
Recv = dpNames(\"*.*.*.Recv\", \"MPS_Crates\");
Send2 = dpNames(\"*.*.*.*.Send\", \"MPS_Crates\");
Recv2 = dpNames(\"*.*.*.*.Recv\", \"MPS_Crates\");

if (dynlen(Send) < dynlen(Recv))
		lengh = dynlen(Recv);
else lengh = dynlen(Send);

for(i=1; i<=lengh; i++)
	{
	if(i <= dynlen(Send)) confDel(Send[i]);
	if(i <= dynlen(Recv)) confDel(Recv[i]);
	if(i <= dynlen(Send2)) confDel(Send2[i]);
	if(i <= dynlen(Recv2)) confDel(Recv2[i]);
	}
DebugN(getCurrentTime(), \": Configs Deleted!\");

  setValue(\"\",\"foreCol\",\"\");
}

confDel(string dpeName)
{

dpSetWait(dpeName + \":_msg_conv.._type\", DPCONFIG_NONE);
dpSetWait(dpeName + \":_cmd_conv.._type\", DPCONFIG_NONE);

}" 0
 E E E
13 36
"Button10"
""
1 370 479 E E E 1 E 1 E N "_3DText" E N {255,128,64} E E
 E E
28 0 0 0 0 0
EE E
0
1
LANG:1 0 
0
1
LANG:1 105 -microsoft windows-Arial-bold-r-normal-*-*-140-100-100-*-*-iso8859-1|-16,0,0,0,700,0,0,0,0,3,2,1,34,Arial
0 ""
328 337 562 401
T 
1
LANG:1 14 Delete Configs
"//Delete Configs
/******************************************************************************\\
123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789
|*=====================================-======================================*|
|*			               SCT POWER SUPPLIES MODULES     		              *|
|*=====================================-======================================*|
|*   AUTHORs:        G.Codispoti - codispoti@cs.infn.it			    		  *|
|*								   Giuseppe.Codispoti@cern.ch			      *|
|*																		      *|
|*   DESIGN ISSUEs:  This Script delete all existing configs				  *|
|*					 in the DPs of MPS_Crates DPT.							  *|
|*																		      *|
|*   MODIF_HISTORY:  17.03.2003  - first release						      *|
|*																		      *|
\\******************************************************************************/

main()
{
int i, lengh;
dyn_string Send, Recv, Send2, Recv2;

setValue(\"\",\"foreCol\",\"Red\");

DebugN(getCurrentTime(), \": Start Deleting Configs (Alert, Addresses & Co.)\");

Send = dpNames(\"*.*.*.Send\", \"MPS_Crates\");
Recv = dpNames(\"*.*.*.Recv\", \"MPS_Crates\");
Send2 = dpNames(\"*.*.*.*.Send\", \"MPS_Crates\");
Recv2 = dpNames(\"*.*.*.*.Recv\", \"MPS_Crates\");

if (dynlen(Send) < dynlen(Recv))
		lengh = dynlen(Recv);
else lengh = dynlen(Send);

for(i=1; i<=lengh; i++)
	{
	if(i <= dynlen(Send)) confDel(Send[i]);
	if(i <= dynlen(Recv)) confDel(Recv[i]);
	if(i <= dynlen(Send2)) confDel(Send2[i]);
	if(i <= dynlen(Recv2)) confDel(Recv2[i]);
	}
DebugN(getCurrentTime(), \": Configs Deleted!\");

  setValue(\"\",\"foreCol\",\"\");
}

confDel(string dpeName)
{
int direction, intDpeType, rc, type;
dyn_errClass err;
bool ok;

//DebugN(dpeName);

dpSetWait(dpeName + \":_address.._type\", DPCONFIG_NONE);
dpSetWait(dpeName + \":_msg_conv.._type\", DPCONFIG_NONE);
dpSetWait(dpeName + \":_cmd_conv.._type\", DPCONFIG_NONE);

// check if the alarm already exists
rc = dpGet (dpeName+\":_alert_hdl.._type\", type);
err = getLastError ();	
if (rc | dynlen(err))
	{
	DebugN(\"Failed to check whether alarm already exists for dpe: \"+dpeName+\" : \"+rc);
	throwError (err);
	return;
	}

// if it exists, deactivate the alarm handling (so we can change it)
if (type != DPCONFIG_NONE)
	{
	dpDeactivateAlert (dpeName, ok);		
	if ( ! ok)
		{
		DebugN(\"Failed to deactivate alarm on dpe: \"+dpeName);
		return;
		}
	dpSetWait(dpeName+\":_alert_hdl.._ack\", DPATTR_ACKTYPE_MULTIPLE);
	dpSetWait(dpeName+\":_alert_hdl.._type\", DPCONFIG_NONE);
	}
}" 0
 E E E
0
LAYER, 1 
1
LANG:1 6 Layer2
0
LAYER, 2 
1
LANG:1 6 Layer3
0
LAYER, 3 
1
LANG:1 6 Layer4
0
LAYER, 4 
1
LANG:1 6 Layer5
0
LAYER, 5 
1
LANG:1 6 Layer6
0
LAYER, 6 
1
LANG:1 6 Layer7
0
LAYER, 7 
1
LANG:1 6 Layer8
0
0