PLC-Name / Steuerungsname

2013-02-19
2013-02-22
  • ThomasRohner - 2013-02-19

    Hallo Forum,

    gibt es eine Funktion/Bibliothek um den Steuerungsnamen aus CODESYSCONTROL.CFG auszulesen?
    Oder muss ich das von Hand und mit SysFile selbst bewerkstelligen?

    Does a function/library exist to read out the nodename-value from CODESYSCONTROL.CFG?
    Or do I have to read manually with library 'SysFile'?

     
  • TimvH

    TimvH - 2013-02-22

    Good question. Please share your solution if you have found out how to do this.
    You could use the CmpApp library to get information about the application, but as far as I have seen this doesn't give information about the device name.

     
  • ThomasRohner - 2013-02-22

    my solution, quick and possibly "dirty" -> is there a better solution ?

    e.g.

    PROGRAM ReadOutSysInfos
    VAR
       init: BOOL;
       strTemp: STRING(255);
       strBoardName: STRING(30);
       strBoardName2: STRING(30);
       wstrBoardName2: WSTRING(30);
       fileHandle:    SysTypes.RTS_IEC_HANDLE;                  // File handle number
       fileName:      STRING[63] := '/flashdisk/CodesysV3/CoDeSysControl.cfg';      // Path and file name
       rte:          RTS_IEC_RESULT;                  // Error code according runtime error list
       ptrToString: POINTER TO BYTE;
       ptrToString1: POINTER TO BYTE;
       ptrToString1a: POINTER TO STRING(255);
       strCmp1: STRING(12):= '[SysTarget]';
       readSize: UDINT := constantReadSize;
       bytesRead: UDINT := 0;
       udi :UDINT;
       readLog:      ARRAY [0..constantReadSize] OF BYTE;// Array to read old logs
       str_offset: INT;
       str_offset2: INT;
       iLen: INT;
       strComponent : STRING:='SysTarget';
       strKeyValue: STRING:='NodeName';
    END_VAR
    VAR CONSTANT
       constantReadSize:   UDINT:=4000;   
    END_VAR
    IF init = FALSE THEN
       IF strBoardName = '' THEN
          fileHandle := SysFileOpen(fileName, AM_READ,  ADR(rte));   // Open original file
          IF (fileHandle = 16#FFFFFFFF) OR (fileHandle = 0) THEN
             strBoardName := 'invalid handle';
          ELSE
             strBoardName := 'not found';
             ptrToString := ADR(readLog);
             ptrToString1 := ADR(strCmp1);
             bytesRead := SysFileRead(fileHandle, ptrToString, readSize, ADR(rte));   // Read the original file
             FOR udi:=1 TO (bytesRead - 250) DO
                ptrToString1a := ptrToString;
                str_offset := Standard.FIND(ptrToString1a^, strCmp1);
                IF str_offset > 0 THEN
                   ptrToString1a := ptrToString1a + str_offset;
                   str_offset := Standard.FIND(ptrToString1a^, 'NodeName=') + 8;
                   IF str_offset > 8 THEN
                      ptrToString1a := ptrToString1a + str_offset + 1;
                      ptrToString1 := ptrToString1a + Standard.FIND(ptrToString1a^, '$R') - 2;
                      ptrToString1^ := 0;
                      strBoardName := ptrToString1a^;
                      EXIT;
                   END_IF
                END_IF
                ptrToString := ptrToString + 1;
             END_FOR
             rte := SysFileClose(fileHandle);            // Close original file
          END_IF
       END_IF
       init:= TRUE;
    END_IF
    
     

Log in to post a comment.