FB_CreateDir

FB_CreateDir 1:

This functionblock creates new directories on the data medium.

VAR_INPUT

VAR_INPUT
    sNetId      : T_AmsNetId;          
    sPathName   : T_MaxString;
    ePath       : E_OpenPath := PATH_GENERIC; (* Default: generic file path*)
 bExecute       : BOOL;     
    tTimeout    : TIME := DEFAULT_ADS_TIMEOUT;
END_VAR

sNetId    : Is a string containing the AMS network identifier of the target device to which the ADS command is directed.

sPathName : The name of the new directory as string. The function block can create only one new directory per call, so only the last component of sPathname can name a new directory.

ePath : The variable of this type selects one of the TwinCAT system paths on the target device to create a directory.

bExecute    : The ADS command is triggered by a rising edge at this input.

tTimeout    : States the time before the function is cancelled.

VAR_OUTPUT

VAR_OUTPUT
    bBusy       : BOOL;
    bError      : BOOL;
    nErrId      : UDINT;
END_VAR

bBusy:    This output remains TRUE until the block has executed a command, but at the longest for the duration supplied to the ‘tTimeout’ input. While bBusy = TRUE, no new command will be accepted at the inputs.

bError:    This output is switched to TRUE if an error occurs during the execution of a command. The command-specific error code is contained in ‘nErrId’.

nErrId:    Contains the command-specific ADS error code of the most recently executed command. 

 

Function specific ADS error code

Possible reason

0x70C

Folder is allready existing or invalid sPathName or ePath parameter.

 

Example in ST:

By a rising edge at bCreate a new directory in the main directory 'C:\'named : 'PRJDATA' is created. By a rising edge at bRemove a directory with the same name can be deleted.

At bBootFolder = TRUE a driectory in the  ..\TwinCAT\Boot directory can be created or deleted.

PROGRAM MAIN
VAR
    sFolderName : STRING := 'PRJDATA'; (* folder name *)
    bBootFolder : BOOL;

    ePath : E_OpenPath; (* folders root path *)
    sPathName : STRING;

    fbCreateDir : FB_CreateDir;
    bCreate : BOOL;
    bCreate_Busy : BOOL;
    bCreate_Error : BOOL;
    nCreate_ErrID : UDINT;

    fbRemoveDir : FB_RemoveDir;
    bRemove : BOOL;
    bRemove_Busy : BOOL;
    bRemove_Error : BOOL;
    nRemove_ErrID : UDINT;
END_VAR
ePath := SEL( bBootFolder, PATH_GENERIC, PATH_BOOTPATH );
sPathName := SEL( bBootFolder, CONCAT('C:\', sFolderName), sFolderName );

IF bCreate THEN
    bCreate := FALSE;
    fbCreateDir( bExecute := FALSE );
    fbCreateDir(sNetId:= '',
        sPathName:= sPathName,
        ePath:= ePath,
        bExecute:= TRUE,
        tTimeout:= DEFAULT_ADS_TIMEOUT,
        bBusy=>bCreate_Busy, bError=>bCreate_Error, nErrId=>nCreate_ErrID );
ELSE
    fbCreateDir( bExecute := FALSE, bBusy=>bCreate_Busy, bError=>bCreate_Error, nErrId=>nCreate_ErrID );
END_IF



IF bRemove THEN
    bRemove := FALSE;
    fbRemoveDir( bExecute := FALSE );
    fbRemoveDir(sNetId:= '',
        sPathName:= sPathName,
        ePath:= ePath,
        bExecute:= TRUE,
        tTimeout:= DEFAULT_ADS_TIMEOUT,
        bBusy=>bRemove_Busy, bError=>bRemove_Error, nErrId=>nRemove_ErrID );
ELSE
    fbRemoveDir( bExecute := FALSE, bBusy=>bRemove_Busy, bError=>bRemove_Error, nErrId=>nRemove_ErrID );
END_IF

 

Requirements

Development Environment

Target System

PLC Libraries to include

TwinCAT v2.10.0 Build > 1310 (CE image v2.17d or higher)

PC or CX (x86, ARM)

TcSystem.Lib