The Building_common.lib provided by WAGO allows for quick and simple control of blinds. However, constructing more complex functions with it is very cumbersome and requires manual work.
An alternative to that standard approach could be using the open-source OSCAT libraries maid available at ww.oscat.de. Please however be warned: if you have never worked with those libraries you might be surprised by their complexity and size as well as short documentation.
The first difficulty you might run into while adding the oscat-basic and oscat-building libraries to your project is the 'Maximum POU number exceeded' error shown by CoDeSys and compiling/building the project. A solution was presented by kamiKAC on our forum:
Many thanks to kamiKAC for this hint!
In the oscat-building library one can find many function. When it comes to blind-controlling ones, the following are the most important:
BLIND_INPUT - to connect buttons and controlling signals
BLIND_CONTROL(_S) - to connect DO outputs controlling the blind motor
The basic functionalityy can be achieved by connecting the function block BLIND_INPUT and BLIND_CONTROL as follows:
VAR Input_Blind1: BLIND_INPUT; Control_Blind1:BLIND_CONTROL_S; END_VAR * * * Input_Blind1( S1:=Button1 OR VIS_Blind1_UP , S2:=Button2 OR VIS_Blind1DN, POS:=Control_Blind1.POS ); Control_Blind1( UP:=Input_Blind1.QU, DN:=Input_Blind1.QD, S_IN:=Input_Blind1.STATUS, pi:=Input_Blind1.PO\ ); OUT1:=Control_Blind1.MU; OUT1:=Control_Blind1.MD;
Where:
The connections between BLIND_INPUT i BLIND_CONTROL_S function blocks is best presented by the graph taken from the OSCAT documentation:
The beauty of the structure offered by the oscat-building library lies in the ability of connecting many function-specific function blocks like 'share control', 'night/sun control', 'alarm', 'scenes', which are placed in between INPUT and CONTROL function blocks. It all looks like a set of LEGO block, which are placed one on another, creating a tower.
Here is an example taken directly from my installation - controlling one blind in the living room:
VAR Clicker_IN1 : Fb_ShortLong:=(uiTS_10tel_s:=1, uiTL_10tel_s:=1, uiT_10tel_s :=5); END_VAR VAR RETAIN PERSISTENT Input_B_1S1 :BLIND_INPUT:=(PI:=120, MAX_RUNTIME:=T#25s, MANUAL_TIMEOUT:=t#60m, MASTER_MODE:=TRUE); Shade_B_1S1 :BLIND_SHADE_S:=(HORZ1:=70, HORZ2:=150, SHADE_POS:=150, SHADE_DELAY:=T#60s); Control_B_1S1 :BLIND_CONTROL_S:=(T_UP:=T#20s, T_DN:=T#18s); END_VAR * * * Clicker_IN1(xSwitch:=IN1); Input_B_1S1( S1:=Clicker_IN1.xShort OR VIS_B_1S1_UP, S2:=Clicker_IN1.xLong OR VIS_B_1S1_DOWN, IN:=VIS_B_1S1_SpecPos, POS:=Control_B_1S1.POS ); Shade_B_1S1( UP:=Input_B_1S1.QU, DN:=Input_B_1S1.QD, S_IN:=Input_B_1S1.STATUS, pi:=Input_B_1S1.PO, ENABLE:=ShadeFlag_B_1S, SUN:=SunSignal_1S, CX:=ReadClock.Calendar ); Control_B_1S1( UP:=Shade_B_1S1.QU, DN:=Shade_B_1S1.QD, S_IN:=Shade_B_1S1.STATUS, pi:=Shade_B_1S1.PO ); OUT1:=Control_B_1S1.MU; OUT2:=Control_B_1S1.MD;
Where in definitions:
Clicker_IN1 - function block from WAGO Building_common.lib recognizing long/short button pushes. A similar function in OSCAT library is in my opinion inferior.
Input_B_1S1:
Shade_B_1S1:
Control_B_1S1:
In the program code:
Input_B_1S1:
Shade_B_1S1
Control_B_1S1
In a separate program ReadClock (executed every 1s: Task configuration, Append Task itd.):
VAR Calendar_Updater : CALENDAR_CALC:=(SPE:=TRUE); Calendar : CALENDAR:=(LATITUDE:=51.0, LONGITUDE:=16.0, OFFSET:=120); Holidays :ARRAY [0..29] OF HOLIDAY_DATA; END_VAR * * * Calendar_Updater(XCAL:=Calendar, HOLIDAYS:=Holidays); Calendar.Utc:=SysRtcGetTime(TRUE); (*make sure your system runs at UTC time, otherwise - correct it with for example +/- T#2h*)
Where:
How does it all work?
A short press of a button connected to IN1 moves the blind UP, a long (>0.5 sec) moves it down, a short pres when motor in motion stops it. When the sun crosses the position of 70 deg (while 90 is EAST), the blind will move to position 150 (255=open, 0=closed), when the sun moves past 150deg the blinds will move up. Tapping the variable VIS_B_1S1_SpecPos in visualization will move the blind to position 120. In my living room I have blinds from three directions: East, South and West - they move up and down following the sun position.
REMARKS:
So..... good luck :)