LGF_FileRead (FB / V1.0.0)

Overview

Author: Siemens SIMATIC Systems Support

Short description

This function block offers reading data as binary / serialized data stream from files stored on the PLC's memory card in the folder UserFiles.

Block Interface

LGF_FileRead (FB)
Bool  execute done  Bool
    
Bool  dataLengthMustMatch busy  Bool
    
String  fileName error  Bool
    
   status  Word
    
   dataLength  DInt
    
   diagnostics  LGF_typeDiagnostics
    
Array[*] of Byte  bufferByteArray  Array[*] of Byte
       
Variant  data  Variant
       
   

Input parameter

IdentifierData type Default value Description
executeBool FALSE Rising edge starts file read once
dataLengthMustMatchBool FALSE TRUE: The length of the file data set and the dataset in the PLC have to match.
fileNameString '' Name of file including path: `UserFiles/test.dat`

Output parameter

IdentifierData type Description
doneBool TRUE: Commanded functionality has been completed successfully
busyBool TRUE: FB is not finished and new output values can be expected
errorBool TRUE: An error occurred during the execution of the FB
statusWord 16#0000 - 16#7FFF: Status of the FB, 16#8000 - 16#FFFF: Error identification
dataLengthDInt Data length read from file (serialized length of `data`)
diagnosticsLGF_typeDiagnostics Diagnostic structure to store and transfer diagnostic information from blocks trough the interface.

In/Out parameter

IdentifierData type Description
bufferByteArrayArray[*] of Byte Byte array buffer for read / write from / to file
dataVariant Data set read from file

Status & Error codes

Code / ValueIdentifier / Description
16#0000STATUS_EXECUTION_FINISHED
Execution finished without errors
16#7000STATUS_NO_CALL
No job being currently processed
16#7001STATUS_FIRST_CALL
First call after incoming new job (rising edge 'execute')
16#7002STATUS_SUBSEQUENT_CALL
Subsequent call during active processing without further details
16#8201ERR_BUFFER_LOWERBOUND
Error: Buffer array lower bound Lower bound has to be 0
16#8202ERR_BUFFER_ARRAY_TO_SMALL_TO_COPY
Error: Buffer size less than needed size for data
16#8401ERR_FILE_PATH
Error: File path error: File path has to start with 'UserFiles/'.
16#8411ERR_FILE_SIZE_GRATER_THEN_DATA_SIZE
Error: File length and Data length dose not match!
16#8412ERR_FILE_SIZE_LESS_THEN_DATA_SIZE
Error: File length and Data length dose not match!
16#8600ERR_UNDEFINED_STATE
Error due to an undefined state in state machine
16#8601ERR_MOVE_BLK_VARIANT
Error: Move block variant (buffer to data) - see `diagnostics.subFunctionStatus`
16#8602ERR_DATA_SERIALIZE
Error: Serialize data - see `diagnostics.subFunctionStatus`
16#8603ERR_DATA_DESERIALIZE
Error: Deserialize data - see `diagnostics.subFunctionStatus`
16#8604ERR_FILE_READ_INIT
Error: Read file from SMC - see `diagnostics.subFunctionStatus`
16#8605ERR_FILE_READ
Error: Read file from SMC - see `diagnostics.subFunctionStatus`

User defined datatype(s)

LGF_typeDiagnostics (UDT / V1.0.0)

Diagnostic structure to store and transfer diagnostic information from blocks trough the interface.

Identifier Data type Default value Description
status Word 16#0000 Status of the Block or error identification when error occurred
subfunctionStatus Word 16#0000 Status or return value of called FB's, FC's and system blocks
stateNumber DInt 0 State in the state machine of the block where the error occurred

Functional description

With the function LGF_FileRead a file can be read into the data budget of a variable at data. To read the data it is necessary to deserialize it, which the function already takes from the user.
For deserialization an external buffer in the form of a byte array must be connected which can take up the amount of data, if the buffer is too small an error is output.

The file name must always be specified in full together with the folder name and the file extension in the following format: UserFiles/test.dat.

Change log

Version & DateChange description
01.00.00Simatic Systems Support
19.02.2023First released version