[r31]: / branches / PackMLState / Display_Escape_PLC / Plc Logic / Application / Function Blocks / MessageQueue / svnobj  Maximize  Restore  History

Download this file

40 lines (37 with data), 3.9 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
FUNCTION_BLOCK MessageQueue
VAR_IN_OUT
	Client 				: Client;
END_VAR
VAR
	NewMessage			: BOOL;
	DuplicationTimeoutTimer		: TON;
	DuplicationTimeout			: BOOL;
	TimeoutTimer		: TON;
	Timeout				: BOOL;
	InQueue				: INT;
	OutIndex			: INT;
	InIndex				: INT;
	Commands 			: ARRAY[0..15] OF CommandType;
	Values 				: ARRAY[0..15] OF STRING;
IF InQueue > 0 THEN
	
	IF TimeoutTimer.Q THEN
		IF NOT Client.bReadyFromPLC THEN
			Client.sCommandFromPLC:= Values[OutIndex];
			Client.iCommandFromPLC:= Commands[OutIndex];
			Client.bReadyFromPLC:= TRUE;
			
			IF OutIndex >= 15 THEN
				OutIndex := 0;		
			ELSE		
				OutIndex := OutIndex + 1;		
			END_IF			
			InQueue := InQueue - 1;
			Timeout := FALSE;
		END_IF
	ELSE
			Timeout := TRUE;
	END_IF
ELSE
		Timeout := TRUE;	
END_IF&
TimeoutTimer(IN := Timeout,PT := T#5S);
DuplicationTimeoutTimer(IN := Timeout,PT:=T#30S);