FUNCTION_BLOCK ReadE300IO
(*=====================================================================================================================================
	[UDFB Name]					:ReadE300IO    
	[Category]					:Communication
	[Description]				:Read the CIP Discrete Input Status from a compatible device using Explicit Messaging
	[Author]					:Rockwell Automation
	[Created using CCW version]	:8.0
	[FeedBack]					:pmcdonagh@henry-pump.com
	[Revison History]			:2015-October
	[Notes]						:

 =====================================================================================================================================*)
MSGObjRead_EN := Enable;
FBENO := FBEN;
(*-------- Initialize --------*)
FBEN_RTRIG(FBEN);
IF (__SYSVA_FIRST_SCAN OR FBEN_RTRIG.Q) THEN
	MSGObjRead_EN					:= TRUE;
	
	IF UpdateRate_ms < 1000 THEN 
   		ObjReadCtrlCfg.TriggerType 	:= 1000; (*Triggers message every 1000 ms while MSGObjRead_EN is true*)
	ELSE
		ObjReadCtrlCfg.TriggerType 	:= ANY_TO_UDINT(UpdateRate_ms);
	END_IF;
	ObjReadTargetCfg.Path			:= '4,'+ IPAddress;
	ObjReadTargetCfg.CipConnMode	:= 1;    (*0-unconnected, 1-Class 3*)
	ObjReadTargetCfg.UcmmTimeout	:= 250;  (*Unconnected message time out, Set to 0 means 3000ms, range 250-10000*)
	ObjReadTargetCfg.ConnMsgTimeout	:= 800;  (*Class3 time out, Set to 0 means 3000ms, range 800-10000*)
	ObjReadTargetCfg.ConnClose		:= FALSE;(*Don't close the connection upon message completion*)
	ObjReadAppCfg.Service			:= 14;    (*Service code 0eh for Get Attributes All*)
	ObjReadAppCfg.Class				:= 8;   (*Class code 0x0008h for Discrete Input Point Object*)
	ObjReadAppCfg.Instance			:= 1 + ANY_TO_UDINT(ChannelNumber);    (*Instance 1*)
	ObjReadAppCfg.Attribute			:= 3;    (*Attribute 3: Value*)
	ObjReadAppCfg.MemberCnt			:= 1;
	CIPErrorStatus					:= NoErrorStatus;
	
	
END_IF;

FBEN_FTRIG(FBEN);
IF FBEN_FTRIG.Q THEN
	CIPErrorStatus	:= NoErrorStatus;
	
END_IF;

(*-------- Main Routine --------*)
IF FBEN THEN
	MSGObjRead_Q_RTRIG(MSGObjRead.Q);
		
	IF MSGObjRead_Q_RTRIG.Q THEN
		CIPErrorStatus	:= MSGObjRead.Status;
		IF ObjReadResData[0] = 0 THEN
			IOStatus := FALSE;
		ELSE
			IOStatus:= TRUE;
		END_IF;
	END_IF;
	
	MSGObjRead_Err_RTRIG(MSGObjRead.Status.Error);
	

	IF MSGObjRead_Err_RTRIG.Q THEN
		MSGObjRead_EN	:= FALSE;
		CIPErrorStatus	:= MSGObjRead.Status;
		
	END_IF;
	
ELSE
	MSGObjRead_EN	:= FALSE;
	
END_IF;

MSGObjRead(MSGObjRead_EN, ObjReadCtrlCfg, ObjReadAppCfg, ObjReadTargetCfg,, 1, ObjReadResData);


END_FUNCTION_BLOCK