Inhalte

Dependency Injection: Declaration in Main

Table of Contents

Introduction

In the code listing of the main program, only the declaration is shown, but that is sufficient to understand dependency injection.

Main Program

Program Main
PROGRAM MAIN
VAR
	stopperSensor	:SimpleDigitalSensor(maskSensorIsOccupied := TRUE);
	jamSensor		:SimpleDigitalSensor(maskSensorIsOccupied := TRUE);
	
	stopperCylinder	:Cylinder0Inputs1Output(
		maskMoveToHomePosition 		:= FALSE,
		delayUntilPositionIsReached := T#500MS
	);
	
	transportInterfaceToNextSection		:SimpleTransportInterface;
	transportInterfaceToPreviousSection	:SimpleTransportInterface;
	conveyor							:Conveyor(followUpTime := T#10S);
	
	{region "stopper"}
		{region "sending workflow"}
			stateWaitUntilCarrierIsArrived		:StateWaitUntilCarrierIsArrived(
				conveyorInterface		:= conveyor,
				receiverInterface		:= transportInterfaceToNextSection,
				nextState				:= 0
			);
			
			stateStopNextCarrier					:StateStopNextCarrier(
				conveyorInterface		:= conveyor,
				stopperCylinder			:= stopperCylinder,
				nextState				:= stateWaitUntilCarrierIsArrived
			);
											 
			stateWaitUntilCarrierIsGone			:StateWaitUntilCarrierIsGone(
				conveyorInterface		:= conveyor,
				stopperSensor			:= stopperSensor,
				nextState				:= stateStopNextCarrier
			);
							
			stateReleaseCarrier						:StateReleaseCarrier(
				conveyorInterface		:= conveyor,
				stopperCylinder			:= stopperCylinder,
				nextState				:= stateWaitUntilCarrierIsGone
			);
							
			stateStartConveyor						:StateStartConveyor(
				conveyorInterface		:= conveyor,
				nextState				:= stateReleaseCarrier
			);
			
			stateWaitUntilReceiverIsReady		:StateWaitUntilReceiverIsReady(
				receiverInterface		:= transportInterfaceToNextSection,
				nextState				:= stateStartConveyor
			);
			
			stateWaitForCarrierToSend			:StateWaitForCarrierToSend(
				stopperSensor					:= stopperSensor,
				nextState						:= stateWaitUntilReceiverIsReady
			);
		{endregion}
				  
		{region "receiving workflow"}
			receivingWorkflow		:ReceivingWorkflow(
				cylinder					:= stopperCylinder,
				jamSensor					:= jamSensor,
				transportInterface   		:= transportInterfaceToPreviousSection,
				nextState					:= receivingWorkflow
			);
		{endregion}
		
		stopper							:SimpleStopperUnit(
			firstStateReceivingWorkflow	:= receivingWorkflow,		
			lastStateReceivingWorkflow	:= receivingWorkflow,
			firstStateSendingWorkflow	:= stateWaitForCarrierToSend,
			lastStateSendingWorkflow	:= stateWaitUntilCarrierIsArrived
		);
	{endregion}	

END_VAR