FUNCTION_BLOCK ProgramNameToWords VAR_INPUT programName : STRING[255]; END_VAR VAR_OUTPUT Reg5 : WORD; Reg6 : WORD; Reg7 : WORD; Reg8 : WORD; Reg9 : WORD; Reg10 : WORD; Reg11 : WORD; Reg12 : WORD; Reg13 : WORD; Reg14 : WORD; regLen : INT; END_VAR VAR char : ARRAY[0..100] OF BYTE; PT : POINTER TO BYTE; i : INT; WordIndex: INT; ProgramWord: ARRAY[1..10] OF WORD; // Max string len is 10 * 2 = 20 char characterbyteindex: INT; ProgramWordIndex: INT; nameLen : INT; END_VAR ---------------------------------------------------------------------------------------- nameLen := LEN(programName); pt:=ADR(programName); FOR i:=0 TO nameLen-1 DO char[i]:=pt^; // Assign the value of the pointer to a Character pt:=pt+1; // pointer to next char END_FOR characterbyteindex := 0; regLen := (nameLen/2) + (nameLen MOD 2); FOR ProgramWordIndex:=1 TO regLen DO IF ( regLen = ProgramWordIndex ) AND ((nameLen MOD 2) > 0) THEN ProgramWord[ProgramWordIndex]:= BYTE_TO_WORD(char[characterbyteindex]); ELSE ProgramWord[ProgramWordIndex]:= SHL(BYTE_TO_WORD(char[characterbyteindex]),8)+BYTE_TO_WORD(char[characterbyteindex+1]); END_IF characterbyteindex:=characterbyteindex+2; END_FOR Reg5 := ProgramWord[1]; Reg6 := ProgramWord[2]; Reg7 := ProgramWord[3]; Reg8 := ProgramWord[4]; Reg9 := ProgramWord[5]; Reg10 := ProgramWord[6]; Reg11 := ProgramWord[7]; Reg12 := ProgramWord[8]; Reg13 := ProgramWord[9]; Reg14 := ProgramWord[10];