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

//{{LSL_DEFINES
#define LMCCONTROLLER_SAFETYID_SBTTESTTIME        16#6723
#define LMCCONTROLLER_SAFETYSUBID_SBTTESTTIME     1
#define LMCCONTROLLER_SAFETYID_SBTMINTORQUE       16#6724
#define LMCCONTROLLER_SAFETYSUBID_SBTMINTORQUE    1
#define LMCCONTROLLER_SAFETYID_SBTTESTINTERVAL    16#6728
#define LMCCONTROLLER_SAFETYSUBID_SBTTESTINTERVAL 1

// defines from Headerfile DriveSafetyIF.h to reduce the dependency to the HW Lib
#define DPCS_DRIVESAFETYIF_NEWINSTPDO                          100       // DRIVESAFETYIF_NEWINSTPDO
#define DPCS_DRIVESAFETYIF_READPDODATA                         101       // DRIVESAFETYIF_READPDODATA
#define DPCS_DRIVESAFETYIF_WRITEPDODATA                        102       // DRIVESAFETYIF_WRITEPDODATA
#define DPCS_DRIVESAFETYIF_DOAXERRORQUIT                       0x8591    // DRIVESAFETYIF_DOAXERRORQUIT
#define DPCS_DRIVESAFETYIF_DOAXERRORQUIT_VER_1                 1         // version 1 -> DRIVESAFETYIF_DOAXERRORQUIT
#define DPCS_DRIVESAFETYIF_DOSAFETYAXERRORQUIT                 0x8592    // DRIVESAFETYIF_DOSAFETYAXERRORQUIT
#define DPCS_DRIVESAFETYIF_DOSAFETYAXERRORQUIT_VER_1           1         // version 1 -> DRIVESAFETYIF_DOSAFETYAXERRORQUIT
#define DPCS_DRIVESAFETYIF_READAXISSTATE                       0x8590    // DRIVESAFETYIF_READAXISSTATE
#define DPCS_DRIVESAFETYIF_READAXISSTATE_VER_1                 1         // version 1 -> DRIVESAFETYIF_READAXISSTATE_VER_1
#define DPCS_DRIVESAFETYIF_SETVERIFYAXIS                       0x8593    // DRIVESAFETYIF_SETVERIFYAXIS
#define DPCS_DRIVESAFETYIF_SETVERIFYAXIS_VER_1                 1         // version 1 -> DRIVESAFETYIF_SETVERIFYAXIS_VER_1
#define DPCS_DRIVESAFETYIF_SETREFERENCEAXIS                    0x8595    // DRIVESAFETYIF_SETREFERENCEAXIS
#define DPCS_DRIVESAFETYIF_SETREFERENCEAXIS_VER_1              1         // version 1 -> DRIVESAFETYIF_SETREFERENCEAXIS_VER_1
#define DPCS_DRIVESAFETYIF_GETSAFECONTROLSTATEWORD             0x859D    // DRIVESAFETYIF_GETSAFECONTROLSTATEWORD
#define DPCS_DRIVESAFETYIF_GETSAFECONTROLSTATEWORD_VER_1       1         // version 1 -> DRIVESAFETYIF_GETSAFECONTROLSTATEWORD_VER_1
#define DPCS_DRIVESAFETYIF_SETACKZEROPOSITION                  0x8597    // DRIVESAFETYIF_SETACKZEROPOSITION
#define DPCS_DRIVESAFETYIF_SETACKZEROPOSITION_VER_1            1         // version 1 -> DRIVESAFETYIF_SETACKZEROPOSITION_VER_1
#define DPCS_DRIVESAFETYIF_SETSBTSTATE                         0x8599    // DRIVESAFETYIF_SETSBTSTATE
#define DPCS_DRIVESAFETYIF_SETSBTSTATE_VER_1                   1         // version 1 -> DRIVESAFETYIF_SETSBTSTATE_VER_1
#define DPCS_DRIVESAFETYIF_GETVERIFYSTATE                      0x8594    // DRIVESAFETYIF_GETVERIFYSTATE
#define DPCS_DRIVESAFETYIF_GETVERIFYSTATE_VER_1                1         // version 1 -> DRIVESAFETYIF_GETVERIFYSTATE_VER_1
#define DPCS_DRIVESAFETYIF_CHANGESAFESERVICEMODE               0x859E    // DRIVESAFETYIF_CHANGESAFESERVICEMODE
#define DPCS_DRIVESAFETYIF_CHANGESAFESERVICEMODE_VER_1         1         // version 1 -> DRIVESAFETYIF_CHANGESAFESERVICEMODE_VER_1
#define DPCS_DRIVESAFETYIF_ADD_PARA_OBJECT                     16#857B   // DRIVESAFETYIF_ADD_PARA_OBJECT
#define DPCS_DRIVESAFETYIF_ADD_PARA_OBJECT_VER_1               1         // version 1 - > DRIVESAFETYIF_ADD_PARA_OBJECT_VER_1
#define DPCS_DRIVESAFETYIF_GETREFERENCESTATE                   0x8596    // DRIVESAFETYIF_GETREFERENCESTATE
#define DPCS_DRIVESAFETYIF_GETREFERENCESTATE_VER_1             1         // version 1 -> DRIVESAFETYIF_GETREFERENCESTATE_VER_1
#define DPCS_DRIVESAFETYIF_GETSBTSTATE                         0x8598    // DRIVESAFETYIF_GETSBTSTATE
#define DPCS_DRIVESAFETYIF_GETSBTSTATE_VER_1                   1         // version 1 -> DRIVESAFETYIF_GETSBTSTATE_VER_1
#define DPCS_DRIVESAFETYIF_GETGENERALPARA                      0x859A    // DRIVESAFETYIF_GETGENERALPARA
#define DPCS_DRIVESAFETYIF_GETGENERALPARA_VER_1                1         //version 1 -> DRIVESAFETYIF_GETGENERALPARA_VER_1
#define DPCS_DRIVESAFETYIF_GETSAFETYERRORINFOS                 0x859B    // DRIVESAFETYIF_GETSAFETYERRORINFOS
#define DPCS_DRIVESAFETYIF_GETSAFETYERRORINFOS_VER_1           1         //version 1 -> DRIVESAFETYIF_GETSAFETYERRORINFOS_VER_1
#define DPCS_DRIVESAFETYIF_GETSAFEFUNCTIONERRORINFOS           0x859C    // DRIVESAFETYIF_GETSAFEFUNCTIONERRORINFOS
#define DPCS_DRIVESAFETYIF_GETSAFEFUNCTIONERRORINFOS_VER_1     1         //version 1 -> DRIVESAFETYIF_GETSAFEFUNCTIONERRORINFOS_VER_1




//}}LSL_DEFINES

//{{LSL_DECLARATION

(*!
<Class
	Name               = "DrivePosControlSafety"
	Revision           = "1.4"
	GUID               = "{459D7342-C14C-4339-B58B-A80825C908CB}"
	RealtimeTask       = "false"
	CyclicTask         = "false"
	BackgroundTask     = "false"
	Sigmatek           = "true"
	OSInterface        = "false"
	HighPriority       = "false"
	Automatic          = "false"
	UpdateMode         = "Prescan"
	IconPath           = ".\Class\DrivePosControl\Controller.ico"
	SharedCommandTable = "true"
	Objectsize         = "(498,120)"
	Comment            = "The DrivePosControlSafety class is used in combination with a Sigmatek DiasDrive with safety features for position control with speed feedforward.">
	<Channels>
		<Server Name="SetPosOut" GUID="{0D29525F-C059-4247-B6C9-F7A4CEE22FEA}" Visualized="false" Initialize="false" WriteProtected="true" Retentive="false" Comment="Actual Set Position which is written to the Drive Axis object [Application Units]"/>
		<Server Name="SetVelOut" GUID="{AE5FCB0A-F04B-48E2-8BD6-DFE01BD840AA}" Visualized="false" Initialize="false" WriteProtected="true" Retentive="false" Comment="Actual set velocity which can be written to the Drive Axis object [Internal Units / Tik]"/>
		<Server Name="XW" GUID="{9B0A86A5-1C2D-4D77-B413-3C3B76B64860}" Visualized="true" Initialize="false" WriteProtected="false" Retentive="false" Comment="In this server, the actual contouring error (difference between set position and &#13;&#10;actual position) is shown [Internal units]. Depending on the setting in SetConf &#13;&#10;the Xw is directly from the drive or calculated in the PLC."/>
		<Server Name="XWMax" GUID="{2774BC6A-3196-4EB6-BF39-2B61F7B34863}" Visualized="true" Initialize="false" WriteProtected="false" Retentive="false" Comment="In this server, the maximum contouring error (difference between set position and &#13;&#10;actual position) is shown [Internal units]. This value can be reset using the server&apos;s &#13;&#10;write function."/>
		<Client Name="ActXW" Required="false" Internal="false" Comment="Optional client (when this client is connected the functional communication is done via optional clients, only safety data is transferred via DriveAxis command channel):&#13;&#10;Connect this client to read the actual drag from the connected axis."/>
		<Client Name="Draglimit" Required="false" Internal="false" Comment="Maximum limit of the contouring error [Application units].&#13;&#10;By entering &quot;0&quot; the monitoring of the contouring error can be deactivated."/>
		<Client Name="DriveAxis" Required="false" Internal="false" Comment="Connection to the drive Axis object"/>
		<Client Name="DriveEnabled" Required="false" Internal="false" Comment="Optional client (when this client is connected the functional communication is done via optional clients, only safety data is transferred via DriveAxis command channel):&#13;&#10;When optional clients are used either this client or client StateWord have to be connected. When client StateWord is connected this value is not read.&#13;&#10;Connect this client to read if the connected axis is operational."/>
		<Client Name="Enable" Required="false" Internal="false" Comment="Optional client (when this client is connected the functional communication is done via optional clients, only safety data is transferred via DriveAxis command channel):&#13;&#10;Connect this client to enable the connected axis."/>
		<Client Name="HWError" Required="false" Internal="false" Comment="Optional client (when this client is connected the functional communication is done via optional clients, only safety data is transferred via DriveAxis command channel):&#13;&#10;When Client StateWord is connected this client is not read.&#13;&#10;Connect this client to read if an hw error on the axis occured."/>
		<Client Name="HWErrorQuit" Required="false" Internal="false" Comment="Optional client (when this client is connected the functional communication is done via optional clients, only safety data is transferred via DriveAxis command channel):&#13;&#10;Connect this client to quit axis errors."/>
		<Client Name="Online" Required="false" Internal="false" Comment="Optional client (when this client is connected the functional communication is done via optional clients, only safety data is transferred via DriveAxis command channel):&#13;&#10;Connect this client to read the online signal from the connected axis."/>
		<Client Name="PosOffset" Required="false" Internal="false" Comment="Position offset in drive units (i.e. increments)."/>
		<Client Name="SetConf" Required="false" Internal="false" DefValue="2#101" Comment="configuration settings"/>
		<Client Name="SetPos" Required="false" Internal="false" Comment="Optional client (when this client is connected the functional communication is done via optional clients, only safety data is transferred via DriveAxis command channel):&#13;&#10;Connect this client to set the desired position of the connected axis."/>
		<Client Name="SetSpeed" Required="false" Internal="false" Comment="Optional client (when this client is connected the functional communication is done via optional clients, only safety data is transferred via DriveAxis command channel):&#13;&#10;Connect this client to set the desired speed of the connected axis."/>
		<Client Name="StateWord" Required="false" Internal="false" Comment="Optional client (when this client is connected the functional communication is done via optional clients, only safety data is transferred via DriveAxis command channel):&#13;&#10;When optional clients are used either this client or client DriveEnabled have to be connected.&#13;&#10;Connect this client to read the actual status word of the axis."/>
	</Channels>
	<Separators>
		<Clients>
			<SepChn Position="4"/>
		</Clients>
	</Separators>
	<RevDoku>
		<Owner Company="Sigmatek"/>
		<Dokumentation Revision="1.4" Date="2025-02-13" Author="RauAnd" Company="Sigmatek" Description="reducing the dependency to hw class lib"/>
		<Dokumentation Revision="1.3" Date="2024-12-03" Author="StePhi" Company="Sigmatek" Description="1. Bugfix: The check if client SetPos is connected is done for SetConf instead. Error does not change class behaviour because information is not used."/>
		<Dokumentation Revision="1.2" Date="2024-06-14" Author="StePhi" Company="Sigmatek" Description="1. Bugfix: In case of a contouring error triggered by the controller the set position is not updated in tick of error and the old set position is outputted for two ticks. The inconsistent position might trigger a &quot;Trajectory Error&quot; at the connected drive hardware."/>
		<Dokumentation Revision="1.1" Date="2024-04-16" Author="StePhi" Company="Sigmatek" Description="1. Bugfix: Fixed access data size for read requests of SBT data from axis safety configuration. The result was the overwriting of uninvolved data and a crash via AccessError when calling the Read() or Write() method of the server &quot;AbsEncoder&quot; of the class _LMCAxis.&#13;&#10;2. Improvement: Added support for control action with speed and position in LREAL. The new control action is automatically activated when _JERK_PROFILE is used at the connected _LMCAxis object."/>
		<Dokumentation Revision="1.0" Date="2023-10-19" Author="StePhi" Company="Sigmatek" Description="Initial version"/>
	</RevDoku>
	<Network Name="DrivePosControlSafety">
		<!-- List of Components in this network -->
		<Components>
			<Object
				Name       = "_base"
				GUID       = "{6FAE3E3A-E643-4367-8BEC-655BD93AD5EF}"
				Class      = "Controller"
				Position   = "(218,120)"
				Visualized = "false">
				<Channels>
					<Server Name="Signal_Input"/>
				</Channels>
			</Object>
		</Components>
		<Comments>
		</Comments>
		<!-- List of Connections in this network -->
		<Connections>
			<Connection Source="this.Signal_Input" Destination="_base.Signal_Input" Vertices="(690,210),(518,210),"/>
		</Connections>
		<!-- Headerfiles -->
		<Options>
		</Options>
	</Network>
</Class>
*)
#pragma using Controller

DrivePosControlSafety : CLASS
: Controller
	TYPE
#pragma pack(push, 1)
	  _DragCalc : STRUCT
	    PosBuffer : ARRAY [0..MaxDragDelayCycles] OF DINT;
	    pBufferActPos : ^DINT;
	    pBufferCalcPos : ^DINT;
	    BufferRdy : BOOL;
	    IntPosCalc : DINT;
	    OverflowStart : DINT;
	    OverflowIndex : DINT;
	  END_STRUCT;
#pragma pack(pop)
#pragma pack(push, 1)
	  _SDD_PDO_READ_v1 : STRUCT
	    Online : BOOL;
	    StateWord : BSINT
	    [
	      1 ReadyToSwitchOn,
	      2 SwitchedOn,
	      3 OperationEnabled,
	      4 Fault,
	    ];
	    ActPos : DINT;
	    ActXw : DINT;
	  END_STRUCT;
#pragma pack(pop)
#pragma pack(push, 1)
	  _SDD_PDO_WRITE_ENTRY : STRUCT
	    Active : UINT;
	    Value : DINT;
	  END_STRUCT;
#pragma pack(pop)
#pragma pack(push, 1)
	  _SDD_PDO_WRITE_v1 : STRUCT
	    SetPos : _SDD_PDO_WRITE_ENTRY;
	    Enable : _SDD_PDO_WRITE_ENTRY;
	    SetSpeed : _SDD_PDO_WRITE_ENTRY;
	  END_STRUCT;
#pragma pack(pop)
	END_TYPE
  //Servers:
	XW 	: SvrCh_DINT;
	XWMax 	: SvrCh_DINT;
	SetPosOut 	: SvrCh_DINT;
	SetVelOut 	: SvrCh_DINT;
  //Clients:
	DriveAxis 	: CltChCmd_iprStates;
	SetConf 	: CltCh__POSFLAGS;
	Draglimit 	: CltCh_DINT;
	PosOffset 	: CltCh_DINT;
	Online 	: CltCh_DINT;
	Enable 	: CltCh_DINT;
	SetSpeed 	: CltCh_DINT;
	SetPos 	: CltCh_DINT;
	HWError 	: CltCh_DINT;
	HWErrorQuit 	: CltCh_DINT;
	DriveEnabled 	: CltCh_DINT;
	StateWord 	: CltCh_DS402_State;
	ActXW 	: CltCh_DINT;
  //Variables:
		pCNCVars 	: ^CNCInternalStruct;
		ResFac 	: DINT;
		SpeedInt 	: DINT;
		PosContrOff 	: DINT;
		fSpeedInt 	: LREAL;
		fPosContrOff 	: LREAL;
		Hires 	: DINT;
		SetSpeedInternal 	: DINT;
		StateWordInternal 	: DS402_State;
		SetPosOutInc 	: DINT;
		SetVelOutInc 	: DINT;
		DraglimInt 	: DINT;
		AxEnable 	: DINT;
		AccRamp 	: DINT;
		AccMax 	: DINT;
		AccEmergency 	: DINT;
		pStatusAxis 	: ^_LMCAXIS_STATUS;
		pErrorAxis 	: ^_LMCAXIS_ERROR;
		pControlAxis 	: ^_LMCAXIS_CONTROLBITS;
		DragCalc 	: _DragCalc;
		DragCalcDelay 	: DINT;
		PosBufferOffset 	: DINT;
		StoreActPos 	: DINT;
		DelayCounter 	: DINT;
		SBTActive 	: DINT;
		AsyncPoll : ARRAY [0..8] OF DINT;

		ClientConnected : BDINT
		[
		  1 HWAxis,
		  2 Enable,
		  3 SetSpeed,
		  4 SetPos,
		  5 HWError,
		  6 HWErrorQuit,
		  7 DriveEnabled,
		  8 StateWord,
		  9 Online,
		  10 ActXW,
		];

		PdoReadV1 	: _SDD_PDO_READ_v1;
		PdoWriteV1 	: _SDD_PDO_WRITE_v1;
		PdoWriteData 	: CmdStruct;
		PdoReadData 	: CmdStruct;
		NIReadDataHWDiag 	: CmdStruct;			//! <Variable Comment="CmdStruct Variable storing the command data to get the Hardware Diagnosis data from the connected DriveAxis." Name="NIReadDataHWDiag"/>
		NIResultHWDiag 	: results;			//! <Variable Comment="Variable storing the result of the NewInst command to read the hardware diagnosis data." Name="NIResultHWDiag"/>
		NIAxisGeneralWriteData 	: CmdStruct;
		NIAxisGeneralWriteResult 	: results;
		NIAxisGeneralReadData 	: CmdStruct;
		NIAxisGeneralReadResult 	: results;
		NIAxisStateData 	: CmdStruct;
		NIAxisStateResult 	: results;
		NIAxisSafeCntrStateData 	: CmdStruct;
		NIAxisSafeCntrStateResult 	: results;
  //Functions:
	
	FUNCTION VIRTUAL GLOBAL Init;
				//! <Function Comment="Receives as input from the CNC/_LMCAxis, the Actual Position and the Internal Position.&#13;&#10;Controls also the controller errors and Draglimits." Name="control"/>
	FUNCTION VIRTUAL GLOBAL control
		VAR_INPUT
			ActPos 	: DINT;
			IntPos 	: DINT;
		END_VAR
		VAR_OUTPUT
			Result 	: DINT;
		END_VAR;
	
	FUNCTION VIRTUAL GLOBAL ControlLongReal
		VAR_INPUT
			ActPos 	: LREAL;
			IntPos 	: LREAL;
			IntSpeed 	: LREAL;
		END_VAR;
				//! <Function Comment="Adopts the addresses of the Servers: AxisStatus, AxisError and the Bitfield:AxisControl&#13;&#10;around this for reading and updating" Name="SetAxisFlgs"/>
	FUNCTION VIRTUAL GLOBAL SetAxisFlgs
		VAR_INPUT
			pAxisStatus 	: ^_LMCAXIS_STATUS;
			pAxisError 	: ^_LMCAXIS_ERROR;
			pAxisControl 	: ^_LMCAXIS_CONTROLBITS;
		END_VAR
		VAR_OUTPUT
			Result 	: _LMCCONTROLLERTYPE;
		END_VAR;
				//! <Function Comment="Function to test if we have a controller connected to the CNC/_LMCAxis" Name="WriteConstant"/>
	FUNCTION VIRTUAL GLOBAL WriteConstant
		VAR_INPUT
			Resolution 	: DINT;
			Timebase 	: DINT;
			Accel 	: DINT;
			ptrCNCIntStruct 	: ^CNCInternalStruct;
		END_VAR
		VAR_OUTPUT
			StartSpeed 	: DINT;
		END_VAR;
				//! <Function Comment="Function used for transmitting the Speed value from the CNC/_LMCAxis to the controller" Name="Speed"/>
	FUNCTION VIRTUAL GLOBAL Speed
		VAR_INPUT
			ActSpeed 	: DINT;
		END_VAR;
				//! <Function Comment="Set Clients:&#13;&#10;0 ... cDraglimit&#13;&#10;1 ... DragCalcDelay&#13;&#10;2 ... SetConf&#13;&#10;4 ... PosOffset&#13;&#10;20 ... acc / accHires" Name="SetClients"/>
	FUNCTION VIRTUAL GLOBAL SetClients
		VAR_INPUT
			No 	: DINT;			//! <Variable Comment="The parameter number of the client that should be changed." Name="SetClients.No"/>
			Value 	: DINT;			//! <Variable Comment="The value to which the client should be changed." Name="SetClients.Value"/>
		END_VAR
		VAR_OUTPUT
			State 	: DINT;			//! <Variable Comment="0 =&gt; Error : The number entered was invalid or controller is active&#13;&#10;1 =&gt; Ok" Name="SetClients.State"/>
		END_VAR;
				//! <Function Comment="checks if the drive is enabled or not" Name="PowerIsOn"/>
	FUNCTION VIRTUAL GLOBAL PowerIsOn
		VAR_OUTPUT
			RetCode 	: BOOL;			//! <Variable Comment="true ... Drive is enabled" Name="PowerIsOn.RetCode"/>
		END_VAR;
				//! <Function Comment="checks if a Hardware Error is activ" Name="CheckHWError"/>
	FUNCTION VIRTUAL GLOBAL CheckHWError
		VAR_OUTPUT
			Retcode 	: BOOL;
		END_VAR;
				//! <Function Comment="check, wether the DrivAxis object is ready for communication." Name="CheckHwReady"/>
	FUNCTION VIRTUAL GLOBAL CheckHwReady
		VAR_OUTPUT
			IsReady 	: BOOL;
		END_VAR;
				//! <Function Comment="Read parameters:&#13;&#10;0 ... XW&#13;&#10;1 ... XWMax&#13;&#10;2 ... SetConf&#13;&#10;3 ... cDragLimmit&#13;&#10;4 ... PosOffset" Name="ReadParameter"/>
	FUNCTION VIRTUAL GLOBAL ReadParameter
		VAR_INPUT
			No 	: DINT;			//! <Variable Comment="Parameter number" Name="ReadParameter.No"/>
		END_VAR
		VAR_OUTPUT
			Value 	: DINT;
		END_VAR;
				//! <Function Comment="Read the actual encoder position from the drive&#13;&#10;for DrivePosControl and _LMCSigControl only." Name="ReadActPosition"/>
	FUNCTION VIRTUAL GLOBAL ReadActPosition
		VAR_OUTPUT
			BinPos 	: DINT;			//! <Variable Comment="actual position in external units" Name="ReadActPosition.BinPos"/>
		END_VAR;
				//! <Function Comment="This methode is called at the beginig of each realtime cycle by the _LMCAxis object. DrivePosControl and _LMCSigControl use this interface to get all information from the hardware class _DriveAxis" Name="ReadPDO"/>
	FUNCTION VIRTUAL GLOBAL ReadPDO;
				//! <Function Comment="function to quit a hardware error" Name="QuitHWError"/>
	FUNCTION VIRTUAL GLOBAL QuitHWError;
				//! <Function Comment="Check whether the hardware is ready for switch on." Name="IsReadyToSwitchOn"/>
	FUNCTION VIRTUAL GLOBAL IsReadyToSwitchOn
		VAR_OUTPUT
			IsReady 	: DINT;
		END_VAR;
				//! <Function Comment="This method reads the Hardware Diagnosis data from the connected DriveAxis object and returns a pointer to the hardeware diagnosis structure.&#13;&#10;The pointer is casted as pointer to DINT." Name="ReadHWDiagnosisDriveAxis"/>
	FUNCTION VIRTUAL GLOBAL ReadHWDiagnosisDriveAxis
		VAR_OUTPUT
			pHWDiagnosis 	: ^DINT;
		END_VAR;
	
	FUNCTION VIRTUAL GLOBAL ReceiveSafetyRequest
		VAR_INPUT
			SafetyParam 	: t_e_LMCCONTROLLER_SAFETY_PARAM;
			pPara1 	: ^DINT;
			pPara2 	: ^DINT;
			pPara3 	: ^DINT;
			pPara4 	: ^DINT;
			Mode 	: DINT;
		END_VAR
		VAR_OUTPUT
			RSRRetState 	: DINT;
		END_VAR;
	
	FUNCTION VIRTUAL GLOBAL SendSafetyRequest
		VAR_INPUT
			SafetyParam 	: t_e_LMCCONTROLLER_SAFETY_PARAM;
			ParamValue 	: DINT;
			ParamMode 	: DINT;
		END_VAR
		VAR_OUTPUT
			SSRRetState 	: DINT;
		END_VAR;
	
	FUNCTION CalcPos
		VAR_INPUT
			IntPos 	: DINT;
		END_VAR;
	
	FUNCTION CalcVelocity
		VAR_INPUT
			IntVel 	: DINT;
		END_VAR;
	
	FUNCTION ControlLMCAxis
		VAR_INPUT
			ActPos 	: DINT;
			IntPos 	: DINT;
		END_VAR;
	
	FUNCTION ControlLMCAxisOptHwClass
		VAR_INPUT
			ActPos 	: DINT;
			IntPos 	: DINT;
		END_VAR;
	
	FUNCTION SetClientsIntern
		VAR_INPUT
			No 	: DINT;
			Value 	: DINT;
			PowerOn 	: DINT;
		END_VAR
		VAR_OUTPUT
			State 	: DINT;
		END_VAR;
	
	FUNCTION CalcContouringDistance
		VAR_INPUT
			IntPos 	: DINT;
		END_VAR;
	
	FUNCTION AWL MulDiv64
		VAR_INPUT
			input 	: DINT;
			multiply 	: DINT;
			divisor 	: DINT;
			ErrorInfo 	: ^iprStates;
		END_VAR
		VAR_OUTPUT
			Result 	: DINT;
		END_VAR;
	
	FUNCTION CalcPosLREAL
		VAR_INPUT
			IntPos 	: LREAL;
		END_VAR;
	
	FUNCTION CalcVelocityLREAL
		VAR_INPUT
			IntVel 	: LREAL;
		END_VAR;
	
	FUNCTION ControlLMCAxisOptHwClassLREAL
		VAR_INPUT
			ActPos 	: DINT;
			fIntPos 	: LREAL;
			fSetSpeed 	: LREAL;
		END_VAR;
	
	FUNCTION ControlLMCAxisLREAL
		VAR_INPUT
			ActPos 	: DINT;
			fIntPos 	: LREAL;
			fSetSpeed 	: LREAL;
		END_VAR;
  //Tables:
	FUNCTION @STD
		VAR_OUTPUT
			ret_code	: CONFSTATES;
		END_VAR;
	FUNCTION GLOBAL TAB @CT_;
END_CLASS;

//}}LSL_DECLARATION


FUNCTION GLOBAL TAB DrivePosControlSafety::@CT_
0$UINT,
2#0100000000000000$UINT, //TY_DRIVEPOSCONTROLSAFETY
1$UINT, 4$UINT, (SIZEOF(::DrivePosControlSafety))$UINT, 
4$UINT, 13$UINT, 0$UINT, 
TO_UDINT(2807648805), "DrivePosControlSafety", //Class
TO_UDINT(1198357413), "Controller", 1$UINT, 46$UINT, //Baseclass
//Servers:
(::DrivePosControlSafety.XW.pMeth)$UINT, _CH_SVR$UINT, 2#0000000000000000$UINT, TO_UDINT(3333685748), "XW", 
(::DrivePosControlSafety.XWMax.pMeth)$UINT, _CH_SVR$UINT, 2#0000000000000000$UINT, TO_UDINT(1812725021), "XWMax", 
(::DrivePosControlSafety.SetPosOut.pMeth)$UINT, _CH_SVR$UINT, 2#0000000000000000$UINT, TO_UDINT(3299408146), "SetPosOut", 
(::DrivePosControlSafety.SetVelOut.pMeth)$UINT, _CH_SVR$UINT, 2#0000000000000000$UINT, TO_UDINT(1346061671), "SetVelOut", 
//Clients:
(::DrivePosControlSafety.DriveAxis.pCh)$UINT, _CH_CLT_CMD$UINT, 2#0000000000000000$UINT, TO_UDINT(2080180789), "DriveAxis", 
(::DrivePosControlSafety.SetConf.pCh)$UINT, _CH_CLT_DATA$UINT, 2#0000000000000000$UINT, TO_UDINT(511010176), "SetConf", 
(::DrivePosControlSafety.Draglimit.pCh)$UINT, _CH_CLT_DATA$UINT, 2#0000000000000000$UINT, TO_UDINT(3434425290), "Draglimit", 
(::DrivePosControlSafety.PosOffset.pCh)$UINT, _CH_CLT_DATA$UINT, 2#0000000000000000$UINT, TO_UDINT(1860950598), "PosOffset", 
(::DrivePosControlSafety.Online.pCh)$UINT, _CH_CLT_DATA$UINT, 2#0000000000000000$UINT, TO_UDINT(1858763116), "Online", 
(::DrivePosControlSafety.Enable.pCh)$UINT, _CH_CLT_DATA$UINT, 2#0000000000000000$UINT, TO_UDINT(56102836), "Enable", 
(::DrivePosControlSafety.SetSpeed.pCh)$UINT, _CH_CLT_DATA$UINT, 2#0000000000000000$UINT, TO_UDINT(33026088), "SetSpeed", 
(::DrivePosControlSafety.SetPos.pCh)$UINT, _CH_CLT_DATA$UINT, 2#0000000000000000$UINT, TO_UDINT(110881026), "SetPos", 
(::DrivePosControlSafety.HWError.pCh)$UINT, _CH_CLT_DATA$UINT, 2#0000000000000000$UINT, TO_UDINT(2544391667), "HWError", 
(::DrivePosControlSafety.HWErrorQuit.pCh)$UINT, _CH_CLT_DATA$UINT, 2#0000000000000000$UINT, TO_UDINT(2200854325), "HWErrorQuit", 
(::DrivePosControlSafety.DriveEnabled.pCh)$UINT, _CH_CLT_DATA$UINT, 2#0000000000000000$UINT, TO_UDINT(2552786170), "DriveEnabled", 
(::DrivePosControlSafety.StateWord.pCh)$UINT, _CH_CLT_DATA$UINT, 2#0000000000000000$UINT, TO_UDINT(1307193485), "StateWord", 
(::DrivePosControlSafety.ActXW.pCh)$UINT, _CH_CLT_DATA$UINT, 2#0000000000000000$UINT, TO_UDINT(3335054416), "ActXW", 
END_FUNCTION


#define USER_CNT_DrivePosControlSafety 19

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	IF Controller::Signal_Input.pMeth THEN
		ret_code	:= C_OK;
	ELSE
		ret_code	:= C_OUTOF_NEAR;
		RETURN;
	END_IF;
	XW.pMeth			:= StoreMethod( #M_RD_DIRECT(), #M_WR_DIRECT() );
	IF XW.pMeth THEN
		ret_code	:= C_OK;
	ELSE
		ret_code	:= C_OUTOF_NEAR;
		RETURN;
	END_IF;
	XWMax.pMeth			:= StoreMethod( #M_RD_DIRECT(), #M_WR_DIRECT() );
	IF XWMax.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, 155000 characters]
999C2A35169968201C4A562AA97EE8943B049BDB