Welcome to our new forum
All users of the legacy CODESYS Forums, please create a new account at account.codesys.com. But make sure to use the same E-Mail address as in the old Forum. Then your posts will be matched. Close

SysDir

libi
2022-02-16
2022-02-16
  • libi - 2022-02-16

    Hello,
    I would like to use sysDir with sysdiropen and sysdirread but it does not work if someone can help me here the code (I made it from a codesys 2.3 and try to pass it on codesys 3.5 ):

    PROGRAM POU
    VAR
    RUNIT :BOOL;
    tempo :TON;
    commande :STRING(255);
    folder :POINTER TO BYTE ;
    ENDREADFOLDER:UDINT;
    NAMEELEMENTFIND: STRING(255);
    INFOELEMENTFIND:DirInfo;
    FOLDERRECEXISTING:BOOL;
    END_VAR

    IF visuelems.CURRENTVISU = 'Visu_Default' THEN
    IF GVL_Keylist_RT.xKey_Return THEN
    IF RUNIT=TRUE THEN
    RUNIT:=FALSE;
    ELSE
    RUNIT:=TRUE;
    END_IF
    END_IF
    IF GVL_Keylist_RT.xF2 THEN
    folder:=SysDirOpen(szDir:= '/home/data' , szDirEntry:= '' , diMaxDirEntry:= 0, pDirInfo:= 0,pResult:= 0);
    END_IF
    IF GVL_Keylist_RT.xF3 THEN
    sysdircreate('/home/data/REC');
    END_IF
    IF GVL_Keylist_RT.xF4 THEN
    visuelems.CURRENTVISU := 'Visualisation';
    END_IF
    IF LANCER=TRUE THEN
    REPEAT
    ENDREADFOLDER := SysDirRead(hDir:= folder, szDirEntry:= FOLDERRECEXISTING,
    diMaxDirEntry:=1024 , pDirInfo:=ADR(INFOELEMENTFIND));
    IF INFOELEMENTFIND = '/REC' AND INFOELEMENTFIND.diDirectory = 2 (16#0 = fichier 16#2= Dossier ) THEN
    ( Dossier existant )
    FOLDERRECEXISTING := TRUE;
    END_IF
    UNTIL
    ENDREADFOLDER=0
    END_REPEAT
    IF FOLDERRECEXISTING = FALSE THEN
    SysDirCreate('/data/REC');
    END_IF
    END_IF
    END_IF

    IF visuelems.CURRENTVISU = 'Visualization' THEN
    IF GVL_Keylist_RT.xF4 THEN
    visuelems.CURRENTVISU := 'Visu_Default';
    END_IF
    END_IF

     
  • Lo5tNet - 2022-02-16

    There are some issues in how you are calling SysDirOpen and SysDirRead. I would suggest, for starters, looking at the File Utilities example on forge or to look more at the help files.
    File Utilites example can be found here: https://forge.codesys.com/prj/codesys-example/file-utilities/home/Home/ or you can search the forge.

     

Log in to post a comment.