//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"
#include "..\..\Source\BusIFVVDrive.h"

(*!
<Class
	Name               = "BusIFVVMDD2000"
	Revision           = "1.1"
	GUID               = "{ABF80968-C08F-4C98-9210-665F7CED230A}"
	RealtimeTask       = "false"
	CyclicTask         = "false"
	BackgroundTask     = "false"
	Sigmatek           = "true"
	OSInterface        = "false"
	HighPriority       = "false"
	Automatic          = "false"
	UpdateMode         = "Prescan"
	SharedCommandTable = "true"
	Objectsize         = "(750,1560)">
	<Channels>
		<Server Name="CallCommandFSoE" GUID="{EFD93981-94B1-48F9-B938-955CB9B6C7B9}" Visualized="false" Initialize="false" WriteProtected="true" Retentive="false"/>
		<Server Name="ClassState" GUID="{F8D92B85-80CA-4716-B1A8-3914A51E4FC8}" Class="MDD2000VVBase" Visualized="false" Initialize="false" WriteProtected="true" Retentive="false"/>
		<Server Name="DriveBusIF" GUID="{115AF36D-59CC-4B51-BFAD-9EAB93A89351}" Visualized="false" Initialize="false" WriteProtected="true" Retentive="false"/>
		<Server Name="Input1" GUID="{ABC5970D-A34B-4AEC-A06B-BA07E09BABA4}" Visualized="true" Initialize="false" WriteProtected="true" Retentive="false" Comment="State of digital input 1 of drive.&#13;&#10; 0 .. off&#13;&#10; 1 .. on&#13;&#10;-1 .. deactivated"/>
		<Server Name="Input2" GUID="{BB87B246-838D-4CFB-8495-E468D287AD4A}" Visualized="true" Initialize="false" WriteProtected="true" Retentive="false" Comment="State of digital input 2 of drive.&#13;&#10; 0 .. off&#13;&#10; 1 .. on&#13;&#10;-1 .. deactivated"/>
		<Server Name="Input3" GUID="{C0627C11-6223-463A-B005-3E710292710E}" Visualized="true" Initialize="false" WriteProtected="true" Retentive="false" Comment="State of digital input 3 of drive.&#13;&#10; 0 .. off&#13;&#10; 1 .. on&#13;&#10;-1 .. deactivated"/>
		<Server Name="Input4" GUID="{9665C0C4-75AF-4C72-9989-135DFEC03726}" Visualized="true" Initialize="false" WriteProtected="true" Retentive="false" Comment="State of digital input 4 of drive.&#13;&#10; 0 .. off&#13;&#10; 1 .. on&#13;&#10;-1 .. deactivated"/>
		<Server Name="Input5" GUID="{17528EB4-8C04-46E5-AA71-9CFBFA168B9D}" Visualized="true" Initialize="false" WriteProtected="true" Retentive="false" Comment="State of digital input 5 of drive.&#13;&#10; 0 .. off&#13;&#10; 1 .. on&#13;&#10;-1 .. deactivated"/>
		<Server Name="Input6" GUID="{F87137D0-88F1-4ECC-9904-61F5D6E59567}" Visualized="true" Initialize="false" WriteProtected="true" Retentive="false" Comment="State of digital input 6 of drive.&#13;&#10; 0 .. off&#13;&#10; 1 .. on&#13;&#10;-1 .. deactivated"/>
		<Server Name="SafetyRunState" GUID="{E87E4C70-903E-4D07-9290-40FB791758AA}" Visualized="true" Initialize="false" WriteProtected="true" Retentive="false"/>
		<Server Name="State" Visualized="false">
		</Server>
		<Client Name="DriveDeviceID" Required="true" Internal="false"/>
		<Client Name="MDD2000VVBase1" Required="true" Internal="true"/>
		<Client Name="TimeMultiplier" Required="true" Internal="false" Comment="multiplier of varan time set as init value."/>
	</Channels>
	<Dependencies>
		<Files>
			<File Path=".\Class\MDD2000MngBase\MDD2000MngBase.h" Include="true"/>
			<File Path=".\Source\BusIFVVDrive.h" Include="true"/>
		</Files>
	</Dependencies>
	<RevDoku>
		<Owner Company="Sigmatek" Author="LanSte"/>
		<Dokumentation Revision="1.1" Date="13.12.2024" Author="LanSte" Company="Sigmatek" Description="Removed GetRequiredWaitTime.  Instead the wait time will be fetched from HWControl and apply to all modules."/>
		<Dokumentation Revision="1.0" Date="28.08.2023" Author="LanSte" Company="Sigmatek" Description="First library version."/>
	</RevDoku>
	<Network Name="BusIFVVMDD2000">
		<!-- List of Components in this network -->
		<Components>
			<Object
				Name       = "_base"
				GUID       = "{A4E7BF67-9336-4E30-9935-B918FB5BA02C}"
				Class      = "BusInterfaceVARAN"
				Position   = "(218,120)"
				Visualized = "false">
				<Channels>
					<Server Name="CallCommand"/>
					<Server Name="ConnectCounter"/>
					<Server Name="DeviceAddress"/>
					<Server Name="DeviceID"/>
					<Server Name="DiagControl"/>
					<Server Name="FaultCounter"/>
					<Server Name="HardwareVersion"/>
					<Server Name="Online"/>
					<Server Name="ProtocolVersion"/>
					<Server Name="Release"/>
					<Server Name="RetryCounter"/>
					<Server Name="RXLost"/>
					<Server Name="SerialNo"/>
					<Server Name="State"/>
					<Server Name="TXLost"/>
					<Server Name="ValidateSerNo"/>
					<Server Name="VendorID"/>
					<Client Name="Required"/>
					<Client Name="SerNoValidation"/>
					<Client Name="ToOSKernel"/>
					<Client Name="Transparent" Value="0"/>
					<Client Name="UserAction"/>
					<Client Name="VaranIn"/>
				</Channels>
			</Object>
			<Object
				Name           = "MDD2000VVBase1"
				GUID           = "{25AD8185-6769-496F-9FED-F9A5D9FF4A1B}"
				Class          = "MDD2000VVBase"
				Position       = "(210,1380)"
				Visualized     = "true"
				Remotely       = "true"
				BackgroundTime = "100 ms">
				<Channels>
					<Server Name="CallCommandFSoE"/>
					<Server Name="ClassState"/>
					<Server Name="DriveBusIF"/>
					<Server Name="Input1"/>
					<Server Name="Input2"/>
					<Server Name="Input3"/>
					<Server Name="Input4"/>
					<Server Name="Input5"/>
					<Server Name="Input6"/>
					<Server Name="SafetyRunState"/>
					<Client Name="DeviceID"/>
					<Client Name="TimeMultiplier" Value="1"/>
					<Client Name="ToBusInterface"/>
					<Client Name="ToMultiTask"/>
					<Client Name="toStdLib"/>
					<Client Name="toVaranIn"/>
				</Channels>
			</Object>
		</Components>
		<Comments>
		</Comments>
		<!-- List of Connections in this network -->
		<Connections>
			<Connection Source="this.State" Destination="_base.State" Vertices="(1118,210),(718,210),"/>
			<Connection Source="this.Online" Destination="_base.Online" Vertices="(1118,270),(718,270),"/>
			<Connection Source="this.Release" Destination="_base.Release" Vertices="(1118,330),(718,330),"/>
			<Connection Source="this.DeviceAddress" Destination="_base.DeviceAddress" Vertices="(1118,450),(718,450),"/>
			<Connection Source="this.VendorID" Destination="_base.VendorID" Vertices="(1118,510),(718,510),"/>
			<Connection Source="this.DeviceID" Destination="_base.DeviceID" Vertices="(1118,570),(718,570),"/>
			<Connection Source="this.SerialNo" Destination="_base.SerialNo" Vertices="(1118,630),(718,630),"/>
			<Connection Source="this.RetryCounter" Destination="_base.RetryCounter" Vertices="(1118,690),(718,690),"/>
			<Connection Source="this.ValidateSerNo" Destination="_base.ValidateSerNo" Vertices="(1118,750),(718,750),"/>
			<Connection Source="this.DiagControl" Destination="_base.DiagControl" Vertices="(1118,810),(718,810),"/>
			<Connection Source="this.ConnectCounter" Destination="_base.ConnectCounter" Vertices="(1118,870),(718,870),"/>
			<Connection Source="this.FaultCounter" Destination="_base.FaultCounter" Vertices="(1118,930),(718,930),"/>
			<Connection Source="this.RXLost" Destination="_base.RXLost" Vertices="(1118,990),(718,990),"/>
			<Connection Source="this.TXLost" Destination="_base.TXLost" Vertices="(1118,1050),(718,1050),"/>
			<Connection Source="this.MDD2000VVBase1" Destination="MDD2000VVBase1.ClassState"/>
			<Connection Source="MDD2000VVBase1.ToBusInterface" Destination="_base.CallCommand" Vertices="(210,1470),(150,1470),(150,1320),(780,1320),(780,1170),(718,1170),"/>
			<Connection Source="MDD2000VVBase1.toVaranIn" Destination="this.VaranIn" Vertices="(210,1530),(120,1530),(120,240),(38,210),"/>
			<Connection Source="_base.VaranIn" Destination="this.VaranIn" Vertices="(218,210),(38,210),"/>
			<Connection Source="_base.Required" Destination="this.Required" Vertices="(218,270),(38,270),"/>
			<Connection Source="_base.UserAction" Destination="this.UserAction" Vertices="(218,330),(38,330),"/>
			<Connection Source="_base.SerNoValidation" Destination="this.SerNoValidation" Vertices="(218,390),(38,390),"/>
			<Connection Source="_base.Transparent" Destination="this.Transparent" Vertices="(218,450),(38,450),"/>
			<Connection Source="MDD2000VVBase1.DeviceID" Destination="this.DriveDeviceID" Vertices="(210,1590),(90,1590),(90,1170),(38,1170),"/>
			<Connection Source="MDD2000VVBase1.TimeMultiplier" Destination="this.TimeMultiplier" Vertices="(210,1650),(60,1650),(60,1230),(38,1230),"/>
			<Connection Source="this.ClassState" Destination="MDD2000VVBase1.ClassState" Vertices="(1118,1170),(990,1170),(990,1470),(946,1470),"/>
			<Connection Source="this.ProtocolVersion" Destination="_base.ProtocolVersion" Vertices="(1118,1110),(718,1110),"/>
			<Connection Source="this.DriveBusIF" Destination="MDD2000VVBase1.DriveBusIF" Vertices="(1118,1230),(1020,1230),(1020,1530),(946,1530),"/>
			<Connection Source="this.Input1" Destination="MDD2000VVBase1.Input1" Vertices="(1118,1290),(1050,1290),(1050,1590),(946,1590),"/>
			<Connection Source="this.Input2" Destination="MDD2000VVBase1.Input2" Vertices="(1118,1350),(1080,1350),(1080,1650),(946,1650),"/>
			<Connection Source="this.Input3" Destination="MDD2000VVBase1.Input3" Vertices="(1118,1410),(1110,1410),(1110,1710),(946,1710),"/>
			<Connection Source="this.Input4" Destination="MDD2000VVBase1.Input4" Vertices="(1118,1470),(946,1770),"/>
			<Connection Source="this.Input5" Destination="MDD2000VVBase1.Input5" Vertices="(1118,1530),(946,1830),"/>
			<Connection Source="this.Input6" Destination="MDD2000VVBase1.Input6" Vertices="(1118,1590),(946,1890),"/>
			<Connection Source="this.CallCommandFSoE" Destination="MDD2000VVBase1.CallCommandFSoE" Vertices="(1118,1710),(946,2010),"/>
			<Connection Source="this.HardwareVersion" Destination="_base.HardwareVersion" Vertices="(1118,390),(718,390),"/>
			<Connection Source="this.SafetyRunState" Destination="MDD2000VVBase1.SafetyRunState" Vertices="(1118,1650),(946,1950),"/>
		</Connections>
		<!-- Headerfiles -->
		<Options>
		</Options>
	</Network>
</Class>
*)
#pragma using BusInterfaceVARAN

BusIFVVMDD2000 : CLASS
: BusInterfaceVARAN
  //Servers:
	ClassState 	: SvrChCmd_t_e_VaranErrors;
	DriveBusIF 	: SvrChCmd_DINT;
	Input1 	: SvrCh_DINT;
	Input2 	: SvrCh_DINT;
	Input3 	: SvrCh_DINT;
	Input4 	: SvrCh_DINT;
	Input5 	: SvrCh_DINT;
	Input6 	: SvrCh_DINT;
	SafetyRunState 	: SvrCh_t_e_MDD2000SafetyRunState_PTofCls_MDD2000MngBase;
	CallCommandFSoE 	: SvrChCmd_DINT;
  //Clients:
	DriveDeviceID 	: CltCh_UDINT;
	TimeMultiplier 	: CltCh_UDINT;
	MDD2000VVBase1 	: CltChCmd_MDD2000VVBase;
  //Variables:
  //Functions:
				//! <Function Comment="Init for Varan Client" Name="Init"/>
	FUNCTION VIRTUAL GLOBAL Init;
	
	FUNCTION VIRTUAL GLOBAL GetDeviceID
		VAR_OUTPUT
			output 	: UDINT;
		END_VAR;
	
	FUNCTION VIRTUAL GLOBAL State::NewInst
		VAR_INPUT
			pPara 	: ^CmdStruct;
			pResult 	: ^results;
		END_VAR
		VAR_OUTPUT
			ret_code 	: iprStates;
		END_VAR;
	
	FUNCTION VIRTUAL GLOBAL ClassState::Read
		VAR_OUTPUT
			output (EAX) 	: t_e_VaranErrors;
		END_VAR;
	
	FUNCTION VIRTUAL GLOBAL DriveBusIF::Read
		VAR_OUTPUT
			output (EAX) 	: DINT;
		END_VAR;
	
	FUNCTION VIRTUAL GLOBAL Input1::Read
		VAR_OUTPUT
			output (EAX) 	: DINT;
		END_VAR;
	
	FUNCTION VIRTUAL GLOBAL Input2::Read
		VAR_OUTPUT
			output (EAX) 	: DINT;
		END_VAR;
	
	FUNCTION VIRTUAL GLOBAL Input3::Read
		VAR_OUTPUT
			output (EAX) 	: DINT;
		END_VAR;
	
	FUNCTION VIRTUAL GLOBAL Input4::Read
		VAR_OUTPUT
			output (EAX) 	: DINT;
		END_VAR;
	
	FUNCTION VIRTUAL GLOBAL Input5::Read
		VAR_OUTPUT
			output (EAX) 	: DINT;
		END_VAR;
	
	FUNCTION VIRTUAL GLOBAL Input6::Read
		VAR_OUTPUT
			output (EAX) 	: DINT;
		END_VAR;
	
	FUNCTION VIRTUAL GLOBAL SafetyRunState::Read
		VAR_OUTPUT
			output (EAX) 	: MDD2000MngBase::t_e_MDD2000SafetyRunState;
		END_VAR;
	
	FUNCTION VIRTUAL GLOBAL CallCommandFSoE::Read
		VAR_OUTPUT
			output (EAX) 	: DINT;
		END_VAR;
  //Tables:
	FUNCTION @STD
		VAR_OUTPUT
			ret_code	: CONFSTATES;
		END_VAR;
	FUNCTION GLOBAL TAB @CT_;
END_CLASS;

#pragma using MDD2000VVBase


//}}LSL_DECLARATION


FUNCTION GLOBAL TAB BusIFVVMDD2000::@CT_
0$UINT,
2#0100000000000000$UINT, //TY_BUSIFVVMDD2000
1$UINT, 1$UINT, (SIZEOF(::BusIFVVMDD2000))$UINT, 
10$UINT, 3$UINT, 0$UINT, 
TO_UDINT(423404954), "BusIFVVMDD2000", //Class
TO_UDINT(24783181), "BusInterfaceVARAN", 1$UINT, 75$UINT, //Baseclass
//Servers:
(::BusIFVVMDD2000.ClassState.pMeth)$UINT, _CH_SVR_OBJ$UINT, 2#0000000000000000$UINT, TO_UDINT(1096059024), "ClassState", 
(::BusIFVVMDD2000.DriveBusIF.pMeth)$UINT, _CH_CMD$UINT, 2#0000000000000000$UINT, TO_UDINT(253971569), "DriveBusIF", 
(::BusIFVVMDD2000.Input1.pMeth)$UINT, _CH_SVR$UINT, 2#0000000000000000$UINT, TO_UDINT(1344628668), "Input1", 
(::BusIFVVMDD2000.Input2.pMeth)$UINT, _CH_SVR$UINT, 2#0000000000000000$UINT, TO_UDINT(3375117830), "Input2", 
(::BusIFVVMDD2000.Input3.pMeth)$UINT, _CH_SVR$UINT, 2#0000000000000000$UINT, TO_UDINT(3190490768), "Input3", 
(::BusIFVVMDD2000.Input4.pMeth)$UINT, _CH_SVR$UINT, 2#0000000000000000$UINT, TO_UDINT(542085939), "Input4", 
(::BusIFVVMDD2000.Input5.pMeth)$UINT, _CH_SVR$UINT, 2#0000000000000000$UINT, TO_UDINT(1464378277), "Input5", 
(::BusIFVVMDD2000.Input6.pMeth)$UINT, _CH_SVR$UINT, 2#0000000000000000$UINT, TO_UDINT(3460428319), "Input6", 
(::BusIFVVMDD2000.SafetyRunState.pMeth)$UINT, _CH_SVR$UINT, 2#0000000000000000$UINT, TO_UDINT(1037834220), "SafetyRunState", 
(::BusIFVVMDD2000.CallCommandFSoE.pMeth)$UINT, _CH_CMD$UINT, 2#0000000000000000$UINT, TO_UDINT(2758564975), "CallCommandFSoE", 
//Clients:
(::BusIFVVMDD2000.DriveDeviceID.pCh)$UINT, _CH_CLT_DATA$UINT, 2#0000000000000110$UINT, TO_UDINT(3022020647), "DriveDeviceID", 
(::BusIFVVMDD2000.TimeMultiplier.pCh)$UINT, _CH_CLT_DATA$UINT, 2#0000000000000110$UINT, TO_UDINT(2421717411), "TimeMultiplier", 
(::BusIFVVMDD2000.MDD2000VVBase1.pCh)$UINT, _CH_CLT_OBJ$UINT, 2#0000000000000010$UINT, TO_UDINT(4089659920), "MDD2000VVBase1", TO_UDINT(1968777221), "MDD2000VVBase", 1$UINT, 1$UINT, 
END_FUNCTION


#define USER_CNT_BusIFVVMDD2000 73

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

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

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

	_memcpy((#vmt.CmdTable)$^USINT, Varan_Base::State.pMeth, nCmdSize);
	vmt.CmdTable.nCmds		:= nSTDCMD + USER_CNT_BusIFVVMDD2000;
	vmt.CmdTable.NewInstr		:= #State::NewInst();
	vmt.CmdTable.Init		:= #Init();
#pragma warning (disable : 74)
	vmt.UserFcts[43]		:= #GetDeviceID();

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

	IF Varan_Base::State.pMeth THEN
		ret_code	:= C_OK;
	ELSE
		ret_code	:= C_OUTOF_NEAR;
		RETURN;
	END_IF;
	_memcpy((#vmt.CmdTable)$^USINT, ClassState.pMeth, SIZEOF(CMDMETH));
	vmt.CmdTable.nCmds		:= nSTDCMD;
	vmt.CmdTable.Read		:= #ClassState::Read();
	ClassState.pMeth		:= StoreCmd (pCmd := #vmt.CmdTable, SHARED);

	IF ClassState.pMeth THEN
		ret_code	:= C_OK;
	ELSE
		ret_code	:= C_OUTOF_NEAR;
		RETURN;
	END_IF;
	_memcpy((#vmt.CmdTable)$^USINT, DriveBusIF.pMeth, SIZEOF(CMDMETH));
	vmt.CmdTable.nCmds		:= nSTDCMD;
	vmt.CmdTable.Read		:= #DriveBusIF::Read();
	DriveBusIF.pMeth		:= StoreCmd (pCmd := #vmt.CmdTable, SHARED);

	IF DriveBusIF.pMeth THEN
		ret_code	:= C_OK;
	ELSE
		ret_code	:= C_OUTOF_NEAR;
		RETURN;
	END_IF;
	Input1.pMeth			:= StoreMethod( #Input1::Read(), #M_NO_F() );
	IF Input1.pMeth THEN
		ret_code	:= C_OK;
	ELSE
		ret_code	:= C_OUTOF_NEAR;
		RETURN;
	END_IF;
	Input2.pMeth			:= StoreMethod( #Input2::Read(), #M_NO_F() );
	IF Input2.pMeth THEN
		ret_code	:= C_OK;
	ELSE
		ret_code	:= C_OUTOF_NEAR;
		RETURN;
	END_IF;
	Input3.pMeth			:= StoreMethod( #Input3::Read(), #M_NO_F() );
	IF Input3.pMeth THEN
		ret_code	:= C_OK;
	ELSE
		ret_code	:= C_OUTOF_NEAR;
		RETURN;
	END_IF;
	Input4.pMeth			:= StoreMethod( #Input4::Read(), #M_NO_F() );
	IF Input4.pMeth THEN
		ret_code	:= C_OK;
	ELSE
		ret_code	:= C_OUTOF_NEAR;
		RETURN;
	END_IF;
	Input5.pMeth			:= StoreMethod( #Input5::Read(), #M_NO_F() );
	IF Input5.pMeth THEN
		ret_code	:= C_OK;
	ELSE
		ret_code	:= C_OUTOF_NEAR;
		RETURN;
	END_IF;
	Input6.pMeth			:= StoreMethod( #Input6::Read(), #M_NO_F() );
	IF Input6.pMeth THEN
		ret_code	:= C_OK;
	ELSE
		ret_code	:= C_OUTOF_NEAR;
		RETURN;
	END_IF;
	SafetyRunState.pMeth			:= StoreMethod( #SafetyRunState::Read(), #M_NO_F() );
	IF SafetyRunState.pMeth THEN
		ret_code	:= C_OK;
	ELSE
		ret_code	:= C_OUTOF_NEAR;
		RETURN;
	END_IF;
	_memcpy((#vmt.CmdTable)$^USINT, CallCommandFSoE.pMeth, SIZEOF(CMDMETH));
	vmt.CmdTable.nCmds		:= nSTDCMD;
	vmt.CmdTable.Read		:= #CallCommandFSoE::Read();
	CallCommandFSoE.pMeth		:= StoreCmd (pCmd := #vmt.CmdTable, SHARED);

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

END_FUNCTION

//{{LSL_IMPLEMENTATION
FUNCTION VIRTUAL GLOBAL BusIFVVMDD2000::State::NewInst
	VAR_INPUT
		pPara 	: ^CmdStruct;
		pResult 	: ^results;
	END_VAR
	VAR_OUTPUT
		ret_code 	: iprStates;
	END_VAR
  VAR
    // local variables for the Requested HWTString
    pStr_HWTRequested         : ^CHAR;
    b_CallThisModule          : BOOL;
    us_HWTRequestedCurrIndex  : USINT;
  END_VAR

  pStr_HWTRequested         := NIL;
  us_HWTRequestedCurrIndex  := 0;
  b_CallThisModule          := TRUE;
  ret_code := ready;

  case pPara^.uiCmd of

//**********************************************************************************************************************************************************
    //*****************************************************************************
    //** COMMANDS FROM Safety Manager                                            **
    //*****************************************************************************
    CMD_SM_CMD_MIN_RANGE .. CMD_SM_CMD_MAX_RANGE:
      ret_code :=  MDD2000VVBase1.ClassState.NewInst(pPara:=pPara, pResult:=pResult);


//**********************************************************************************************************************************************************

    //*****************************************************************************
    //** COMMANDS FROM BusInterface                                              **
    //*****************************************************************************
    CMD_GET_HARDWARE_DIAGNOSIS:
      //initialize retcode
      ret_code := ERROR;
      pResult^.aData[0]$t_HWCGetHardwareDiagnosisOut.retcode := _HWC_RETVAL_ERROR;
      pStr_HWTRequested := pPara^.aPara[0]$t_HWCGetHardwareDiagnosisIn.pStr_HardewareTreeEntry;

      // Check HWT String
      if pStr_HWTRequested then

        us_HWTRequestedCurrIndex  := pPara^.aPara[0]$t_HWCGetHardwareDiagnosisIn.us_current_index;

        // Check for any Escape sequence
        if (pStr_HWTRequested + us_HWTRequestedCurrIndex)^ and HWT_ESCAPE_SEQU then

          // Check if current index + 1 is valid, pStr_HWTRequested^ + 1 for extra byte of length
          if (us_HWTRequestedCurrIndex + 1) <= (pStr_HWTRequested$^UINT^ + 1) then
            // Update Current index to next position = Place of SDIAS Module
            pPara^.aPara[0]$t_HWCGetHardwareDiagnosisIn.us_current_index   += 1;
            pPara^.aPara[0]$t_HWCGetHardwareDiagnosisIn.us_current_length  -= 1;

            if p_UserCalls.p_Callback then
              ret_code := p_UserCalls.p_Callback^.pSvrChCmd.NewInst(pPara,pResult); //Pass on command to connected extension module
            end_if;
          end_if;
        else
          //get safety number
          MDD2000VVBase1.ClassState.NewInst(pPara:=pPara, pResult:=pResult);
          ret_code := Varan_Base::State.NewInst(pPara, pResult);  // Pass on command to base
        end_if;
      end_if;


//**********************************************************************************************************************************************************
    CMD_GET_HARDWARE_TREE_ENTRY:
      pResult^.aData$t_HWCGetHardwareTreeEntryOut.retcode := _HWC_RETVAL_ERROR_CLASS_NOT_ONLINE;
      ret_code := ERROR;

      pStr_HWTRequested := pPara^.aPara[0]$t_HWCGetHardwareTreeEntryIn.pStr_LastHardewareTreeEntry;

      // Check HWT String
      if pStr_HWTRequested & p_ObjectPath then


        // Compare string content
        if _memcmp( ptr1 := pStr_HWTRequested + 2,
                       ptr2 := p_ObjectPath +1,
                       cntr := p_ObjectPath^) = 0 then


          //Check if last call was to Base itself, Compare string length
          if (pStr_HWTRequested$^USINT^ = p_ObjectPath^) then

            //If last call was to base itself, don't call it this time
            b_CallThisModule := FALSE;

            //Don't set this pointer to nil at drives (only neccessary for Sdias to begin with first module)
            //pPara^.aPara[0]$t_HWCGetHardwareTreeEntryIn.pStr_LastHardewareTreeEntry := NIL;

            if p_UserCalls.p_Callback then
              ret_code := p_UserCalls.p_Callback^.pSvrChCmd.NewInst(pPara,pResult); //Pass on command to extension module
            else
              pResult^.aData[0]$t_HWCGetHardwareTreeEntryOut.retcode := _HWC_RETVAL_OK_END_OF_LIST;
            end_if;

          elsif (pStr_HWTRequested$^USINT^ > p_ObjectPath^ + 1) then // Must be at least 2 Byte larger, ESCAPE Sequence + Place

            // Check escape sequence
            if ( (pStr_HWTRequested + (p_ObjectPath^) + 2 )^ AND HWT_ESCAPE_SEQU) then // First place after extension module Itself is escape sequence + 1 for addional length byte
              // Last Module must have been a Module behind an extension module

              //If last call was to base itself, don't call it this time
              b_CallThisModule := FALSE;

              // Update index
              pPara^.aPara[0]$t_HWCGetHardwareTreeEntryIn.us_current_index  := p_ObjectPath^ + 3; // Second place after BUSIF Itself is place + 1 for addional length byte
              pPara^.aPara[0]$t_HWCGetHardwareTreeEntryIn.us_current_length := pStr_HWTRequested^ - p_ObjectPath^ - 1;

              //If we have a extension module
              if p_UserCalls.p_Callback then
                ret_code := p_UserCalls.p_Callback^.pSvrChCmd.NewInst(pPara,pResult); //Pass on command to extension module
              else
                ret_code := READY;
                pResult^.aData[0]$t_HWCGetHardwareTreeEntryOut.retcode := _HWC_RETVAL_OK_END_OF_LIST;
              end_if;
            end_if;
          end_if;
        end_if;
      end_if;

      if b_CallThisModule then
        ret_code := Varan_Base::State.NewInst(pPara, pResult);  // Pass on command to base
      end_if;

    _BUSIF_VVDRIVE_ADD_MDD2000_MDP_ERROR:
      //forward command to Drivevvbase class
      ret_code :=  MDD2000VVBase1.ClassState.NewInst(pPara:=pPara, pResult:=pResult);

    MDD2000MNG_IF_SAFETYCONFIG_CHANGED:
      //forward command to Drivevvbase class
      ret_code :=  MDD2000VVBase1.ClassState.NewInst(pPara:=pPara, pResult:=pResult);
    
  else
    // unknown commands are forwarded to the base
    ret_code := BusInterfaceVARAN::NewInst(pPara, pResult);

  end_case;


//**********************************************************************************************************************************************************


END_FUNCTION


FUNCTION VIRTUAL GLOBAL BusIFVVMDD2000::GetDeviceID
	VAR_OUTPUT
		output 	: UDINT;
	END_VAR

  output := DriveDeviceID;

END_FUNCTION


FUNCTION VIRTUAL GLOBAL BusIFVVMDD2000::Init

  //first call baseclass
  BusInterfaceVARAN::Init();

END_FUNCTION


FUNCTION VIRTUAL GLOBAL BusIFVVMDD2000::ClassState::Read
	VAR_OUTPUT
		output (EAX) 	: t_e_VaranErrors;
	END_VAR

	ClassState := MDD2000VVBase1.ClassState.Read();
	output := ClassState;

END_FUNCTION


FUNCTION VIRTUAL GLOBAL BusIFVVMDD2000::DriveBusIF::Read
	VAR_OUTPUT
		output (EAX) 	: DINT;
	END_VAR

	DriveBusIF := MDD2000VVBase1.DriveBusIF.Read();
	output := DriveBusIF;

END_FUNCTION


FUNCTION VIRTUAL GLOBAL BusIFVVMDD2000::Input1::Read
	VAR_OUTPUT
		output (EAX) 	: DINT;
	END_VAR

	Input1 := MDD2000VVBase1.Input1.Read();
	output := Input1;

END_FUNCTION


FUNCTION VIRTUAL GLOBAL BusIFVVMDD2000::Input2::Read
	VAR_OUTPUT
		output (EAX) 	: DINT;
	END_VAR

	Input2 := MDD2000VVBase1.Input2.Read();
	output := Input2;

END_FUNCTION


FUNCTION VIRTUAL GLOBAL BusIFVVMDD2000::Input3::Read
	VAR_OUTPUT
		output (EAX) 	: DINT;
	END_VAR

	Input3 := MDD2000VVBase1.Input3.Read();
	output := Input3;

END_FUNCTION


FUNCTION VIRTUAL GLOBAL BusIFVVMDD2000::Input4::Read
	VAR_OUTPUT
		output (EAX) 	: DINT;
	END_VAR

	Input4 := MDD2000VVBase1.Input4.Read();
	output := Input4;

END_FUNCTION


FUNCTION VIRTUAL GLOBAL BusIFVVMDD2000::Input5::Read
	VAR_OUTPUT
		output (EAX) 	: DINT;
	END_VAR

	Input5 := MDD2000VVBase1.Input5.Read();
	output := Input5;

END_FUNCTION


FUNCTION VIRTUAL GLOBAL BusIFVVMDD2000::Input6::Read
	VAR_OUTPUT
		output (EAX) 	: DINT;
	END_VAR

	Input6 := MDD2000VVBase1.Input6.Read();
	output := Input6;

END_FUNCTION


FUNCTION VIRTUAL GLOBAL BusIFVVMDD2000::CallCommandFSoE::Read
	VAR_OUTPUT
		output (EAX) 	: DINT;
	END_VAR

	CallCommandFSoE := MDD2000VVBase1.CallCommandFSoE.Read();
	output := CallCommandFSoE;

END_FUNCTION


FUNCTION VIRTUAL GLOBAL BusIFVVMDD2000::SafetyRunState::Read
	VAR_OUTPUT
		output (EAX) 	: MDD2000MngBase::t_e_MDD2000SafetyRunState;
	END_VAR

	SafetyRunState := MDD2000VVBase1.SafetyRunState.Read();
	output := SafetyRunState;

END_FUNCTION
