Module Templates

To interface with Piper a task requires two files. (1) A variable file where the Module and ModuleInferace is decalared and (2) the action file either in ST or C depending on the task which the interface is added. Once these two files are added, call the action in task cyclic code.

Variable

This file contains the Module Fub and ModuleInterface structure declarations.

(* PiperModuleTemplate.var *)
VAR
	ModuleInterface : Module_Interface_typ;
	Module : Piper_Module_Fub;
END_VAR

Interface

This file is where the module interfaces with Piper. States can be uncommented as needed.

ST

// In cyclic code of module
// Call PiperModuleInterface to interface with the rest of the machine
PiperModuleInterface;
// PiperModuleInterface.st
ACTION PiperModuleInterface:

	//Give this module a name so it is easier to debug
	ModuleInterface.ModuleName:=	'Name';

	//Add a module to the Piper
	Module.ModuleInterface:=	ADR(ModuleInterface);
	Module.Piper:= 	ADR(gMachine);
	Module();

	// Handle any machine states that this module needs to respond to
	CASE ModuleInterface.PiperState OF
//		MACH_ST_BOOTING:		
//		MACH_ST_CLEARING:
//		MACH_ST_STOPPED:
//		MACH_ST_STARTING:
//		MACH_ST_IDLE:
//		MACH_ST_SUSPENDED:
//		MACH_ST_EXECUTE:
//		MACH_ST_STOPPING:
//		MACH_ST_ABORTING:
//		MACH_ST_ABORTED:
//		MACH_ST_HOLDING:
//		MACH_ST_HELD:
//		MACH_ST_UNHOLDING:
//		MACH_ST_SUSPENDING:
//		MACH_ST_UNSUSPENDING:
//		MACH_ST_RESETTING:
//		MACH_ST_COMPLETING:
//		MACH_ST_COMPLETE:
		
		MACH_ST_BYPASSED:
		
		ELSE
			ModuleInterface.ModuleResponse:=	ModuleInterface.PiperState;
		
	END_CASE

END_ACTION

C

// In cyclic code of module
// Call PiperModuleInterface to interface with the rest of the machine
PiperModuleInterface();
// PiperModuleInterface.c
#include <string.h>

void PiperModuleInterface() {

	// Give this module a name so it is easier to debug
	strcpy(ModuleInterface.ModuleName, "Name");

	// Add a module to the Piper
	Module.ModuleInterface = &ModuleInterface;
	Module.Piper = &gMachine;
	Piper_Module_Fub(&Module);

	// Handle any machine states that this module needs to respond to
	switch (ModuleInterface.PiperState) {
		
		//case MACH_ST_BOOTING:
		//case MACH_ST_STOPPED:
		//case MACH_ST_RESETTING:
		//case MACH_ST_IDLE:
		//case MACH_ST_STARTING:
		//case MACH_ST_EXECUTE:
		//case MACH_ST_COMPLETING:
		//case MACH_ST_COMPLETE:
		//case MACH_ST_HOLDING:
		//case MACH_ST_HELD:
		//case MACH_ST_UNHOLDING:
		//case MACH_ST_SUSPENDING:
		//case MACH_ST_SUSPENDED:
		//case MACH_ST_UNSUSPENDING:
		//case MACH_ST_STOPPING:
		//case MACH_ST_ABORTING:
		//case MACH_ST_ABORTED:
		//case MACH_ST_CLEARING:

		case MACH_ST_BYPASSED: break;

		default: ModuleInterface.ModuleResponse = ModuleInterface.PiperState;
		
	} // switch(PiperState)
		
} // PiperModuleInterface()
Made by Loupe