Download this file
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
FUNCTION_BLOCK retryRead VAR_INPUT xReadDone:BOOL; sData:STRING(255); sTrailer:STRING; szSize:UDINT; END_VAR VAR_OUTPUT xRead:BOOL:=true; sOutput:STRING; xOutputReady:BOOL; VAR sTemp:STRING(255); sTemp2:STRING(255); sConcat:STRING(255); iTrailerPos:INT; iStep:INT:=0; size: INT; // Remove Header and trailer, return payload // FIND if trigger was Succesful IF xReadDone THEN IF szSize > 0 THEN sConcat:= Standard.DELETE(STR:= sConcat, LEN:=4 , POS:= 1); // remove TRG P or F from output END_IF IF len(STR:=sConcat) > 0 THEN iTrailerPos := FIND(STR1:= sConcat, STR2:=sTrailer); IF iTrailerPos > 0 THEN sOutput := LEFT(STR:= sConcat,size:=iTrailerPos-1); sConcat := ''; xOutputReady := TRUE; END_IF END_IF ELSE xOutputReady := FALSE; END_IF &