Example 2. Program structure For sun position calculations you should declare an instance of function block FB_SPA [ } 17] and local variables for allocating the required result values. The input parameter for the calculation can be directly assigned to the inputs of the function block. In addition to the sun angles the sunrise and sunset is required as output, which means the advanced functionality is required, which is specified via the enumeration value eSPA_ZA_RTS of type E_SPA_FunctionCode [ } 21] . The output values of the function block are assigned to your local variables. The program section should now look as follows: PROGRAM MAIN VAR fbSPA : FB_SPA; fSunZenith :
LREAL; fSunAzimuth : LREAL; tSunrise : TIME; tSunset : TIME; eErrorCode : E_SPA_ErrorCode; bExecute : BOOL; bInit :
BOOL := TRUE; END_VAR IF bInit THEN bInit := FALSE; fbSPA.stTime.iYear := 2010; fbSPA.stTime.iMonth := 3; fbSPA.stTime.iDay := 4; fbSPA.stTime.iHour := 14; fbSPA.stTime.iMinute := 27; fbSPA.fTimezone := 2; fbSPA.fLongitude := 31.134; fbSPA.fLatitude := 29.979; fbSPA.fElevation := 70; fbSPA.fTemperature := 21.7; fbSPA.eFunction := eSPA_ZA_RTS; END_IF IF bExecute THEN fbSPA(); eErrorCode := fbSPA.iErrorCode; fSunZenith := fbSPA.fZenith; fSunAzimuth := fbSPA.fAzimuth; tSunrise := LREAL_TO_TIME(fbSPA.fSunrise*60*60*1000); tSunset := LREAL_TO_TIME(fbSPA.fSunset*60*60*1000); END_IF This sample of the TwinCAT Solar Position Algorithm library contains a visualisation facility that provides a quick overview of current inputs and outputs of function block FB_SPA [ } 17] .
It is therefore ideal for test purposes. 3. Test Compile the created PLC program. Make sure that TwinCAT is in the Run mode on the desired system. Login to the desired run-time system from TwinCAT PLC Control. Start the PLC program. The calculation is executed by setting the local variable bExecute to TRUE. This can be done via 'online write' or the corresponding button in the visualisation, for example. The visualisation should now present the following results: TF3900 24 Version: 1.1.1