//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
#include "..\..\Class\MDD2000MngBase\MDD2000MngBase.h"

(*!
<Class
	Name               = "MDD2000_SafetyErrorInfo"
	Revision           = "1.0"
	GUID               = "{7D241F6D-555E-4A5A-9C07-0834EC98B3AD}"
	RealtimeTask       = "false"
	CyclicTask         = "false"
	BackgroundTask     = "false"
	Sigmatek           = "true"
	OSInterface        = "false"
	HighPriority       = "false"
	Automatic          = "false"
	UpdateMode         = "Prescan"
	IconPath           = ".\Class\MDD2000_Mng\MDD2000SafetyDrive.ico"
	SharedCommandTable = "true"
	Objectsize         = "(874,120)"
	Comment            = "Class to read out safety diagnosis info from a MDD2000 drive.">
	<Channels>
		<Server Name="CallPosition_SC1" GUID="{BA4776C5-9883-47CE-869A-852E9CEF2F3E}" Visualized="true" Initialize="false" WriteProtected="true" Retentive="false" Comment="Shows the error call position of the current error of the safety controller 1 of the drive."/>
		<Server Name="CallPosition_SC2" GUID="{BE072789-5A1A-45B0-A1B8-B514054C0181}" Visualized="true" Initialize="false" WriteProtected="true" Retentive="false" Comment="Shows the error call position of the current error of the safety controller 2 of the drive."/>
		<Server Name="FileId_SC1" GUID="{60F7AD27-71B3-4ECB-8CA6-E435987FB5E7}" Visualized="true" Initialize="false" WriteProtected="true" Retentive="false" Comment="Shows the File ID of the current error of the safety controller 1 of the drive."/>
		<Server Name="FileId_SC2" GUID="{AA9B33B3-BA35-4000-9B13-237B3743FA82}" Visualized="true" Initialize="false" WriteProtected="true" Retentive="false" Comment="Shows the File ID of the current error of the safety controller 2 of the drive."/>
		<Server Name="QuitSafetyError" GUID="{172FD2BD-2DF6-423D-8EB6-A9C846C31574}" Visualized="true" Initialize="false" WriteProtected="false" Retentive="false" Comment="Call Write Method of server quit an safety error."/>
		<Server Name="SafetyErrorCode_SC1" GUID="{2BD24BEF-3D0D-435B-8960-2E9355D40077}" Visualized="true" Initialize="false" WriteProtected="true" Retentive="false" Comment="Shows the current error code of the safety controller 1 of the drive."/>
		<Server Name="SafetyErrorCode_SC2" GUID="{10473832-D95E-41B2-B764-6E344FE5C478}" Visualized="true" Initialize="false" WriteProtected="true" Retentive="false" Comment="Shows the current error code of the safety controller 2 of the drive."/>
		<Server Name="SafetyErrorInformation1_SC1" GUID="{5B1D4F1B-B030-4329-AC5E-F2A72789AEE7}" Visualized="true" Initialize="false" WriteProtected="true" Retentive="false" Comment="Shows the current error information 1 of the safety controller 1 of the drive."/>
		<Server Name="SafetyErrorInformation1_SC2" GUID="{AC1E8AF5-E631-4F79-8DE2-29A21B8E1990}" Visualized="true" Initialize="false" WriteProtected="true" Retentive="false" Comment="Shows the current error information 1 of the safety controller 2 of the drive."/>
		<Server Name="SafetyErrorInformation2_SC1" GUID="{3EE0B426-74B0-4F9B-B142-F10DDC383470}" Visualized="true" Initialize="false" WriteProtected="true" Retentive="false" Comment="Shows the current error information 2 of the safety controller 1 of the drive."/>
		<Server Name="SafetyErrorInformation2_SC2" GUID="{F1088860-0FD3-4D5D-93BF-1469C107CFEE}" Visualized="true" Initialize="false" WriteProtected="true" Retentive="false" Comment="Shows the current error information 2 of the safety controller 2 of the drive."/>
		<Server Name="SafetyErrorInformation3_SC1" GUID="{836789B5-D067-4DFF-BA0C-87CF798767D8}" Visualized="true" Initialize="false" WriteProtected="true" Retentive="false" Comment="Shows the current error information 3 of the safety controller 1 of the drive."/>
		<Server Name="SafetyErrorInformation3_SC2" GUID="{A300EF26-3601-4426-A34A-8EAE7F177CB0}" Visualized="true" Initialize="false" WriteProtected="true" Retentive="false" Comment="Shows the current error information 3 of the safety controller 2 of the drive."/>
		<Client Name="FwDatetr" Required="true" Internal="true"/>
		<Client Name="FwNumString" Required="true" Internal="true"/>
	</Channels>
	<Separators>
		<Servers>
			<SepChn Position="0"/>
			<SepChn Position="7"/>
			<SepChn Position="14"/>
		</Servers>
	</Separators>
	<Dependencies>
		<Files>
			<File Path=".\Class\MDD2000MngBase\MDD2000MngBase.h" Include="true"/>
		</Files>
	</Dependencies>
	<RevDoku>
		<Owner Company="Sigmatek" Author="LanSte"/>
		<Dokumentation Revision="1.0" Date="28.08.2023" Author="LanSte" Company="Sigmatek" Description="First library version."/>
	</RevDoku>
	<Network Name="MDD2000_SafetyErrorInfo">
		<!-- List of Components in this network -->
		<Components>
			<Object
				Name       = "_base"
				GUID       = "{4FD7D69B-3B4C-43BF-A24A-2D31A49F2664}"
				Class      = "_DriveSafetyIFParaBase"
				Position   = "(218,120)"
				Visualized = "true"
				Remotely   = "true">
				<Channels>
					<Server Name="ErrorQuit"/>
					<Server Name="State"/>
					<Client Name="DriveIF"/>
					<Client Name="ErrorCode"/>
					<Client Name="UpdateCyTime" Value="0"/>
				</Channels>
			</Object>
			<Object
				Name       = "FwDatetr"
				GUID       = "{FD885A54-6D50-4FB9-95FC-C9D100B5387A}"
				Class      = "String"
				Position   = "(210,540)"
				Visualized = "true"
				Remotely   = "true">
				<Channels>
					<Server Name="Data"/>
					<Client Name="SingleRealloc" Value="1"/>
				</Channels>
			</Object>
			<Object
				Name       = "FwNumString"
				GUID       = "{B4E15D05-D24A-4A50-B8E0-F4D5B4A8CB43}"
				Class      = "String"
				Position   = "(210,390)"
				Visualized = "true"
				Remotely   = "true">
				<Channels>
					<Server Name="Data"/>
					<Client Name="SingleRealloc" Value="1"/>
				</Channels>
			</Object>
		</Components>
		<Comments>
		</Comments>
		<!-- List of Connections in this network -->
		<Connections>
			<Connection Source="this.State" Destination="_base.State" Vertices="(740,210),(568,210),"/>
			<Connection Source="this.ErrorQuit" Destination="_base.ErrorQuit" Vertices="(740,270),(568,270),"/>
			<Connection Source="_base.DriveIF" Destination="this.DriveIF" Vertices="(218,210),(38,210),"/>
			<Connection Source="_base.ErrorCode" Destination="this.ErrorCode" Vertices="(218,270),(38,270),"/>
			<Connection Source="this.FwNumString" Destination="FwNumString.Data"/>
			<Connection Source="this.FwDatetr" Destination="FwDatetr.Data"/>
		</Connections>
		<!-- Headerfiles -->
		<Options>
		</Options>
	</Network>
</Class>
*)
#pragma using _DriveSafetyIFParaBase

MDD2000_SafetyErrorInfo : CLASS
: _DriveSafetyIFParaBase
  //Servers:
	SafetyErrorCode_SC1 	: SvrCh_UDINT;
	SafetyErrorInformation1_SC1 	: SvrCh_DINT;
	SafetyErrorInformation2_SC1 	: SvrCh_DINT;
	SafetyErrorInformation3_SC1 	: SvrCh_DINT;
	FileId_SC1 	: SvrCh_UDINT;
	CallPosition_SC1 	: SvrCh_UDINT;
	SafetyErrorCode_SC2 	: SvrCh_UDINT;
	SafetyErrorInformation1_SC2 	: SvrCh_DINT;
	SafetyErrorInformation2_SC2 	: SvrCh_DINT;
	SafetyErrorInformation3_SC2 	: SvrCh_DINT;
	FileId_SC2 	: SvrCh_UDINT;
	CallPosition_SC2 	: SvrCh_UDINT;
	QuitSafetyError 	: SvrCh_DINT;
  //Clients:
	FwNumString 	: CltChCmd_String;
	FwDatetr 	: CltChCmd_String;
  //Variables:
		SafetyErrorCode_SC1_Raw 	: HDINT;
		SafetyErrorCode_SC2_Raw 	: HDINT;
  //Functions:
	
	FUNCTION VIRTUAL GLOBAL Init;
	
	FUNCTION VIRTUAL GLOBAL RefreshPara
		VAR_INPUT
			hParaIndex 	: HINT;
			hsParaSubIndex 	: HSINT;
			bRW 	: DINT;
			bsDataInfo 	: BSINT;
			pValue 	: ^DINT;
		END_VAR;
	
	FUNCTION VIRTUAL SafetyError
		VAR_INPUT
			StateInfo 	: DINT;
		END_VAR;
	
	FUNCTION VIRTUAL SafetyChanged
		VAR_INPUT
			StateInfo 	: DINT;
		END_VAR;
	
	FUNCTION VIRTUAL GLOBAL QuitSafetyError::Write
		VAR_INPUT
			input (EAX) 	: DINT;
		END_VAR
		VAR_OUTPUT
			result (EAX) 	: DINT;
		END_VAR;
  //Tables:
	FUNCTION @STD
		VAR_OUTPUT
			ret_code	: CONFSTATES;
		END_VAR;
	FUNCTION GLOBAL TAB @CT_;
END_CLASS;

#pragma using String


//}}LSL_DECLARATION


FUNCTION GLOBAL TAB MDD2000_SafetyErrorInfo::@CT_
0$UINT,
2#0100000000000000$UINT, //TY_MDD2000_SAFETYERRORINFO
1$UINT, 0$UINT, (SIZEOF(::MDD2000_SafetyErrorInfo))$UINT, 
13$UINT, 2$UINT, 0$UINT, 
TO_UDINT(3116930091), "MDD2000_SafetyErrorInfo", //Class
TO_UDINT(1914213293), "_DriveSafetyIFParaBase", 1$UINT, 0$UINT, //Baseclass
//Servers:
(::MDD2000_SafetyErrorInfo.SafetyErrorCode_SC1.pMeth)$UINT, _CH_SVR$UINT, 2#0000000000000000$UINT, TO_UDINT(1419143638), "SafetyErrorCode_SC1", 
(::MDD2000_SafetyErrorInfo.SafetyErrorInformation1_SC1.pMeth)$UINT, _CH_SVR$UINT, 2#0000000000000000$UINT, TO_UDINT(18463158), "SafetyErrorInformation1_SC1", 
(::MDD2000_SafetyErrorInfo.SafetyErrorInformation2_SC1.pMeth)$UINT, _CH_SVR$UINT, 2#0000000000000000$UINT, TO_UDINT(1186579302), "SafetyErrorInformation2_SC1", 
(::MDD2000_SafetyErrorInfo.SafetyErrorInformation3_SC1.pMeth)$UINT, _CH_SVR$UINT, 2#0000000000000000$UINT, TO_UDINT(2077878998), "SafetyErrorInformation3_SC1", 
(::MDD2000_SafetyErrorInfo.FileId_SC1.pMeth)$UINT, _CH_SVR$UINT, 2#0000000000000000$UINT, TO_UDINT(2552500605), "FileId_SC1", 
(::MDD2000_SafetyErrorInfo.CallPosition_SC1.pMeth)$UINT, _CH_SVR$UINT, 2#0000000000000000$UINT, TO_UDINT(3817068688), "CallPosition_SC1", 
(::MDD2000_SafetyErrorInfo.SafetyErrorCode_SC2.pMeth)$UINT, _CH_SVR$UINT, 2#0000000000000000$UINT, TO_UDINT(3449763948), "SafetyErrorCode_SC2", 
(::MDD2000_SafetyErrorInfo.SafetyErrorInformation1_SC2.pMeth)$UINT, _CH_SVR$UINT, 2#0000000000000000$UINT, TO_UDINT(2551244812), "SafetyErrorInformation1_SC2", 
(::MDD2000_SafetyErrorInfo.SafetyErrorInformation2_SC2.pMeth)$UINT, _CH_SVR$UINT, 2#0000000000000000$UINT, TO_UDINT(3752891100), "SafetyErrorInformation2_SC2", 
(::MDD2000_SafetyErrorInfo.SafetyErrorInformation3_SC2.pMeth)$UINT, _CH_SVR$UINT, 2#0000000000000000$UINT, TO_UDINT(3805330284), "SafetyErrorInformation3_SC2", 
(::MDD2000_SafetyErrorInfo.FileId_SC2.pMeth)$UINT, _CH_SVR$UINT, 2#0000000000000000$UINT, TO_UDINT(19742919), "FileId_SC2", 
(::MDD2000_SafetyErrorInfo.CallPosition_SC2.pMeth)$UINT, _CH_SVR$UINT, 2#0000000000000000$UINT, TO_UDINT(2055899434), "CallPosition_SC2", 
(::MDD2000_SafetyErrorInfo.QuitSafetyError.pMeth)$UINT, _CH_SVR$UINT, 2#0000000000000000$UINT, TO_UDINT(2317164293), "QuitSafetyError", 
//Clients:
(::MDD2000_SafetyErrorInfo.FwNumString.pCh)$UINT, _CH_CLT_OBJ$UINT, 2#0000000000000010$UINT, TO_UDINT(4286323315), "FwNumString", TO_UDINT(1850111279), "String", 1$UINT, 11$UINT, 
(::MDD2000_SafetyErrorInfo.FwDatetr.pCh)$UINT, _CH_CLT_OBJ$UINT, 2#0000000000000010$UINT, TO_UDINT(4101277167), "FwDatetr", TO_UDINT(1850111279), "String", 1$UINT, 11$UINT, 
END_FUNCTION


#define USER_CNT_MDD2000_SafetyErrorInfo 19

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

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

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

	_memcpy((#vmt.CmdTable)$^USINT, _DriveSafetyIFParaBase::State.pMeth, nCmdSize);
	vmt.CmdTable.nCmds		:= nSTDCMD + USER_CNT_MDD2000_SafetyErrorInfo;
	vmt.CmdTable.Init		:= #Init();
#pragma warning (disable : 74)
	vmt.UserFcts[2]		:= #RefreshPara();

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

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

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

	IF _DriveSafetyIFParaBase::State.pMeth THEN
		ret_code	:= C_OK;
	ELSE
		ret_code	:= C_OUTOF_NEAR;
		RETURN;
	END_IF;
	QuitSafetyError.pMeth			:= StoreMethod( #M_RD_DIRECT(), #QuitSafetyError::Write() );
	IF QuitSafetyError.pMeth THEN
		ret_code	:= C_OK;
	ELSE
		ret_code	:= C_OUTOF_NEAR;
		RETURN;
	END_IF;

END_FUNCTION

//{{LSL_IMPLEMENTATION


FUNCTION VIRTUAL GLOBAL MDD2000_SafetyErrorInfo::Init

   // call base class
  _DriveSafetyIFParaBase::Init();

  if _firstscan then
    if (IsAxisConnected() = TRUE) then
      AddParaObjects(dIndex:=MDD2000MNG_PARAIDX_MNGSAFEERRINFO, pThis:=this);// add the object in the list of the axis
    end_if;
  end_if;
  
END_FUNCTION


FUNCTION VIRTUAL GLOBAL MDD2000_SafetyErrorInfo::RefreshPara
	VAR_INPUT
		hParaIndex 	: HINT;
		hsParaSubIndex 	: HSINT;
		bRW 	: DINT;
		bsDataInfo 	: BSINT;
		pValue 	: ^DINT;
	END_VAR
  
  case hParaIndex of
  
    //*****************************************************************************
    MDD2000_PID_SAFETY_ERROR:
  
      // check the parameter number
      case hsParaSubIndex of
        
        MDD2000_SPID_SAFETY_ERROR_SC1_CODE:
        
          // SafetyErrorCode_SCx:
          // Error Code            Bit  0 ... 11
          // Error Quit Category   Bit 12 ... 13    0 Standard, 1 quit required, 2 not quitable (1,2 not used in first MDD2000 Safety FW Release) 
          // Project Specific Flag Bit 14           (Safety Config Error)
          // Direct Error Flag     Bit 15
          // File ID               Bit 16 ... 23
          // Call Position         Bit 24 ... 31    for each seperate position in the file, from which the error code ist set, the call position is incremneted by 1 (Starting at 0)
           
          SafetyErrorCode_SC1_Raw := pValue^$UDINT;
          SafetyErrorCode_SC1     := SafetyErrorCode_SC1_Raw AND 0xFFF;
          FileId_SC1              := (SafetyErrorCode_SC1_Raw shr 16) AND 0xFF;
          CallPosition_SC1        := (SafetyErrorCode_SC1_Raw shr 24) AND 0xFF;
           
        MDD2000_SPID_SAFETY_ERROR_SC1_INFO1:
        
          SafetyErrorInformation1_SC1 := pValue^;
          
        MDD2000_SPID_SAFETY_ERROR_SC1_INFO2:
        
          SafetyErrorInformation2_SC1 := pValue^;
          
        MDD2000_SPID_SAFETY_ERROR_SC1_INFO3:
        
          SafetyErrorInformation3_SC1 := pValue^;
          
        MDD2000_SPID_SAFETY_ERROR_SC2_CODE:
        
          // See Comment MDD2000_SPID_SAFETY_ERROR_SC1_CODE:
        
          SafetyErrorCode_SC2_Raw := pValue^$UDINT;
          SafetyErrorCode_SC2     := SafetyErrorCode_SC2_Raw AND 0xFFF;
          FileId_SC2              := (SafetyErrorCode_SC2_Raw shr 16) AND 0xFF;
          CallPosition_SC2        := (SafetyErrorCode_SC2_Raw shr 24) AND 0xFF;
          
        MDD2000_SPID_SAFETY_ERROR_SC2_INFO1:
          
          SafetyErrorInformation1_SC2 := pValue^;
        
        MDD2000_SPID_SAFETY_ERROR_SC2_INFO2:
        
          SafetyErrorInformation2_SC2 := pValue^;
          
        MDD2000_SPID_SAFETY_ERROR_SC2_INFO3:
          
          SafetyErrorInformation3_SC2 := pValue^;
          
      end_case;
      
    MDD2000_PID_SAFETY_COMMANDS:
    
      // check the parameter number
      case hsParaSubIndex of
      
        MDD2000_SPID_SAFETY_ERROR_QUIT:
        
          QuitSafetyError := pValue^;
          
      end_case;
      
  end_case;


END_FUNCTION

#pragma warning(disable:73);
FUNCTION VIRTUAL MDD2000_SafetyErrorInfo::SafetyError
	VAR_INPUT
		StateInfo 	: DINT;
	END_VAR
#pragma warning(default:73);
  
  AddAsyncEntryDS402(ParaID:=MDD2000_PID_SAFETY_ERROR, ParaSubID:=MDD2000_SPID_SAFETY_ERROR_SC1_CODE,  ParaRdWr:=0, ParaSize:=MDD2000MNG_DATASIZE_4BYTE, pParaValue:=NIL, pThis:=this);
  AddAsyncEntryDS402(ParaID:=MDD2000_PID_SAFETY_ERROR, ParaSubID:=MDD2000_SPID_SAFETY_ERROR_SC1_INFO1, ParaRdWr:=0, ParaSize:=MDD2000MNG_DATASIZE_4BYTE, pParaValue:=NIL, pThis:=this);
  AddAsyncEntryDS402(ParaID:=MDD2000_PID_SAFETY_ERROR, ParaSubID:=MDD2000_SPID_SAFETY_ERROR_SC1_INFO2, ParaRdWr:=0, ParaSize:=MDD2000MNG_DATASIZE_4BYTE, pParaValue:=NIL, pThis:=this);
  AddAsyncEntryDS402(ParaID:=MDD2000_PID_SAFETY_ERROR, ParaSubID:=MDD2000_SPID_SAFETY_ERROR_SC1_INFO3, ParaRdWr:=0, ParaSize:=MDD2000MNG_DATASIZE_4BYTE, pParaValue:=NIL, pThis:=this);
  AddAsyncEntryDS402(ParaID:=MDD2000_PID_SAFETY_ERROR, ParaSubID:=MDD2000_SPID_SAFETY_ERROR_SC2_CODE,  ParaRdWr:=0, ParaSize:=MDD2000MNG_DATASIZE_4BYTE, pParaValue:=NIL, pThis:=this);
  AddAsyncEntryDS402(ParaID:=MDD2000_PID_SAFETY_ERROR, ParaSubID:=MDD2000_SPID_SAFETY_ERROR_SC2_INFO1, ParaRdWr:=0, ParaSize:=MDD2000MNG_DATASIZE_4BYTE, pParaValue:=NIL, pThis:=this);
  AddAsyncEntryDS402(ParaID:=MDD2000_PID_SAFETY_ERROR, ParaSubID:=MDD2000_SPID_SAFETY_ERROR_SC2_INFO2, ParaRdWr:=0, ParaSize:=MDD2000MNG_DATASIZE_4BYTE, pParaValue:=NIL, pThis:=this);
  AddAsyncEntryDS402(ParaID:=MDD2000_PID_SAFETY_ERROR, ParaSubID:=MDD2000_SPID_SAFETY_ERROR_SC2_INFO3, ParaRdWr:=0, ParaSize:=MDD2000MNG_DATASIZE_4BYTE, pParaValue:=NIL, pThis:=this);

END_FUNCTION


FUNCTION VIRTUAL MDD2000_SafetyErrorInfo::SafetyChanged
	VAR_INPUT
		StateInfo 	: DINT;
	END_VAR
  
  if StateInfo$MDD2000MngBase::t_e_MDD2000SafetyRunState <> MDD2000MngBase::t_e_MDD2000SafetyRunState::_ERROR then
    // Safety Error gone, Reset Servers
    SafetyErrorCode_SC1         := 0;
    SafetyErrorInformation1_SC1 := 0;
    SafetyErrorInformation2_SC1 := 0;
    SafetyErrorInformation3_SC1 := 0;
    FileId_SC1                  := 0;
    CallPosition_SC1            := 0;
    
    SafetyErrorCode_SC2         := 0;
    SafetyErrorInformation1_SC2 := 0;
    SafetyErrorInformation2_SC2 := 0;
    SafetyErrorInformation3_SC2 := 0;
    FileId_SC2                  := 0;
    CallPosition_SC2            := 0;
  end_if;

END_FUNCTION


FUNCTION VIRTUAL GLOBAL MDD2000_SafetyErrorInfo::QuitSafetyError::Write
	VAR_INPUT
		input (EAX) 	: DINT;
	END_VAR
	VAR_OUTPUT
		result (EAX) 	: DINT;
	END_VAR

	QuitSafetyError := input;
  if input then
    AddAsyncEntryDS402(ParaID:=MDD2000_PID_SAFETY_COMMANDS, ParaSubID:=MDD2000_SPID_SAFETY_ERROR_QUIT,  ParaRdWr:=1, ParaSize:=MDD2000MNG_DATASIZE_4BYTE, pParaValue:=#QuitSafetyError.dData, pThis:=this);
  end_if;

	result := QuitSafetyError;

END_FUNCTION
