FB_BA_RdFcdElemLst
With the help of the function block FB_BA_RdFcdElemLst, data for facade elements (windows) can be imported from a pre-defined Excel table in csv format into the List of facade elements. In addition the imported data are checked for plausibility and errors are written to a log file.
The following example shows the Excel table with the entries of the window elements.
All text fields are freely writable. Important are the fields marked in green. Each row there identifies a data set.
The following rules are to be observed:
- A data set must always start with a '@'.
- The indices IndexColumn and IndexRow must lie within the defined limits, see List of facade elements. These indices directly describe the facade element in the list aFcdElem to which the data from the set are saved.
- Window width and window height must be greater than zero
- The corner coordinates P1x and P1y must be greater than or equal to zero.
- Each window element must be assigned to a group 1...255.
- For system-related reasons the total size of the table may not exceed 65534 bytes.
- This must have been saved in Excel as file type "CSV (comma-separated values) (*.csv)".
It is not necessary to describe all window elements that would be possible by definition or declaration. Before the new list is read in, the function block deletes the entire old list in the program. All elements that are not described by entries in the Excel table then have pure zero entries and are thus marked as non-existent and also non-evaluable, since the function block for shading correction, FB_BA_ShdCorr, does not accept elements with the group entry '0'.
Log file
Each time the reading function block is restarted, the log file is rewritten and the old contents are deleted. If there is no log file, it will be automatically created first. The log file then contains either an OK message or a list of all errors that have occurred. Errors connected with the opening, writing or closing of the log file itself cannot be written at the same time. Therefore, always note the output sErrDescr of the reading function block that indicates the last error code. Since the log file is always closed last during the reading process, a corresponding alarm is ensured in the event of an error.
Program sample
In this sample the variable bInit is initially set to TRUE when the PLC starts. Hence, the input bStt on the function block fbReadFacadeElementList receives a once-only rising edge that triggers the reading process. The file FacadeElements.csv is read, which is located in the folder C:∖Projekte∖. The log file "Logfile.txt" is then saved in the same folder. If this log file does not yet exist it will be created, otherwise the existing contents are overwritten. Reading and writing take place on the same computer on which the PLC is located. This is defined by the input tNetID = '' (=local). All data are written to the list aFcdElem declared in the program. The output bBusy is set to TRUE during reading and writing. The last file handling error that occurred is displayed at sErrDescr; bErr is then TRUE. If an error is detected in the data set, this is displayed at bErrDataSet and described in more detail in the log file. The number of found and read data rows is displayed at nAmtSetsRd for verification purposes.
The errors marked were "built into" the following Excel list. This gives rise to the log file shown:
The first error is in data set 2 and is an index error, since "0" is not permitted.
The next error in data set 6 was found after validation of the data with the internally used function block FB_BA_ShdObjEntry and allocated an error description. The third and the fourth errors likewise occurred after the internal validation.
Important here it that the data set numbers (in this case 22 and 24) do not go by the numbers entered in the list, but by the actual sequential numbers: only 30 data sets were read in here. |
Inputs
VAR_INPUT
bStt : BOOL;
sDataFile : STRING;
sLogFile : STRING;
tNetId : T_AmsNetId;
END_VAR
Name | Type | Description |
---|---|---|
bStt | BOOL | A TRUE edge on this input starts the reading process. |
sDataFile | STRING | Contains the path and file name for the data file to be opened. This must have been saved in Excel as file type "CSV (comma-separated values) (*.csv)". If the file is opened with a simple text editor, the values must be separated by semicolons. Example of an entry: sDataFile:= 'C:∖Projekte∖FacadeElements.csv' |
sLogFile | STRING | ditto log file for the accumulating errors. This file is overwritten each time the function block is activated, so that only current errors are contained. |
tNetId | T_AmsNetId | A string can be entered here with the AMS Net ID of the TwinCAT computer on which the files are to be written/read. If it is to be run on the local computer, an empty string can be entered. |
The data can be saved only on the control computer itself and on the computers that are connected by ADS to the control computer. Links to local hard disks in this computer are possible, but not to connected network hard drives. |
/ Inputs/Outputs
VAR_IN_OUT
aFcdElem : ARRAY[1..BA_Param.nSunPrt_MaxColumnFcd, 1..BA_Param.nSunPrt_MaxRowFcd] OF ST_BA_FcdElem;
END_VAR
Name | Type | Description |
---|---|---|
aFcdElem | ARRAY OF ST_BA_FcdElem |
Outputs
VAR_OUTPUT
bBusy : BOOL;
nAmtSetsRd : UDINT;
bErr : BOOL;
sErrDescr : T_MAXSTRING;
bErrDataSet : BOOL;
END_VAR
Name | Type | Description |
---|---|---|
bBusy | BOOL | This output is TRUE as long as elements are being read from the file. |
aAmtSetsRd | UDINT | Number of data sets read |
bErr | BOOL | In case of a fault, e.g. if warning stages are active, this output is set to TRUE. |
sErrDescr | T_MAXSTRING | Contains the error description. |
Error description |
---|
01: File handling error: Opening the log file - the ADS error number is stated. |
02: File handling error: Opening the data file - the ADS error number is stated. |
03: File handling error: Reading the data file - the ADS error number is stated. |
04: Error: During reading of the data file it was determined that the file is too large (number of bytes larger than nMaxDataFileSize) |
05: File handling error: Writing the log file - the ADS error number is stated. |
06: File handling error: Closing the data file - the ADS error number is stated. |
07: File handling error: Writing to the log file (OK message if no errors were detected) - the ADS error number is stated. |
08: File handling error: Closing the log file - the ADS error number is stated. |
Name | Type | Description |
---|---|---|
bErrDataSet | BOOL | This output is set to TRUE, if the read data sets are faulty. Further details are entered in the log file. |
Requirements
Development environment | Required PLC library |
---|---|
TwinCAT from v3.1.4024.22 | Tc3_BA2 from v5.2.5.0 |