PLC-Name / Steuerungsname

  • ThomasRohner

    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

    ThomasRohner - 2013-02-22

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


    PROGRAM ReadOutSysInfos
       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';
       constantReadSize:   UDINT:=4000;   
    IF init = FALSE THEN
       IF strBoardName = '' THEN
          fileHandle := SysFileOpen(fileName, AM_READADR(rte));   // Open original file
          IF (fileHandle = 16#FFFFFFFF) OR (fileHandle = 0) THEN
             strBoardName := 'invalid handle';
             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^;
                ptrToString := ptrToString + 1;
             rte := SysFileClose(fileHandle);            // Close original file
       init:= TRUE;

Log in to post a comment.