FB_CreateDir
The function block FB_CreateDir can be used to create new directories on the data storage device.
This function block is only suitable for logging in real-time to a limited extent. |
Inputs
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
Name | Type | Description |
---|---|---|
sNetId | T_AmsNetId | String containing the AMS network ID of the target device to which the ADS command is addressed (type: T_AmsNetId). |
sPathName | T_MaxString | Name of the new directory. When the function block is called, the only option is to create a new directory (type: T_MaxString). |
ePath | E_OpenPath | This input can be used to select a TwinCAT system path for the new directory on the target device (type: E_OpenPath). |
bExecute | BOOL | The function block is activated by a rising edge at this input. |
tTimeout | TIME | States the length of the timeout that may not be exceeded by execution of the ADS command. |
Outputs
VAR_OUTPUT
bBusy : BOOL;
bError : BOOL;
nErrId : UDINT;
END_VAR
Name | Type | Description |
---|---|---|
bBusy | BOOL | When the function block is activated, this output is set to TRUE and remains set until feedback is received. As long as bBusy is TRUE, no new command can be executed. |
bError | BOOL | If an error occurs during command execution, this output is set, once the bBusy output has been reset. |
nErrId | UDINT | Returns the ADS error code or the command-specific error code when the bError output is set. |
Command-specific error code | Possible cause |
---|---|
0x723 | Folder is already 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 directory 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 type |
PLC libraries to include (Category group) |
---|---|---|
TwinCAT v3.1.0 |
PC or CX (x86, x64, ARM) |
Tc2_System (System) |