V 10
1
LANG:1 8 (NoName)
PANEL,485 344 570 309 N "_3DFace" 0
EEE E E 1 -1 -1 0  130 100
"" 0 1
EE 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
13 0
"Button5"
""
1 20 20 E E E 1 E 1 E N "_3DText" E N {102,204,255} E E
 E E
1 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 ""
18 18 292 82
T 
1
LANG:1 20 Create Addr and Conv
"//Function CreateAddress()
/*
1234567890123456789012345678901234567890123456789012345678901234567890123456
																			
*/
main()
{
string 	raw, path, prefix, opcprefix, Bus, Crate, Chan, Card,
		 dpeName, dpeType, OPCItemName, DpeType, OPCgroup;
int num, i, crat, err, UnitMax;
file syst, opc;


setValue(\"\",\"foreCol\",\"Red\");
DebugN(getCurrentTime());  
	getSyst(UnitMax);
	if (!UnitMax) return;
	DebugN(UnitMax);
	
  /* open new file for OPC configuration */
	path = getPath(PANELS_REL_PATH, \"OPCCanServer.cfg\");
	opc = fopen(path,\"w\");
	err=ferror(opc); // export error
	if (err!=0)
		{ 
		DebugN(\"Error no. \",err,\" occurred: not able to create \\\"OPCCanServer.cfg\\\" file\");
		return;
		}
		
for ( crat = 2; crat < 3; crat++ )
	{
	sprintf( Crate, \"Crate%02d\", crat);
	sprintf( Bus, \"Bus%02d\", 0 );
	opcprefix = Bus + \".\" + Crate+ \".\" + Crate;
	//It's like \"Bus00.Crate00.Crate00\" needed as a prefix for the OPCItemName
	
	//Write file's header:
	fputs(\"[CANBUS]\\n\" + Bus + \" = dumcanserver 125000\\n\\n[DEVICE]\\n\"
						 + Crate + \" = \" + Bus + \" 1 NG\\n\\n[SDOItem]\\n\", opc);

	/* Channels addresses *******************************************/
		for(i=0; i<48; i++)
		{
		sprintf( Chan, \"%d\", i);	//needed for a correct OPCItemName!
		sprintf( prefix, getSystemName() + Crate + \".Channel%02d.\", i );
		//It's like: \"SCTmops1:Crate00.Channel00.\"
	
		DebugN(\" Setting Addresses for Crate \", Crate, \", Channel \", i);

		dpeName		= \"LVchStat.Recv\";
		OPCItemName = \"_LVchStat_RecvChan\";
		dpeType		= \"DEFAULT\";
		OPCgroup	= \"Moni\";
		num 		= 0;
		if (dpExists (prefix + dpeName))
			{
			OPCAddress (prefix + dpeName, OPCgroup, opcprefix + OPCItemName + Chan, dpeType);
			writeSDOcfg ( opc, OPCItemName, Crate, num, dpeType);
			}
		else DebugN(\"Error! Datapoint\", prefix + dpeName, \"doesn't exist!\");
		
		dpeName		= \"LVch_Vcc.Send\";
		OPCItemName = \"_LVch_Vcc_SendChan\";
		dpeType		= \"DEFAULT\";
		OPCgroup	= \"Comm\";
		num			= 0;
		if (dpExists (prefix + dpeName))
			{
			OPCAddress (prefix + dpeName, OPCgroup, opcprefix + OPCItemName + Chan, dpeType);
			writeSDOcfg ( opc, OPCItemName, Crate, num, dpeType);
			Conversion(prefix + dpeName, \"OUT\", 0.0, 1000.0 / 20.0);
			}
		else DebugN(\"Error! Datapoint\", prefix + dpeName, \"doesn't exist!\");
				
		dpeName 	= \"LVch_Vcc.Recv\";
		OPCItemName = \"_LVch_Vcc_RecvChan\";
		dpeType		= \"DEFAULT\";
		OPCgroup	= \"Moni\";
		num			= 0;
		if (dpExists (prefix + dpeName))
			{
			OPCAddress (prefix + dpeName, OPCgroup, opcprefix + OPCItemName + Chan, dpeType);
			writeSDOcfg ( opc, OPCItemName, Crate, num, dpeType);
			Conversion(prefix + dpeName, \"IN\", 0.0, 20.0 / 1000.0);
			}
		else DebugN(\"Error! Datapoint\", prefix + dpeName, \"doesn't exist!\");			
	
		dpeName 	= \"LVps_Vcc.Recv\";
		OPCItemName = \"_LVps_Vcc_RecvChan\";
		dpeType		= \"DEFAULT\";
		OPCgroup	= \"Moni\";
		num			= 0;
		if (dpExists (prefix + dpeName))
			{
			OPCAddress (prefix + dpeName, OPCgroup, opcprefix + OPCItemName + Chan, dpeType);
			writeSDOcfg ( opc, OPCItemName, Crate, num, dpeType);
			Conversion(prefix + dpeName, \"IN\", 0.0, 50.0 / 1000.0);
			}
		else DebugN(\"Error! Datapoint\", prefix + dpeName, \"doesn't exist!\");

		dpeName 	= \"LVretVcc.Recv\";
		OPCItemName = \"_LVretVcc_RecvChan\";
		dpeType		= \"DEFAULT\";
		OPCgroup	= \"Moni\";
		num			= 0;
		if (dpExists (prefix + dpeName))
			{
		OPCAddress (prefix + dpeName, OPCgroup, opcprefix + OPCItemName + Chan, dpeType);
		writeSDOcfg ( opc, OPCItemName, Crate, num, dpeType);	
		Conversion(prefix + dpeName, \"IN\", 0.0, 20.0 / 1000.0);
			}
		else DebugN(\"Error! Datapoint\", prefix + dpeName, \"doesn't exist!\");

		dpeName 	= \"LVch_Icc.Recv\";
		OPCItemName =\"_LVch_Icc_RecvChan\";
		dpeType		= \"DEFAULT\";
		OPCgroup	= \"Moni\";
		num			= 0;
		if (dpExists (prefix + dpeName))
			{
		OPCAddress (prefix + dpeName, OPCgroup, opcprefix + OPCItemName + Chan, dpeType);
		writeSDOcfg ( opc, OPCItemName, Crate, num, dpeType);
		Conversion(prefix + dpeName, \"IN\", 0.0, 10.0);
			}
		else DebugN(\"Error! Datapoint\", prefix + dpeName, \"doesn't exist!\");

		dpeName 	= \"LVch_Vdd.Send\";
		OPCItemName = \"_LVch_Vdd_SendChan\";
		dpeType		= \"DEFAULT\";
		OPCgroup	= \"Comm\";
		num			= 0;
		if (dpExists (prefix + dpeName))
			{
		OPCAddress (prefix + dpeName, OPCgroup, opcprefix + OPCItemName + Chan, dpeType);
		writeSDOcfg ( opc, OPCItemName, Crate, num, dpeType);			
		Conversion(prefix + dpeName, \"OUT\", 0.0, 1000.0 / 20.0);
			}
		else DebugN(\"Error! Datapoint\", prefix + dpeName, \"doesn't exist!\");

		dpeName		= \"LVch_Vdd.Recv\";
		OPCItemName = \"_LVch_Vdd_RecvChan\";
		dpeType		= \"DEFAULT\";
		OPCgroup	= \"Moni\";
		num			= 0;
		if (dpExists (prefix + dpeName))
			{
		OPCAddress (prefix + dpeName, OPCgroup, opcprefix + OPCItemName + Chan, dpeType);
		writeSDOcfg ( opc, OPCItemName, Crate, num, dpeType);
		Conversion(prefix + dpeName, \"IN\", 0.0, 20.0 / 1000.0);
			}
		else DebugN(\"Error! Datapoint\", prefix + dpeName, \"doesn't exist!\");

		dpeName		= \"LVps_Vdd.Recv\";
		OPCItemName = \"_LVps_Vdd_RecvChan\";
		dpeType		= \"DEFAULT\";
		OPCgroup	= \"Moni\";
		num			= 0;
		if (dpExists (prefix + dpeName))
			{
		OPCAddress (prefix + dpeName, OPCgroup, opcprefix + OPCItemName + Chan, dpeType);
		writeSDOcfg ( opc, OPCItemName, Crate, num, dpeType);
		Conversion(prefix + dpeName, \"IN\", 0.0, 50.0 / 1000.0);
			}
		else DebugN(\"Error! Datapoint\", prefix + dpeName, \"doesn't exist!\");

		dpeName 	= \"LVretVdd.Recv\";
		OPCItemName = \"_LVretVdd_RecvChan\";
		dpeType		= \"DEFAULT\";
		OPCgroup	= \"Moni\";
		num			= 0;
		if (dpExists (prefix + dpeName))
			{
		OPCAddress (prefix + dpeName, OPCgroup, opcprefix + OPCItemName + Chan, dpeType);
		writeSDOcfg ( opc, OPCItemName, Crate, num, dpeType);
		Conversion(prefix + dpeName, \"IN\", 0.0, 20.0 / 1000.0);
			}
		else DebugN(\"Error! Datapoint\", prefix + dpeName, \"doesn't exist!\");

		dpeName 	= \"LVch_Idd.Recv\";
		OPCItemName = \"_LVch_Idd_RecvChan\";
		dpeType		= \"DEFAULT\";
		OPCgroup	= \"Moni\";
		num			= 0;
		if (dpExists (prefix + dpeName))
			{
		OPCAddress (prefix + dpeName, OPCgroup, opcprefix + OPCItemName + Chan, dpeType);
		writeSDOcfg ( opc, OPCItemName, Crate, num, dpeType);
		Conversion(prefix + dpeName, \"IN\", 0.0, 10.0);
			}
		else DebugN(\"Error! Datapoint\", prefix + dpeName, \"doesn't exist!\");

		dpeName 	= \"LVchVCSV.Send\";
		OPCItemName = \"_LVchVCSV_SendChan\";
		dpeType		= \"DEFAULT\";
		OPCgroup	= \"Comm\";
		num			= 0;
		if (dpExists (prefix + dpeName))
			{
		OPCAddress (prefix + dpeName, OPCgroup, opcprefix + OPCItemName + Chan, dpeType);
		writeSDOcfg ( opc, OPCItemName, Crate, num, dpeType);
		Conversion(prefix + dpeName, \"OUT\", 0.0, 1000.0 / 40.0);
			}
		else DebugN(\"Error! Datapoint\", prefix + dpeName, \"doesn't exist!\");

		dpeName 	= \"LVchVCSV.Recv\";
		OPCItemName = \"_LVchVCSV_RecvChan\";
		dpeType		= \"DEFAULT\";
		OPCgroup	= \"Moni\";
		num			= 0;
		if (dpExists (prefix + dpeName))
			{
		OPCAddress (prefix + dpeName, OPCgroup, opcprefix + OPCItemName + Chan, dpeType);
		writeSDOcfg ( opc, OPCItemName, Crate, num, dpeType);
		Conversion(prefix + dpeName, \"IN\", 0.0, 40.0 / 1000.0);
			}
		else DebugN(\"Error! Datapoint\", prefix + dpeName, \"doesn't exist!\");

		dpeName 	= \"LVchVCSI.Recv\";
		OPCItemName = \"_LVchVCSI_RecvChan\";
		dpeType		= \"DEFAULT\";
		OPCgroup	= \"Moni\";
		num			= 0;
		if (dpExists (prefix + dpeName))
			{
		OPCAddress (prefix + dpeName, OPCgroup, opcprefix + OPCItemName + Chan, dpeType);
		writeSDOcfg ( opc, OPCItemName, Crate, num, dpeType);
		Conversion(prefix + dpeName, \"IN\", 0.0, 1.0 / 25.0);
			}
		else DebugN(\"Error! Datapoint\", prefix + dpeName, \"doesn't exist!\");

		dpeName 	= \"LVchPINV.Send\";
		OPCItemName = \"_LVchPINV_SendChan\";
		dpeType		= \"DEFAULT\";
		OPCgroup	= \"Comm\";
		num			= 0;
		if (dpExists (prefix + dpeName))
			{
		OPCAddress (prefix + dpeName, OPCgroup, opcprefix + OPCItemName + Chan, dpeType);
		writeSDOcfg ( opc, OPCItemName, Crate, num, dpeType);
		Conversion(prefix + dpeName, \"OUT\", 0.0, 1000.0 / 50.0);
			}
		else DebugN(\"Error! Datapoint\", prefix + dpeName, \"doesn't exist!\");

		dpeName 	=  \"LVchPINV.Recv\";
		OPCItemName = \"_LVchPINV_RecvChan\";
		dpeType		= \"DEFAULT\";
		OPCgroup	= \"Moni\";
		num			= 0;
		if (dpExists (prefix + dpeName))
			{
		OPCAddress (prefix + dpeName, OPCgroup, opcprefix + OPCItemName + Chan, dpeType);
		writeSDOcfg ( opc, OPCItemName, Crate, num, dpeType);
		Conversion(prefix + dpeName, \"IN\", 0.0, 50.0 / 1000.0);
			}
		else DebugN(\"Error! Datapoint\", prefix + dpeName, \"doesn't exist!\");

		dpeName 	= \"LVchPINI.Recv\";
		OPCItemName = \"_LVchPINI_RecvChan\";
		dpeType		= \"DEFAULT\";
		OPCgroup	= \"Moni\";
		num			= 0;
		if (dpExists (prefix + dpeName))
			{
		OPCAddress (prefix + dpeName, OPCgroup, opcprefix + OPCItemName + Chan, dpeType);
		writeSDOcfg ( opc, OPCItemName, Crate, num, dpeType);
		Conversion(prefix + dpeName, \"IN\", 0.0, 1.0 / 100.0);
			}
		else DebugN(\"Error! Datapoint\", prefix + dpeName, \"doesn't exist!\");

		dpeName 	= \"MOch_Tm0.Recv\";
		OPCItemName = \"_MOch_Tm0_RecvChan\";
		dpeType		= \"UINT16\";
		OPCgroup	= \"Moni\";
		num			= 0;
		if (dpExists (prefix + dpeName))
			{
		OPCAddress (prefix + dpeName, OPCgroup, opcprefix + OPCItemName + Chan, dpeType);
		writeSDOcfg ( opc, OPCItemName, Crate, num, dpeType);
		Conversion(prefix + dpeName, \"IN\", 0.0, 1.0);
			}
		else DebugN(\"Error! Datapoint\", prefix + dpeName, \"doesn't exist!\");

		dpeName 	= \"MOch_Tm1.Recv\";
		OPCItemName = \"_MOch_Tm1_RecvChan\";
		dpeType		= \"UINT16\";
		OPCgroup	= \"Moni\";
		num			= 0;
		if (dpExists (prefix + dpeName))
			{
		OPCAddress (prefix + dpeName, OPCgroup, opcprefix + OPCItemName + Chan, dpeType);
		writeSDOcfg ( opc, OPCItemName, Crate, num, dpeType);
		Conversion(prefix + dpeName, \"IN\", 0.0, 1.0);
			}
		else DebugN(\"Error! Datapoint\", prefix + dpeName, \"doesn't exist!\");

		dpeName		= \"LVchDTrp.Send\";
		OPCItemName = \"_LVchDTrp_SendChan\";
		dpeType		= \"DEFAULT\";
		OPCgroup	= \"Comm\";
		num			= 0;
		if (dpExists (prefix + dpeName))
			{
		OPCAddress (prefix + dpeName, OPCgroup, opcprefix + OPCItemName + Chan, dpeType);
		writeSDOcfg ( opc, OPCItemName, Crate, num, dpeType);
		Conversion(prefix + dpeName, \"OUT\", 0.0, 1.0 / 2.0);
			}
		else DebugN(\"Error! Datapoint\", prefix + dpeName, \"doesn't exist!\");

		dpeName 	= \"LVchCTrp.Send\";
		OPCItemName = \"_LVchCTrp_SendChan\";
		dpeType		= \"DEFAULT\";
		OPCgroup	= \"Comm\";
		num			= 0;
		if (dpExists (prefix + dpeName))
			{
		OPCAddress (prefix + dpeName, OPCgroup, opcprefix + OPCItemName + Chan, dpeType);
		writeSDOcfg ( opc, OPCItemName, Crate, num, dpeType);
		Conversion(prefix + dpeName, \"OUT\", 0.0, 1.0 / 2.0);
			}
		else DebugN(\"Error! Datapoint\", prefix + dpeName, \"doesn't exist!\");

		dpeName 	= \"LVchTLim.Send\";
		OPCItemName = \"_LVchTLim_SendChan\";
		dpeType		= \"DEFAULT\";
		OPCgroup	= \"Comm\";
		num			= 0;
		if (dpExists (prefix + dpeName))
			{
		OPCAddress (prefix + dpeName, OPCgroup, opcprefix + OPCItemName + Chan, dpeType);
		writeSDOcfg ( opc, OPCItemName, Crate, num, dpeType);
		Conversion(prefix + dpeName, \"OUT\", 128.0, 1.0);
			}
		else DebugN(\"Error! Datapoint\", prefix + dpeName, \"doesn't exist!\");

		dpeName 	= \"LVchTTrp.Send\";
		OPCItemName = \"_LVchTTrp_SendChan\";
		dpeType		= \"DEFAULT\";
		OPCgroup	= \"Comm\";
		num			= 0;
		if (dpExists (prefix + dpeName))
			{
		OPCAddress (prefix + dpeName, OPCgroup, opcprefix + OPCItemName + Chan, dpeType);
		writeSDOcfg ( opc, OPCItemName, Crate, num, dpeType);
		Conversion(prefix + dpeName, \"OUT\", 128.0, 1.0);
			}
		else DebugN(\"Error! Datapoint\", prefix + dpeName, \"doesn't exist!\");

		dpeName 	= \"LVchCLKS.Send\";
		OPCItemName = \"_LVchCLKS_SendChan\";
		dpeType		= \"DEFAULT\";
		OPCgroup	= \"Comm\";
		num			= 0;
		if (dpExists (prefix + dpeName))
			{
		OPCAddress (prefix + dpeName, OPCgroup, opcprefix + OPCItemName + Chan, dpeType);
		writeSDOcfg ( opc, OPCItemName, Crate, num, dpeType);
			}
		else DebugN(\"Error! Datapoint\", prefix + dpeName, \"doesn't exist!\");

		dpeName  	= \"LVchCLKR.Send\";
		OPCItemName = \"_LVchCLKR_SendChan\";
		dpeType		= \"DEFAULT\";
		OPCgroup	= \"Comm\";
		num			= 0;
		if (dpExists (prefix + dpeName))
			{
		OPCAddress (prefix + dpeName, OPCgroup, opcprefix + OPCItemName + Chan, dpeType);
		writeSDOcfg ( opc, OPCItemName, Crate, num, dpeType);
			}
		else DebugN(\"Error! Datapoint\", prefix + dpeName, \"doesn't exist!\");

		dpeName 	= \"LVchVOut.Send\";
		OPCItemName = \"_LVchVOut_SendChan\";
		dpeType		= \"DEFAULT\";
		OPCgroup	= \"Comm\";
		num			= 0;
		if (dpExists (prefix + dpeName))
			{
		OPCAddress (prefix + dpeName, OPCgroup, opcprefix + OPCItemName + Chan, dpeType);
		writeSDOcfg ( opc, OPCItemName, Crate, num, dpeType);
			}
		else DebugN(\"Error! Datapoint\", prefix + dpeName, \"doesn't exist!\");

		dpeName 	= \"HVchStat.Recv\";
		OPCItemName = \"_HVchStat_RecvChan\";
		dpeType		= \"DEFAULT\";
		OPCgroup	= \"Moni\";
		num			= 0;
		if (dpExists (prefix + dpeName))
			{
		OPCAddress (prefix + dpeName, OPCgroup, opcprefix + OPCItemName + Chan, dpeType);
		writeSDOcfg ( opc, OPCItemName, Crate, num, dpeType);
			}
		else DebugN(\"Error! Datapoint\", prefix + dpeName, \"doesn't exist!\");

		dpeName 	= \"HVchVolt.Send\";
		OPCItemName = \"_HVchVolt_SendChan\";
		dpeType		= \"UINT16\";
		OPCgroup	= \"Comm\";
		num			= 0;
		if (dpExists (prefix + dpeName))
			{
		OPCAddress (prefix + dpeName, OPCgroup, opcprefix + OPCItemName + Chan, dpeType);
		writeSDOcfg ( opc, OPCItemName, Crate, num, dpeType);
			}
		else DebugN(\"Error! Datapoint\", prefix + dpeName, \"doesn't exist!\");
	

		dpeName 	= \"HVchVolt.Recv\";
		OPCItemName = \"_HVchVolt_RecvChan\";
		dpeType		= \"UINT16\";
		OPCgroup	= \"Moni\";
		num			= 0;
		if (dpExists (prefix + dpeName))
			{
		OPCAddress (prefix + dpeName, OPCgroup, opcprefix + OPCItemName + Chan, dpeType);
		writeSDOcfg ( opc, OPCItemName, Crate, num, dpeType);
		Conversion(prefix + dpeName, \"IN\", 0.0, 1.0 / 8.0);
			}
		else DebugN(\"Error! Datapoint\", prefix + dpeName, \"doesn't exist!\");

		dpeName 	= \"HVchCurr.Recv\";
		OPCItemName = \"_HVchCurr_RecvChan\";
		dpeType		= \"UINT16\";
		OPCgroup	= \"Moni\";
		num			= 0;
		if (dpExists (prefix + dpeName))
			{
		OPCAddress (prefix + dpeName, OPCgroup, opcprefix + OPCItemName + Chan, dpeType);
		writeSDOcfg ( opc, OPCItemName, Crate, num, dpeType);
		Conversion(prefix + dpeName, \"IN\", 0.0, 1.0);
			}
		else DebugN(\"Error! Datapoint\", prefix + dpeName, \"doesn't exist!\");

		dpeName 	= \"HVchITrp.Send\";
		OPCItemName = \"_HVchITrp_SendChan\";
		dpeType		= \"UINT16\";
		OPCgroup	= \"Comm\";
		num			= 0;
		if (dpExists (prefix + dpeName))
			{
		OPCAddress (prefix + dpeName, OPCgroup, opcprefix + OPCItemName + Chan, dpeType);
		writeSDOcfg ( opc, OPCItemName, Crate, num, dpeType);
		Conversion(prefix + dpeName, \"OUT\", 0.0, 1.0);
			}
		else DebugN(\"Error! Datapoint\", prefix + dpeName, \"doesn't exist!\");

		dpeName 	= \"HVchRamp.Send\";
		OPCItemName = \"_HVchRamp_SendChan\";
		dpeType		= \"DEFAULT\";
		OPCgroup	= \"Comm\";
		num			= 0;
		if (dpExists (prefix + dpeName))
			{
		OPCAddress (prefix + dpeName, OPCgroup, opcprefix + OPCItemName + Chan, dpeType);
		writeSDOcfg ( opc, OPCItemName, Crate, num, dpeType);
		Conversion(prefix + dpeName, \"OUT\", 0.0, 1.0);
			}
		else DebugN(\"Error! Datapoint\", prefix + dpeName, \"doesn't exist!\");


		// IV Curve
		dpeName 	= \"IVCurve.HV_Start.Send\";
		OPCItemName = \"_IVchStrt_SendChan\";
		dpeType		= \"UINT16\";
		OPCgroup	= \"Comm\";
		num			= 0;
		if (dpExists (prefix + dpeName))
			{
		OPCAddress (prefix + dpeName, OPCgroup, opcprefix + OPCItemName + Chan, dpeType);
		writeSDOcfg ( opc, OPCItemName, Crate, num, dpeType);
			}
		else DebugN(\"Error! Datapoint\", prefix + dpeName, \"doesn't exist!\");

		dpeName 	= \"IVCurve.HV_Step.Send\";
		OPCItemName = \"_IVchStep_SendChan\";
		dpeType		= \"DEFAULT\";
		OPCgroup	= \"Comm\";
		num			= 0;
		if (dpExists (prefix + dpeName))
			{
		OPCAddress (prefix + dpeName, OPCgroup, opcprefix + OPCItemName + Chan, dpeType);
		writeSDOcfg ( opc, OPCItemName, Crate, num, dpeType);
			}
		else DebugN(\"Error! Datapoint\", prefix + dpeName, \"doesn't exist!\");

		dpeName 	= \"IVCurve.HV_Stop.Send\";
		OPCItemName = \"_IVchStop_SendChan\";
		dpeType		= \"UINT16\";
		OPCgroup	= \"Comm\";
		num			= 0;
		if (dpExists (prefix + dpeName))
			{
		OPCAddress (prefix + dpeName, OPCgroup, opcprefix + OPCItemName + Chan, dpeType);
		writeSDOcfg ( opc, OPCItemName, Crate, num, dpeType);
			}
		else DebugN(\"Error! Datapoint\", prefix + dpeName, \"doesn't exist!\");

		dpeName 	= \"IVCurve.HV_End.Send\";
		OPCItemName = \"_IVchVend_SendChan\";
		dpeType		= \"UINT16\";
		OPCgroup	= \"Comm\";
		num			= 0;
		if (dpExists (prefix + dpeName))
			{
		OPCAddress (prefix + dpeName, OPCgroup, opcprefix + OPCItemName + Chan, dpeType);
		writeSDOcfg ( opc, OPCItemName, Crate, num, dpeType);
			}
		else DebugN(\"Error! Datapoint\", prefix + dpeName, \"doesn't exist!\");

		dpeName 	= \"IVCurve.Curr_Max.Send\";
		OPCItemName = \"_IVchImax_SendChan\";
		dpeType		= \"UINT16\";
		OPCgroup	= \"Comm\";
		num			= 0;
		if (dpExists (prefix + dpeName))
			{
		OPCAddress (prefix + dpeName, OPCgroup, opcprefix + OPCItemName + Chan, dpeType);
		writeSDOcfg ( opc, OPCItemName, Crate, num, dpeType);
			}
		else DebugN(\"Error! Datapoint\", prefix + dpeName, \"doesn't exist!\");

		dpeName 	= \"IVCurve.Curr_Warn.Send\";
		OPCItemName = \"_IVchIwar_SendChan\";
		dpeType		= \"UINT16\";
		OPCgroup	= \"Comm\";
		num			= 0;
		if (dpExists (prefix + dpeName))
			{
		OPCAddress (prefix + dpeName, OPCgroup, opcprefix + OPCItemName + Chan, dpeType);
		writeSDOcfg ( opc, OPCItemName, Crate, num, dpeType);
			}
		else DebugN(\"Error! Datapoint\", prefix + dpeName, \"doesn't exist!\");


		dpeName 	= \"IVCurve.Status.Recv\";
		OPCItemName = \"_IVchStat_RecvChan\";
		dpeType		= \"DEFAULT\";
		OPCgroup	= \"Moni\";
		num			= 0;
		if (dpExists (prefix + dpeName))
			{
		OPCAddress (prefix + dpeName, OPCgroup, opcprefix + OPCItemName + Chan, dpeType);
		writeSDOcfg ( opc, OPCItemName, Crate, num, dpeType);
			}
		else DebugN(\"Error! Datapoint\", prefix + dpeName, \"doesn't exist!\");

		dpeName 	= \"IVCurve.TimeWait.Send\";
		OPCItemName = \"_IVchWait_SendChan\";
		dpeType		= \"DEFAULT\";
		OPCgroup	= \"Comm\";
		num			= 0;
		if (dpExists (prefix + dpeName))
			{
		OPCAddress (prefix + dpeName, OPCgroup, opcprefix + OPCItemName + Chan, dpeType);
		writeSDOcfg ( opc, OPCItemName, Crate, num, dpeType);
			}
		else DebugN(\"Error! Datapoint\", prefix + dpeName, \"doesn't exist!\");
	
		}

	/* LVs cards addresses *******************************************/
	  for(i=0; i<8; i++)
	  	{
		sprintf( Card, \"%d\", i ); //needed for a correct OPCItemName!
		sprintf( prefix, getSystemName() + Crate + \".LV_card%02d.\", i);
		//It's like: \"SCTmops1:Crate00.LV_card00.\"
		
		DebugN(\" Setting Addresses for crate \", Crate, \", LV card N  = \", i);

		dpeName		= \"LVcaMask.Send\";
		OPCItemName = \"_LVcaMask_SendCard\";
		dpeType		= \"DEFAULT\";
		OPCgroup	= \"Comm\";
		num 		= 0;
		if (dpExists (prefix + dpeName))
			{
			OPCAddress (prefix + dpeName, OPCgroup, opcprefix + OPCItemName + Card, dpeType);
			}
		else DebugN(\"Error! Datapoint\", prefix + dpeName, \"doesn't exist!\");

		dpeName		= \"LVcaMask.Recv\";
		OPCItemName = \"_LVcaMask_RecvCard\";
		dpeType		= \"DEFAULT\";
		OPCgroup	= \"Moni\";
		num 		= 0;
		if (dpExists (prefix + dpeName))
			{
			OPCAddress (prefix + dpeName, OPCgroup, opcprefix + OPCItemName + Card, dpeType);
			}
		else DebugN(\"Error! Datapoint\", prefix + dpeName, \"doesn't exist!\");

		dpeName		= \"LVcaStat.Recv\";
		OPCItemName = \"_LVcaStat_RecvCard\";
		dpeType		= \"DEFAULT\";
		OPCgroup	= \"Moni\";
		num 		= 0;
		if (dpExists (prefix + dpeName))
			{
			OPCAddress (prefix + dpeName, OPCgroup, opcprefix + OPCItemName + Card, dpeType);
			}
		else DebugN(\"Error! Datapoint\", prefix + dpeName, \"doesn't exist!\");	

		dpeName		= \"LVcaTemp.Recv\";
		OPCItemName = \"_LVcaTemp_RecvCard\";
		dpeType		= \"DEFAULT\";
		OPCgroup	= \"Moni\";
		num 		= 0;
		if (dpExists (prefix + dpeName))
			{
			OPCAddress (prefix + dpeName, OPCgroup, opcprefix + OPCItemName + Card, dpeType);	
			Conversion(prefix + dpeName, \"IN\", 0.0, 1.0);
			}
		else DebugN(\"Error! Datapoint\", prefix + dpeName, \"doesn't exist!\");

		dpeName		= \"LVcaPowr.Recv\";
		OPCItemName = \"_LVcaPowr_RecvCard\";
		dpeType		= \"DEFAULT\";
		OPCgroup	= \"Moni\";
		num 		= 0;
		if (dpExists (prefix + dpeName))
			{
			OPCAddress (prefix + dpeName, OPCgroup, opcprefix + OPCItemName + Card, dpeType);	
			Conversion(prefix + dpeName, \"IN\", 0.0, 1.0 / 2.5);
			}
		else DebugN(\"Error! Datapoint\", prefix + dpeName, \"doesn't exist!\");

		dpeName		= \"LVcaTrip.Send\";
		OPCItemName = \"_LVcaTrip_SendCard\";
		dpeType		= \"DEFAULT\";
		OPCgroup	= \"Comm\";
		num 		= 0;
		if (dpExists (prefix + dpeName))
			{
			OPCAddress (prefix + dpeName, OPCgroup, opcprefix + OPCItemName + Card, dpeType);		
			Conversion(prefix + dpeName, \"OUT\", 0.0, 2.5);
			}
		else DebugN(\"Error! Datapoint\", prefix + dpeName, \"doesn't exist!\");
		}
		
	/* HVs cards addresses *******************************************/
	  for(i=0; i<4; i++)
		{
		sprintf( Card, \"%d\", i ); //needed for a correct OPCItemName!
		sprintf(prefix, getSystemName() + Crate + \".HV_card%02d.\",  i);
		//It's like: \"SCTmops1:Crate00.HV_card00.\"
			
		DebugN(\" Setting Addresses for Crate \", Crate, \", HV card N  = \", i);

		dpeName		= \"HVcaStat.Recv\";
		OPCItemName = \"_HVcaStat_RecvCard\";
		dpeType		= \"DEFAULT\";
		OPCgroup	= \"Moni\";
		num 		= 0;
		if (dpExists (prefix + dpeName))
			{
			OPCAddress (prefix + dpeName, OPCgroup, opcprefix + OPCItemName + Card, dpeType);
			}
		else DebugN(\"Error! Datapoint\", prefix + dpeName, \"doesn't exist!\");

		dpeName		= \"HVcaMask.Send\";
		OPCItemName = \"_HVcaMask_SendCard\";
		dpeType		= \"DEFAULT\";
		OPCgroup	= \"Comm\";
		num 		= 0;
		if (dpExists (prefix + dpeName))
			{
			OPCAddress (prefix + dpeName, OPCgroup, opcprefix + OPCItemName + Card, dpeType);
			}
		else DebugN(\"Error! Datapoint\", prefix + dpeName, \"doesn't exist!\");	
		}
	
	/* Crate Controller addresses *******************************************/
	
	//	dpeName = prefix + \"CC_Reset.Send\";
	//	OPCItemName = ;
	//	OPCAddress(dpeName, \"\", OPCItemName, \"DEFAULT\");
	
		DebugN(\" Setting Addresses for Crate Controller of Crate \", Crate);
		prefix = getSystemName() + Crate + \".Controller.\";

		dpeName		= \"CCch_Set.Send\";
		OPCItemName = \"_Set\";
		dpeType		= \"DEFAULT\";
		OPCgroup	= \"Comm\";
		num 		= 0;
		if (dpExists (prefix + dpeName))
			{
			OPCAddress (prefix + dpeName, OPCgroup, opcprefix + OPCItemName, dpeType);
			}
		else DebugN(\"Error! Datapoint\", prefix + dpeName, \"doesn't exist!\");			

		dpeName		= \"CCchRead.Send\";
		OPCItemName = \"_Read\";
		dpeType		= \"DEFAULT\";
		OPCgroup	= \"Comm\";
		num 		= 0;
		if (dpExists (prefix + dpeName))
			{
			OPCAddress (prefix + dpeName, OPCgroup, opcprefix + OPCItemName, dpeType);
			}
		else DebugN(\"Error! Datapoint\", prefix + dpeName, \"doesn't exist!\");		

		dpeName		= \"StartIVCurve.Send\";
		OPCItemName = \"_IVcurve\";
		dpeType		= \"DEFAULT\";
		OPCgroup	= \"Comm\";
		num 		= 0;
		if (dpExists (prefix + dpeName))
			{
			OPCAddress (prefix + dpeName, OPCgroup, opcprefix + OPCItemName, dpeType);
			}
		else DebugN(\"Error! Datapoint\", prefix + dpeName, \"doesn't exist!\");	

		dpeName		= \"NMT.Recv\";
		OPCItemName = \"NMT\";
		dpeType		= \"DEFAULT\";
		OPCgroup	= \"Moni\";
		num 		= 0;
		if (dpExists (prefix + dpeName))
			{
			OPCAddress (prefix + dpeName, OPCgroup, Bus + \".\" + OPCItemName, dpeType);
			}
		else DebugN(\"Error! Datapoint\", prefix + dpeName, \"doesn't exist!\");	

		dpeName		= \"NMT.Send\";
		OPCItemName = \"NMT\";
		dpeType		= \"DEFAULT\";
		OPCgroup	= \"Comm\";
		num 		= 0;
		if (dpExists (prefix + dpeName))
			{
			OPCAddress (prefix + dpeName, OPCgroup, Bus + \".\" + OPCItemName, dpeType);
			}

		else DebugN(\"Error! Datapoint\", prefix + dpeName, \"doesn't exist!\");
	}

  /* close OPCCanServer.cfg file */
  fclose(opc); // close file
DebugN(getCurrentTime());  
  setValue(\"\",\"foreCol\",\"\");
}

/****************************************************************************\\
|* This function sets the opc item foer the datapoint element dpeName		*|
\\****************************************************************************/
OPCAddress(string dpeName, string OPCGroup, string OPCItemName, string dpeType )
{
string reference;
int direction, intDpeType, rc, type;
dyn_errClass err;

	// 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 \"DEFAULT\"	: intDpeType = 0;	   break; // 8-Bit Integer signed/unsigned
		case \"UINT16\"	: intDpeType = 488;    break; // 16-Bit Integer unsigned
		case \"UINT32\"	: intDpeType = 489;    break; // 32-Bit Integer signed
		case \"INT16\"	: intDpeType = 481;    break; // 16 bit integer signed
		case \"INT32\"	: intDpeType = 482;    break; // 32 bit integer signed
		case \"UCHAR\"	: intDpeType = 483;    break; // Character unsigned
		case \"FLOAT32\"	: intDpeType = 484;    break; // 32 bit float
		case \"FLOAT64\"	: intDpeType = 485;    break; // 64 bit float
		case \"BOOL\"		: intDpeType = 486;    break; // Bool
		case \"STRING\"	: intDpeType = 487;    break; // String
		case \"UNDEFINED\": intDpeType = 480;    break; // Undefined
/*
			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
*/
		}

	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(\"---------\");*/
} 

/****************************************************************************\\
|* 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);
		}
}

/****************************************************************************\\
|* This function write the address line related to the dpeName				*| 
|* datapoint element in the OPCCanServer.cfg file							*|
\\****************************************************************************/
void writeSDOcfg ( file opc, string OPCItemName, string Crate, int num, string dpeType)
{
bool ok;
ok = TRUE;

switch(dpeType)
	{
	case \"DEFAULT\"	: dpeType = \"VT_UI1\"	; break; // 8-Bit Integer signed/unsigned
	case \"UINT16\"	: dpeType = \"VT_UI2\"	; break; // 16-Bit Integer unsigned
	case \"UINT32\"	: dpeType = \"VT_UI4\"	; break; // 32-Bit Integer signed
	case \"INT16\"	: dpeType = \"VT_I2\"		; break; // 16 bit integer signed
	case \"INT32\"	: dpeType = \"VT_I4\"		; break; // 32 bit integer signed
	case \"FLOAT32\"	: dpeType = \"VT_FLOAT4\"	; break; // 32 bit float
	case \"FLOAT64\"	: dpeType = \"VT_FLOAT8\"	; break; // 64 bit float
	case \"BOOL\"		: dpeType = \"VT_BOOL\"	; break; // Bool
	case \"STRING\"	: dpeType = \"VT_STRING\"	; break; // String
	default			: ok = FALSE			; break; // Undefined
	}
	
if (!ok)
	{
	DebugN(\"Error! The element type \", dpeType, \"is invalid for OPC server\");
	return;
	}
	
fputs(Crate + OPCItemName + \"  = \" + Crate + \" \" 
		+ num + \" IO \" + dpeType + \"\\n\", opc);
}
																			
/****************************************************************************\\
|* 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;

  /* 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);

  /* 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;
}" 0
 E E E
13 8
"Button3"
""
1 320 20 E E E 1 E 1 E N "_3DText" E N {255,128,64} E E
 E E
5 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 ""
318 18 552 82
T 
1
LANG:1 17 Acknoledge Alerts
"//Acknoledge Alerts
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 9
"Button7"
""
1 360 230 E E E 1 E 1 E N "_3DText" E N {255,128,64} E E
 E E
6 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 ""
318 88 552 152
T 
1
LANG:1 14 Delete Configs
"//Delete Configs
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
13 11
"Button9"
""
1 197 280 E E E 1 E 1 E N "_3DText" E N {102,204,255} E E
 E E
8 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 ""
58 88 292 152
T 
1
LANG:1 14 Set Conversion
"//Function CreateAddress()
/*
1234567890123456789012345678901234567890123456789012345678901234567890123456
																			
*/
main()
{
string 	prefix, Crate, dpeName;
int i, crat, UnitMax;

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

	/* 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);
		}
	}
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 13
"Button6"
""
1 700 470 E E E 1 E 1 E N "_3DText" E N {255,128,64} 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 ""
318 158 552 222
T 
1
LANG:1 16 Unset Conversion
"//Unset Conversion
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
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