//This file was generated by the LASAL2 CodeGenerator  -- 
//Please, do not edit this file (it might be overwritten by the next generator run)
//{{LSL_DECLARATION

(*!
<Class
	Name               = "_LMCAxisRef"
	Revision           = "1.32"
	GUID               = "{04D2AAAB-7F37-4C17-BCEC-EC9C3304C3A1}"
	RealtimeTask       = "false"
	CyclicTask         = "false"
	BackgroundTask     = "false"
	Sigmatek           = "true"
	OSInterface        = "false"
	HighPriority       = "false"
	Automatic          = "false"
	UpdateMode         = "Prescan"
	IconPath           = ".\Class\_LMCAxisRef\AxisRef.ico"
	SharedCommandTable = "true"
	Objectsize         = "(358,120)"
	Comment            = "This class provides referencing functions for the axes. &#13;&#10;With this class, the most common referencing variations &#13;&#10;can be performed.">
	<Channels>
		<Server Name="ZPulseDist" GUID="{5A0D5952-8A7D-4EA9-97CB-2960C3076E34}" Visualized="true" Initialize="false" WriteProtected="true" Retentive="false" Comment="Shows the distance between the Z pulse and the point where &#13;&#10;the reference switch is released [application units]."/>
		<Client Name="HWMax" Required="false" Internal="false" Comment="Input for the hardware switch maximum"/>
		<Client Name="HWMin" Required="false" Internal="false" Comment="Input for the hardware switch minimum."/>
		<Client Name="LatchPos" Required="false" Internal="false" Comment="External position [incr] used in mode &quot;RefLatchPos&quot;"/>
		<Client Name="RefSwitch" Required="false" Internal="false" Comment="Reference switch input"/>
		<Client Name="ZImpulse" Required="false" Internal="false" Comment="This input is used to determine the switching status of the Z pulse"/>
	</Channels>
	<RevDoku>
		<Owner Company="Sigmatek"/>
		<Dokumentation Revision="1.32" Date="2019-08-07" Author="ArmKle" Company="Sigmatek" Description="1. Bugfix:&#13;&#10;Failure to complete referencing in a special case where the refenrence switch was made at startup with a specific configuration has been fixed."/>
		<Dokumentation Revision="1.31" Date="2015-09-25" Author="FucHer" Company="Sigmatek" Description="1. Improvement: new cases RefDirectionWait and RefSwitchWait in Control()"/>
		<Dokumentation Revision="1.30" Date="2014-07-07" Author="HasHan" Company="Sigmatek" Description="1. Improvement: added ReadParameter() for reading the ZPulseDist"/>
		<Dokumentation Revision="1.20" Date="2013-07-18" Author="SliMic" Company="Sigmatek" Description="1. now the HW Endswitches were observed by the reference with Z-Impuls"/>
		<Dokumentation Revision="1.0" Date="2012-09-27" Company="Sigmatek" Description="creation"/>
	</RevDoku>
	<Network Name="_LMCAxisRef">
		<!-- List of Components in this network -->
		<Components>
			<Object
				Name       = "_base"
				GUID       = "{6D72E8D7-A2D8-441A-BA21-1670B6A2A5BC}"
				Class      = "_LMCRefBase"
				Position   = "(218,120)"
				Visualized = "true">
				<Channels>
					<Server Name="RefInput"/>
				</Channels>
			</Object>
		</Components>
		<Comments>
		</Comments>
		<!-- List of Connections in this network -->
		<Connections>
			<Connection Source="this.RefInput" Destination="_base.RefInput" Vertices="(690,210),(518,210),"/>
		</Connections>
		<!-- Headerfiles -->
		<Options>
		</Options>
	</Network>
</Class>
*)
#pragma using _LMCRefBase

_LMCAxisRef : CLASS
: _LMCRefBase
	TYPE
	  _REFCASE :
	  (
	    RefIdle,
	    RefGo,
	    RefReady,
	    RefError,
	    RefFindESP,  //! <Type Comment="Moving in pos. direction, waiting for HWMax switch, turning on end switches" Name="_REFCASE.RefFindESP"/>
	    RefFindESN,  //! <Type Comment="Moving in neg. direction, waiting for HWMin switch, turning on end switches" Name="_REFCASE.RefFindESN"/>
	    RefFindRSP,  //! <Type Comment="Moving in pos. direction, waiting for reference switch, turning on end switches" Name="_REFCASE.RefFindRSP"/>
	    RefFindRSN,  //! <Type Comment="Moving in neg. direction, waiting for reference switch, turning on end switches" Name="_REFCASE.RefFindRSN"/>
	    RefFindORSP,  //! <Type Comment="Moving in pos. direction, waiting for reference switch, ignoring switches" Name="_REFCASE.RefFindORSP"/>
	    RefFindORSN,  //! <Type Comment="Moving in neg. direction, waiting for reference switch, ignoring switches" Name="_REFCASE.RefFindORSN"/>
	    RefESClear,  //! <Type Comment="Wait until the switch (reference or endswitch) is reset" Name="_REFCASE.RefESClear"/>
	    RefRSClear,
	    RefRefWait,
	    RefPosWait,
	    Ref0Wait,  //! <Type Comment="Waiting for Z-impulse" Name="_REFCASE.Ref0Wait"/>
	    RefLatchPosP,  //! <Type Comment="Moving in pos. direction, waiting for latch position, turning on end switches" Name="_REFCASE.RefLatchPosP"/>
	    RefLatchPosN,  //! <Type Comment="Moving in neg. direction, waiting for latch position, turning on end switches" Name="_REFCASE.RefLatchPosN"/>
	    RefLatchPosOP,  //! <Type Comment="Moving in pos. direction, waiting for latch position, ignoring end switches" Name="_REFCASE.RefLatchPosOP"/>
	    RefLatchPosON,  //! <Type Comment="Moving in neg. direction, waiting for latch position, ignoring end switches" Name="_REFCASE.RefLatchPosON"/>
	    RefDirectionWait,  //! <Type Comment="Wait until the axis moves in the opposite direction" Name="_REFCASE.RefDirectionWait"/>
	    RefSwitchWait  //! <Type Comment="Wait until the switch (Ref.switch or HW-Endswitch) is &quot;On&quot; again" Name="_REFCASE.RefSwitchWait"/>
	  )$UDINT;
	END_TYPE
  //Servers:
	ZPulseDist 	: SvrCh_DINT;
  //Clients:
	HWMin 	: CltCh_DINT;
	HWMax 	: CltCh_DINT;
	ZImpulse 	: CltCh_DINT;
	RefSwitch 	: CltCh_DINT;
	LatchPos 	: CltCh_DINT;
  //Variables:
		RefCase 	: _REFCASE;
		RefMode 	: _LMCAXIS_REFMODE;
		ResFac 	: DINT;
		Hires 	: DINT;
		Speed1Int 	: DINT;
		Speed2Int 	: DINT;
		AccelInt 	: DINT;
		WindowInt 	: DINT;
		PosEs 	: DINT;
		LatchPosStart 	: DINT;			//! <Variable Comment="Value of client cLatchPos at start of ref. search" Name="LatchPosStart"/>
		pStatusAxis 	: ^_LMCAXIS_STATUS;
		pErrorAxis 	: ^_LMCAXIS_ERROR;
		RefSpeedFirstEdge 	: DINT;			//! <Variable Comment="Actual speed at first edge of switch [Internal Units/tick]" Name="RefSpeedFirstEdge"/>
  //Functions:
				//! <Function Comment="Receives the information of the reference mode in which the _LMCAxis is running.&#13;&#10;Controls the reference signals inputs and also the ref. steps." Name="control"/>
	FUNCTION VIRTUAL GLOBAL control
		VAR_INPUT
			mode 	: _LMCAXIS_REFMODE;			//! <Variable Comment="Adjusted mode of the reference-run: see _LMCAXIS_REFMODE" Name="control.mode"/>
			RefStatus 	: ^_LMCAXIS_REFDATA;			//! <Variable Comment="Pointer to the datastructure of the adjusted mode of a reference-run: see: _LMCAXIS_REFDATA" Name="control.RefStatus"/>
			pos 	: ^DINT;			//! <Variable Comment="Pointer to a physical position" Name="control.pos"/>
			StartRef 	: DINT;			//! <Variable Comment="StartRef is set to &quot;1&quot; to kickk off the reference-run" Name="control.StartRef"/>
		END_VAR;
				//! <Function Comment="Function for writing the constants:&#13;&#10;Resolution, Timebase and &#13;&#10;init-state of the FSM of a reference-run: RefCase:=RefIdle;&#13;&#10; " Name="WriteConstant"/>
	FUNCTION VIRTUAL GLOBAL WriteConstant
		VAR_INPUT
			Resolution 	: DINT;			//! <Variable Comment="Internal resolution factor" Name="WriteConstant.Resolution"/>
			Timebase 	: DINT;			//! <Variable Comment="Number of cycles per second" Name="WriteConstant.Timebase"/>
			vMax 	: DINT;
			aMax 	: DINT;
		END_VAR;
				//! <Function Comment="Adopts the addresses of the Servers: AxisStatus and AxisError&#13;&#10;around this for reading and updating" Name="SetAxisFlgs"/>
	FUNCTION VIRTUAL GLOBAL SetAxisFlgs
		VAR_INPUT
			pAxisStatus 	: ^_LMCAXIS_STATUS;
			pAxisError 	: ^_LMCAXIS_ERROR;
		END_VAR
		VAR_OUTPUT
			Result 	: DINT;
		END_VAR;
				//! <Function Comment="this function returns true,if one of the clients:&#13;&#10;HWMin, HWMax, ZImpulse, RefSwitch or LatchPos is connected" Name="CheckConnection"/>
	FUNCTION VIRTUAL GLOBAL CheckConnection
		VAR_OUTPUT
			RetCode 	: BOOL;			//! <Variable Comment="true  ... something connected&#13;&#10;false ... nothing connected" Name="CheckConnection.RetCode"/>
		END_VAR;
				//! <Function Comment="Reads the software parameters." Name="ReadParameter"/>
	FUNCTION VIRTUAL GLOBAL ReadParameter
		VAR_INPUT
			ParNr 	: _LMCREF_READPARAMETER;			//! <Variable Comment="Parameter number" Name="ReadParameter.ParNr"/>
		END_VAR
		VAR_OUTPUT
			Result 	: DINT;			//! <Variable Comment="parameter" Name="ReadParameter.Result"/>
		END_VAR;
  //Tables:
	FUNCTION @STD
		VAR_OUTPUT
			ret_code	: CONFSTATES;
		END_VAR;
	FUNCTION GLOBAL TAB @CT_;
END_CLASS;

//}}LSL_DECLARATION


FUNCTION GLOBAL TAB _LMCAxisRef::@CT_
0$UINT,
2#0100000000000000$UINT, //TY__LMCAXISREF
1$UINT, 32$UINT, (SIZEOF(::_LMCAxisRef))$UINT, 
1$UINT, 5$UINT, 0$UINT, 
TO_UDINT(2147194214), "_LMCAxisRef", //Class
TO_UDINT(1736530975), "_LMCRefBase", 1$UINT, 11$UINT, //Baseclass
//Servers:
(::_LMCAxisRef.ZPulseDist.pMeth)$UINT, _CH_SVR$UINT, 2#0000000000000000$UINT, TO_UDINT(757568017), "ZPulseDist", 
//Clients:
(::_LMCAxisRef.HWMin.pCh)$UINT, _CH_CLT_DATA$UINT, 2#0000000000000000$UINT, TO_UDINT(820401606), "HWMin", 
(::_LMCAxisRef.HWMax.pCh)$UINT, _CH_CLT_DATA$UINT, 2#0000000000000000$UINT, TO_UDINT(216754847), "HWMax", 
(::_LMCAxisRef.ZImpulse.pCh)$UINT, _CH_CLT_DATA$UINT, 2#0000000000000000$UINT, TO_UDINT(3924944392), "ZImpulse", 
(::_LMCAxisRef.RefSwitch.pCh)$UINT, _CH_CLT_DATA$UINT, 2#0000000000000000$UINT, TO_UDINT(3537427625), "RefSwitch", 
(::_LMCAxisRef.LatchPos.pCh)$UINT, _CH_CLT_DATA$UINT, 2#0000000000000000$UINT, TO_UDINT(3334411160), "LatchPos", 
END_FUNCTION


#define USER_CNT__LMCAxisRef 5

TYPE
	_LSL_STD_VMETH	: STRUCT
			CmdTable	: CMDMETH;
			UserFcts	: ARRAY[0..USER_CNT__LMCAxisRef] OF ^Void;
	END_STRUCT;
END_TYPE

FUNCTION _LMCAxisRef::@STD
	VAR_OUTPUT
		ret_code	: CONFSTATES;
	END_VAR
	VAR
		vmt	: _LSL_STD_VMETH;
		nCmdSize	: UINT;
	END_VAR

	ret_code	:= _LMCRefBase::@STD();
	IF ret_code <> C_OK THEN
		RETURN;
	END_IF;
	nCmdSize		:= _LMCRefBase::RefInput.pMeth^.nCmds$UINT*SIZEOF(pVoid) + CMDMETH.Init;

	_memcpy((#vmt.CmdTable)$^USINT, _LMCRefBase::RefInput.pMeth, nCmdSize);
	vmt.CmdTable.nCmds		:= nSTDCMD + USER_CNT__LMCAxisRef;
#pragma warning (disable : 74)
	vmt.UserFcts[0]		:= #control();

#pragma warning (default : 74)
#pragma warning (disable : 74)
	vmt.UserFcts[1]		:= #WriteConstant();

#pragma warning (default : 74)
#pragma warning (disable : 74)
	vmt.UserFcts[2]		:= #SetAxisFlgs();

#pragma warning (default : 74)
#pragma warning (disable : 74)
	vmt.UserFcts[3]		:= #CheckConnection();

#pragma warning (default : 74)
#pragma warning (disable : 74)
	vmt.UserFcts[4]		:= #ReadParameter();

#pragma warning (default : 74)
	_LMCRefBase::RefInput.pMeth		:= StoreCmd (pCmd := #vmt.CmdTable, SHARED);

	IF _LMCRefBase::RefInput.pMeth THEN
		ret_code	:= C_OK;
	ELSE
		ret_code	:= C_OUTOF_NEAR;
		RETURN;
	END_IF;

END_FUNCTION

//{{LSL_IMPLEMENTATION
//{{LSL_ENCRYPTION 16#800
[encoded data, 40736 characters]