FB_BA_RdShdObjLst

FB_BA_RdShdObjLst 1:

With the help of this function block, data for shading objects can be imported from a pre-defined Excel table in csv format into the list of shading objects. 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. The fields marked in green are important; each line in these fields identifies a data set. The columns G to J have a different meaning depending on whether the type rectangle or ball is concerned. The columns K to M are to be left empty in the case of balls. With regard to the rectangle coordinates, only the relevant data are entered and the remainder are internally calculated, see FB_BA_ShdObjEntry.
The following rules are to be observed:

Is not necessary to describe all shading objects that are possible per facade. Only those contained in the list ultimately take effect.

FB_BA_RdShdObjLst 2:

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

FB_BA_RdShdObjLst 3:

In this sample the variable bInit is initially set to TRUE when the PLC starts. Hence, the input bStt on the function block fbReadShadingObjects receives a once-only rising edge that triggers the reading process. The file "ShadingObjects.csv" is read, which is located in the folder "C:\Projects\". 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 sNetID = '' (=local). All data are written to the list arrShdObj declared in the program. During reading and writing the output bBusy is set to TRUE. The last file handling error that occurred is displayed at sErrDescr; bErr is 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 udiAmtSetsRd for verification purposes.

The errors marked were built into the following Excel list. This gives rise to the log file shown:

FB_BA_RdShdObjLst 4:

The first error is in data set 3 and is a type error, since "2" is not defined.
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 error likewise occurred after the internal validation.

FB_BA_RdShdObjLst 5:

Important here it that the data set number (in this case 11) does not go by the number entered in the list, but by the actual sequential number: only 16 data sets were read in here.

VAR_INPUT

bStt      : BOOL;
sDataFile : STRING;
sLogFile  : STRING;
sNetId    : T_AmsNetId;;

bStt: A TRUE edge on this input starts the reading process.

sDataFile: 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:∖Projects∖ShadingObjects.csv'

sLogFile: 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.

sNetId: A string can be entered here with the AMS Net ID of the TwinCAT computer on which the files are to be written/read. An empty string can be specified for the local computer (see T_AmsNetId).

FB_BA_RdShdObjLst 6:

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.

VAR_OUTPUT

bBusy        : BOOL;
udiAmtSetsRd : UDINT;
bErr         : BOOL;
sErrDescr    : T_MAXSTRING;
bErrDataSet  : BOOL;

bBusy: This output is TRUE as long as elements are being read from the file.

udiAmtSetsRd: Number of data sets read.

bErr: This output is switched to TRUE, if a file write or read error has occurred.

sErrDescr: Contains the error description.

Error description

01: File handling error: Opening the log file - the ADS error number is stated.

02: File handling error: Open 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 udiMaxDataFileSize)

05: File handling error: Writing to 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.

bErrDataSet: This output is set to TRUE, if the read data sets are faulty. Further details are entered in the log file.

VAR_IN_OUT

arrShdObj: ARRAY[1..Param.uiMaxShdObj] OF ST_BA_ShdObj;

arrShdObj: List of shading objects.

Requirements

Development environment

Required PLC library

TwinCAT from v3.1.4024.7

Tc3_BA from v1.1.6.0