FUNCTION_BLOCK PMC_ReadXbotState
	IF Enable = TRUE THEN
		(* Statement section IF*)
		IF (XbotID > 0) AND (XbotID <= MaxXbots) THEN
			(* Statement section IF*)
			ByteOffset := LREAL_TO_USINT(floor((XbotID-1)/2));
			BitOffset := XbotID - 1 - ByteOffset * 2;
			(*uTemp := P2H_XBOT_STATE + ByteOffset;*)
			memcpy(pDest := ADR(uTemp),pSrc := ADR(FBin_pointer) + P2H_START + P2H_XBOT_STATE_OFFSET + ByteOffset,length := 1);
			IF BitOffset = 0 THEN
				(* Statement section IF*)
				State := uTemp AND 15;
			ELSE
				uTemp := uTemp AND 240;
				State := SHR(uTemp,4);
			END_IF;
	        
			Valid := TRUE;
		ELSE
			Valid := FALSE;
		END_IF;
	ELSE
		Valid := FALSE;
	END_IF;

END_FUNCTION_BLOCK
