Function Blocks ¶ Directory DirClose (FunctionBlock) DirCopy (FunctionBlock) DirCreate (FunctionBlock) DirList (FunctionBlock) DirOpen (FunctionBlock) DirRemove (FunctionBlock) DirRename (FunctionBlock) File Close (FunctionBlock) Copy (FunctionBlock) Delete (FunctionBlock) EOF (FunctionBlock) Flush (FunctionBlock) GetAttribute (FunctionBlock) GetPos (FunctionBlock) GetSize (FunctionBlock) GetTime (FunctionBlock) Open (FunctionBlock) Read (FunctionBlock) Rename (FunctionBlock) SetPos (FunctionBlock) Write (FunctionBlock)
Directory ¶ DirClose (FunctionBlock) DirCopy (FunctionBlock) DirCreate (FunctionBlock) DirList (FunctionBlock) DirOpen (FunctionBlock) DirRemove (FunctionBlock) DirRename (FunctionBlock)
DirClose (FB; Prefix fildcl) ¶ FUNCTION_BLOCK DirClose EXTENDS CBM.ETrig This function block closes the access on the specified directory. InOut: Scope Name Type Comment Input hDir CAA.HANDLE Directory handle Output eError ERROR Local library error ID (0: no error; 5101: time out)
DirCopy (FB; Prefix fildcp) ¶ FUNCTION_BLOCK DirCopy EXTENDS CBM.ETrig This function block copies the contents of the source directory to the destination directory Nonexisting destination path will be created. Depending of the parameters, all subdirectories and its content will be copied too, and existing files will be overwritten. NOTE: Empty direcories will be copied if xRecursive is TRUE. InOut: Scope Name Type Comment Input sDirNameDest CAA.FILENAME destination directory name sDirNameSource CAA.FILENAME source directory name xRecursive BOOL TRUE: all subdirectories and their contents are copied, FALSE: subdirectories are omitted xOverWrite BOOL TRUE: existing files are overwritten, FALSE: existing files are left untouched Output eError ERROR Local library error ID (0: no error; 5101: time out)
DirCreate (FB; Prefix fildcr) ¶ FUNCTION_BLOCK DirCreate EXTENDS CBM.ETrig This function block creates a sub-directory in the standard directory. If the sub-directory already exists, an error message is generated. There may be restrictions concerning the specification of the directory name, e.g. only capital letters allowed, for different targets. The function ”FILE. GetProperty ” shows these restrictions. InOut: Scope Name Type Comment Input sDirName CAA.FILENAME Name of the new directory, absolute or relative path specification xParent BOOL Create missing subdirectories; TRUE: missing sub-directories will be created automatically, FALSE: missing sub- directories will cause an error message Output eError ERROR Local library error ID (5104 - FILE_NOT_EXIST: Directory does not exist; 5105 - FILE_EXIST: Directory already exists )
DirList (FB; Prefix fildls) ¶ FUNCTION_BLOCK DirList EXTENDS CBM.ETrig This function reads directory entries. The function block needs a valid handle which identifies the directory as a transfer parameter. The information is written to structure ” deDirEntry ” of type ” FILE_DIR_ENTRY ”. If the function block cannot find any further entries the error message ” ERROR.NO_MORE_ENTRIES ” is generated and the entries in the structure ” deDirEntry ” are deleted. InOut: Scope Name Type Comment Input hDir CAA.HANDLE Directory handle Output eError ERROR Local library error ID (5106 - FILE_NO_MORE_ENTRIES: no further entries available) deDirEntry FILE_DIR_ENTRY Directory entry
Examples (GVL) ¶ Directory ¶ (* example of how to use the CAA_FILE-library - directory function blocks *) PROGRAM DIR_PRG VAR xDirInit : BOOL := FALSE ; uiDirState : UINT := 0 ; sDirNewName : CAA_FILENAME := './TestDirectory' ; sDirNextName : CAA_FILENAME := './NewDirectory' ; hDir : CAA_HANDLE ; deNewDirectory : FILE_DIR_ENTRY ; fildcr : FILE.DirCreate ; fildop : FILE.DirOpen ; fildcl : FILE.DirClose ; fildls : FILE.DirList ; fildrn : FILE.DirRename ; fildrm : FILE.DirRemove ; END_VAR IF NOT xDirInit THEN fildcr ( xExecute := FALSE ); fildcl ( xExecute := FALSE ); fildls ( xExecute := FALSE ); fildrm ( xExecute := FALSE ); xDirInit := TRUE ; uiDirState := 0 ; ELSE CASE uiDirState OF 0 : (* create a new directory *) fildcr.sDirName := sDirNewName ; fildcr.xParent := FALSE ; fildcr ( xExecute := TRUE ); IF fildcr.xDone THEN uiDirState := 1 ; END_IF IF fildcr.xError THEN (* error handling*) ; END_IF 1 : (* open directory *) fildop.sDirName := sDirNewName ; fildop ( xExecute := TRUE ); IF fildop.xDone THEN hDir := fildop.hDir ; uiDirState := 2 ; END_IF IF fildop.xError THEN (* error handling*) ; END_IF 2 : (* get directory property list *) fildls.hDir := hDir ; fildls ( xExecute := TRUE ); IF fildls.xDone THEN deNewDirectory.sEntry := fildls.deDirEntry.sEntry ; deNewDirectory.szSize := fildls.deDirEntry.szSize ; deNewDirectory.xDirectory := fildls.deDirEntry.xDirectory ; deNewDirectory.xExclusive := fildls.deDirEntry.xExclusive ; deNewDirectory.dtLastModification := fildls.deDirEntry.dtLastModification ; uiDirState := 3 ; END_IF IF fildop.xError THEN (* error handling*) ; END_IF 3 : (* close directory *) fildcl.hDir := hDir ; fildcl ( xExecute := TRUE ); IF fildcl.xDone THEN uiDirState := 4 ; END_IF IF fildcl.xError THEN (* error handling*) ; END_IF 4 : (* rename directory*) fildrn.sDirNameOld := sDirNewName ; fildrn.sDirNameNew := sDirNextName ; fildrn ( xExecute := TRUE ); IF fildrn.xDone THEN uiDirState := 5 ; END_IF IF fildrn.xError THEN (* error handling*) ; END_IF 5 : (* remove directory*) fildrm.sDirName := sDirNextName ; fildrm.udiTimeOut := 100000 ; (* 100ms TimeOut *) fildrm.xRecursive := FALSE ; fildrm ( xExecute := TRUE ); IF fildrm.xDone THEN uiDirState := 6 ; END_IF IF fildrm.xError THEN (* error handling*) ; END_IF 6 : (* end of example*) ; END_CASE END_IF File - Standard ¶ (* example of how to use the CAA_FILE-library - file standard function blocks *) PROGRAM FILE_STANDARD_PRG VAR xFileStdInit : BOOL := FALSE ; uiFileStdState : UINT := 0 ; sFileName : CAA_FILENAME := 'TestFile.txt' ; hFile : CAA_HANDLE ; sFileTestString : STRING := 'Hello caa library user' ; sFileString : STRING := '' ; szFileSize1 : CAA_SIZE := 0 ; szFileSize2 : CAA_SIZE := 0 ; filop : FILE.Open ; filwr : FILE.Write ; filrd : FILE.Read ; filcl : FILE.Close ; END_VAR IF NOT xFileStdInit THEN filop ( xExecute := FALSE ); filcl ( xExecute := FALSE ); filwr ( xExecute := FALSE ); filrd ( xExecute := FALSE ); xFileStdInit := TRUE ; uiFileStdState := 0 ; ELSE CASE uiFileStdState OF 0 : (* create a new file *) filop.sFileName := sFileName ; filop.eFileMode := FILE_MRDWR ; filop.xExclusive := TRUE ; filop ( xExecute := TRUE ); IF filop.xDone THEN hFile := filop.hFile ; uiFileStdState := 1 ; END_IF IF filop.xError THEN (* error handling*) ; END_IF 1 : (* write text in the file *) filwr.hFile := hFile ; filwr.pBuffer := ADR ( sFileTestString ); szFileSize1 := SIZEOF ( sFileTestString ); filwr.szSize := szFileSize1 ; filwr.udiTimeOut := 100000 ; (* 100ms Timeout *) filwr ( xExecute := TRUE ); IF filwr.xDone THEN uiFileStdState := 2 ; END_IF IF filwr.xError THEN (* error handling*) ; END_IF 2 : (* read file - TestFile.txt*) filrd.hFile := hFile ; filrd.udiTimeOut := 100000 ; (* 100ms Timeout *) filrd.pBuffer := ADR ( sFileString ); filrd.szBuffer := 255 ; filrd ( xExecute := TRUE ); IF filrd.xDone THEN szFileSize2 := filrd.szSize ; IF szFileSize2 = szFileSize1 THEN uiFileStdState := 3 ; ELSE (* error handling*) ; END_IF END_IF IF filrd.xError THEN (* error handling*) ; END_IF 3 : (* close file - TestFile.txt *) filcl.hFile := hFile ; filcl ( xExecute := TRUE ); IF filcl.xDone THEN uiFileStdState := 4 ; END_IF IF filcl.xError THEN (* error handling*) ; END_IF 4 : (* end of example *) ; END_CASE END_IF File - Modification ¶ (* example of how to use the CAA_FILE-library - file change function blocks *) PROGRAM FILE_CHANGE_PRG VAR xFileChgInit : BOOL := FALSE ; uiFileChgState : UINT := 0 ; sFileOldName : CAA_FILENAME := 'TestFile.txt' ; sFileNewName : CAA_FILENAME := 'NewFile.txt' ; szCopiedFileSize : CAA_SIZE := 0 ; filcp : FILE.Copy ; filrn : FILE.Rename ; fildl : FILE.Delete ; END_VAR IF NOT xFileChgInit THEN fildl ( xExecute := FALSE ); filrn ( xExecute := FALSE ); filcp ( xExecute := FALSE ); xFileChgInit := TRUE ; uiFileChgState := 0 ; ELSE CASE uiFileChgState OF 0 : (*copy file *) filcp.sFileNameSource := sFileNewName ; filcp.sFileNameDest := 'DestFile.txt' ; filcp.udiTimeOut := 100000 ; (* 100ms Timeout *) filcp.xOverWrite := TRUE ; (* overwrite the existing file *) filcp ( xExecute := TRUE ); IF filcp.xDone THEN szCopiedFileSize := filcp.szSize ; uiFileChgState := 1 ; END_IF IF filcp.xError THEN (* error handling*) ; END_IF 1 : (* rename file *) filrn.sFileNameOld := 'DestFile.txt' ; filrn.sFileNameNew := sFileNewName ; filrn ( xExecute := TRUE ); IF filrn.xDone THEN uiFileChgState := 2 ; END_IF IF filrn.xError THEN (* error handling*) ; END_IF 2 : (* delete file *) fildl.sFileName := sFileNewName ; fildl ( xExecute := TRUE ); IF fildl.xDone THEN uiFileChgState := 3 ; END_IF IF fildl.xError THEN (* error handling*) ; END_IF 3 : (* end of example*) ; END_CASE END_IF File – internal pointer ¶ (* example of how to use the CAA_FILE-library - file position function blocks *) PROGRAM FILE_POINT_PRG VAR xFilePosInit : BOOL := FALSE ; uiFilePosState : UINT := 0 ; udiActualPosition : UDINT := 0 ; udiActualEoFPosition : UDINT := 0 ; sFileName : CAA_FILENAME := 'TestFile.txt' ; hFile : CAA_HANDLE ; filop : FILE.Open ; filcl : FILE.Close ; filgp : FILE.GetPos ; filsp : FILE.SetPos ; fileof : FILE.EOF ; END_VAR IF NOT xFilePosInit THEN filop ( xExecute := FALSE ); filcl ( xExecute := FALSE ); filgp ( xExecute := FALSE ); filsp ( xExecute := FALSE ); fileof ( xExecute := FALSE ); xFilePosInit := TRUE ; uiFilePosState := 0 ; ELSE CASE uiFilePosState OF 0 : (* open file *) filop.sFileName := sFileName ; filop.eFileMode := FILE_MRDWR ; filop.xExclusive := TRUE ; filop ( xExecute := TRUE ); IF filop.xDone THEN hFile := filop.hFile ; uiFilePosState := 1 ; END_IF IF filop.xError THEN (* error handling*) ; END_IF 1 : (* get actual internal positon file pointer *) filgp.hFile := hFile ; filgp ( xExecute := TRUE ); IF filgp.xDone THEN udiActualPosition := filgp.udiPos ; uiFilePosState := 2 ; END_IF IF filgp.xError THEN (* error handling*) ; END_IF 2 : (* query - end of file is reached *) fileof.hFile := hFile ; fileof ( xExecute := TRUE ); IF fileof.xDone THEN IF fileof.xEOF THEN udiActualEoFPosition := udiActualPosition ; END_IF uiFilePosState := 3 ; END_IF IF filgp.xError THEN (* error handling*) ; END_IF 3 : (* set the internal positon file pointer *) filsp.hFile := hFile ; filsp.udiPos := udiActualEoFPosition - 5 ; IF filsp.udiPos < 0 THEN filsp.udiPos := 0 ; END_IF filsp ( xExecute := TRUE ); IF filsp.xDone THEN uiFilePosState := 4 ; END_IF IF filsp.xError THEN (* error handling*) ; END_IF 4 : (* close file *) filcl.hFile := hFile ; filcl ( xExecute := TRUE ); IF filcl.xDone THEN uiFilePosState := 5 ; END_IF IF filcl.xError THEN (* error handling*) ; END_IF 5 : (* end of example*) ; END_CASE END_IF File – Properties ¶ (* example of how to use the CAA_FILE-library - file property function blocks *) PROGRAM FILE_PROP_PRG VAR xFilePropInit : BOOL := FALSE ; uiFilePropState : UINT := 0 ; sFileName : CAA_FILENAME := 'TestFile.txt' ; hFile : CAA_HANDLE ; szFileSize : CAA_SIZE := 0 ; dtLastFileMod : DT ; sLastFileModification : STRING := '' ; filop : FILE.Open ; filcl : FILE.Close ; filsa : FILE.SetAttribute ; filgs : FILE.GetSize ; filgt : FILE.GetTime ; END_VAR IF NOT xFilePropInit THEN filop ( xExecute := FALSE ); filcl ( xExecute := FALSE ); filsa ( xExecute := FALSE ); filgs ( xExecute := FALSE ); filgt ( xExecute := FALSE ); xFilePropInit := TRUE ; uiFilePropState := 0 ; ELSE CASE uiFilePropState OF 0 : (* get file size *) filgs.sFileName := sFileName ; filgs ( xExecute := TRUE ); IF filgs.xDone THEN szFileSize := filgs.szSize ; uiFilePropState := 1 ; END_IF IF filgs.xError THEN Attributes: qualified_only InOut: Scope Name Type Initial Constant iDummyforLibDocuCAAFile INT 99
Library Information ¶ GetLibVersion (Function) GetLibVersionNumber (Function) IsLibReleased (Function)
GetLibVersion (FUN) ¶ FUNCTION GetLibVersion : VERSION This function has been automatically generated from the project information. InOut: Scope Name Type Return GetLibVersion VERSION
GetLibVersionNumber (FUN) ¶ FUNCTION GetLibVersionNumber : DWORD This function has been automatically generated from the project information. InOut: Scope Name Type Return GetLibVersionNumber DWORD