FUNCTION_BLOCK RA_PFx_ENET_PAR_READ
(*=====================================================================================================================================
	[UDFB Name]					:RA_PFx_ENET_PAR_READ (v6)     
	[Catagory]					:Communication
	[Description]				:Read a single PF4x or PF52x drive parameter over Ethernet using Explicit Messaging (v6)
	[Author]					:Rockwell Automation
	[Created using CCW version]	:6.01
	[FeedBack]					:RASampleCode@ra.rockwell.com
	[Revison History]			:2014-August - Original Release for Version 6
	[Notes]						:DO NOT USE THIS UDFB WITH MORE THAN 4 DRIVES IN A PROJECT - IF YOU DO, YOU WILL GET RANDOM MSG ERRORS!

 =====================================================================================================================================*)

FBENO := FBEN;
(*-------- Initialize --------*)
FBEN_RTRIG(FBEN);
IF (__SYSVA_FIRST_SCAN OR FBEN_RTRIG.Q) THEN
	
	IF UpdateRate_ms < 1000 THEN 
   		ParReadCtrlCfg.TriggerType 	 := 1000; (*Triggers message every 1000 ms while MSGParRead_EN is true*)
	ELSE
		ParReadCtrlCfg.TriggerType 	 := ANY_TO_UDINT(UpdateRate_ms);
	END_IF;
	
	ParReadTargetCfg.Path			:= '4,'+ IPAddress;
	ParReadTargetCfg.CipConnMode	:= 0;    (*0-unconnected, 1-Class 3*)
	ParReadTargetCfg.UcmmTimeout	:= 250;  (*Unconnected message time out, Set to 0 means 3000ms, range 250-10000*)
	ParReadTargetCfg.ConnMsgTimeout	:= 800;  (*Class3 time out, Set to 0 means 3000ms, range 800-10000*)
	ParReadTargetCfg.ConnClose		:= FALSE;(*Don't close the connection upon message completion*)
	ParReadAppCfg.Service			:= 14;   (*Service code 0Eh for Get Attribute Single*)
	ParReadAppCfg.Class				:= 15;   (*Class code 0Fh for Parameter Object*)
	ParReadAppCfg.Attribute			:= 1;    (*Attribute 1 for Parameter Value*)
	CIPErrorStatus					:= NoErrorStatus;
	
END_IF;

(*-------- Main Routine --------*)
IF FBEN THEN
	ParReadAppCfg.Instance	:= ANY_TO_UDINT(ParameterNumber);
	MSGParRead_Q_RTRIG(MSGParRead.Q);
	MSGParRead_Err_RTRIG(MSGParRead.Status.Error);
	
	IF MSGParRead_Q_RTRIG.Q THEN
		CIPErrorStatus	:= MSGParRead.Status;
		ParameterValue	:= ANY_TO_UINT(SHL(ANY_TO_DINT(ParReadResData[2]),8)+ ANY_TO_DINT(ParReadResData[1]));
	END_IF;
		
	IF MSGParRead_Err_RTRIG.Q THEN
		CIPErrorStatus	:= MSGParRead.Status;
		ParameterValue	:= 0;
	END_IF;
	
ELSE
	ParameterValue	:= 0;
	
END_IF;

MSGParRead_EN := FBEN;
MSGParRead(MSGParRead_EN, ParReadCtrlCfg, ParReadAppCfg, ParReadTargetCfg,, 0, ParReadResData);
END_FUNCTION_BLOCK