Inhalte

Abstract Factories: Test it

Table of Contents

Global Variable List

We use a global variable list to guaranty the access for two tasks. It would be possible to do it via task program parameters, too. But the example is about abstract factories and not about system design.

Global Variable List GVL_HmiAlarm
GVL_HmiAlarm
{attribute 'qualified_only'}
VAR_GLOBAL
	globalAlarmList :OpcUaHmiAlarmList();
	distributor :AlarmMessageDistributor();
	
	{attribute 'hide'}
	serviceLinker :AlarmServiceLinker(
		functionUnitName := 'HmiAlarm-ServiceLinker',
		messageNumber := 0,
		messageInfo := '',
		alarmService := distributor
	);
END_VAR

HMI & Main Task

Program HmiMain
PROGRAM HmiMain
VAR
	isInitDone :BOOL := FALSE;
END_VAR
IF (NOT isInitDone) THEN
	init();
END_IF
GVL_HmiAlarm.globalAlarmList.run();
GVL_HmiAlarm.distributor.run();
ACTION init
GVL_HmiAlarm.distributor.subscribe(GVL_HmiAlarm.globalAlarmList);
isInitDone := TRUE;
Program MAIN
PROGRAM MAIN
VAR		 
	info :InfoMessage(
		functionUnitName := 'MainPrg',
		messageNumber := 100,
		messageInfo := 'Hello World'
	);
	
	trowInfo :BOOL;
	clearInfo :BOOL;
END_VAR
IF (trowInfo) THEN
	info.throw();
	trowInfo := FALSE;
END_IF

IF (clearInfo) THEN
	info.clear();
	clearInfo := FALSE;
END_IF