22/12/2022, 17:21:57
Une petite contribution trouvée dans une des applications notes de Wago Codesys 2.3
Permet l'interfaçage direct en le KNX et DALI comme le ferait une passerelle DALI.
Déclarer une fonction FB par point d'éclairage.
Permet l'interfaçage direct en le KNX et DALI comme le ferait une passerelle DALI.
Déclarer une fonction FB par point d'éclairage.
Code :
FUNCTION_BLOCK FbKNX_DALI_Dim
VAR_INPUT
bKNX_Master : BYTE := 1;
dwIndex_DPT : DWORD;
typBallast : typBallast;
xOnAndStepUp : BOOL;
xOffAndStepDown : BOOL;
xNightMode : BOOL;
bNightDimmLevel : BYTE:= 20;
typConfigDimmer : typConfigDimmer;
END_VAR
VAR_OUTPUT
rActualLevel : REAL;
END_VAR
VAR
Fb_DaliDimmDoubleButton : FbDaliDimmDoubleButton;
Fb_DaliSendDimmValue : FbDaliSendDimmValue;
_01_DimmSignal : FbDPT_Control_Dimming;
_02_SwitchSignal : FbDPT_Switch;
_03_StatusSwitch : FbDPT_Switch;
_04_Set_DimmLevel : FbDPT_Scaling;
_05_Status_DimmValue : FbDPT_Scaling_pro;
typ_ConfigDimmer : typConfigDimmer;
typDPT : typDPT;
idx1 : DWORD;
idx2 : DWORD;
idx3 : DWORD;
idx4 : DWORD;
idx5 : DWORD;
init : BOOL := TRUE;
END_VAR
Code :
(* calculate logical address of KNX instances if needed *)
IF init THEN
init:=FALSE;
IF dwIndex_DPT>0 THEN
idx1:=(dwIndex_DPT*1000000)+1000;
idx2:=(dwIndex_DPT*1000000)+2000;
idx3:=(dwIndex_DPT*1000000)+3000;
idx4:=(dwIndex_DPT*1000000)+4000;
idx5:=(dwIndex_DPT*1000000)+5000;
END_IF
END_IF
(* KNX instance for receiving the KNX dimm up / down command*)
_01_DimmSignal(dwIndex_DPT:=idx1 , bKNX_Master:=bKNX_Master);
(* KNX instance for receiving the KNX on / off command*)
_02_SwitchSignal(dwIndex_DPT:=idx2 , bKNX_Master:=bKNX_Master);
(* Night mode *)
typ_ConfigDimmer := typConfigDimmer;
IF xNightMode THEN
typ_ConfigDimmer.xSwitchOnLastLevel := FALSE;
typ_ConfigDimmer.bSwitchOnLevel := bNightDimmLevel;
END_IF
(* KNX instance for receiving the KNX DimmLevel*)
_04_Set_DimmLevel(dwIndex_DPT:=idx4 , bKNX_Master:=bKNX_Master);
(* evaluation of KNX input comands*)
IF _02_SwitchSignal.xUpdate_PLC THEN (* command switch OFF *)
IF _02_SwitchSignal.xSwitch_OUT THEN
Fb_DaliDimmDoubleButton.xOnAndStepUp:=TRUE;
ELSE
Fb_DaliDimmDoubleButton.xOffAndStepDown:=TRUE; (* command switch ON *)
END_IF
ELSIF _01_DimmSignal.bValue_OUT=1 THEN
typ_ConfigDimmer.tShortPushButton:=t#10ms;
IF _01_DimmSignal.xControl_OUT THEN
Fb_DaliDimmDoubleButton.xOnAndStepUp:=TRUE; (* command dim up *)
ELSE
Fb_DaliDimmDoubleButton.xOffAndStepDown:=TRUE; (* command dim down *)
END_IF
ELSE (* enable dim command via digital inputs *)
typ_ConfigDimmer.tShortPushButton:=t#500ms;
Fb_DaliDimmDoubleButton.xOnAndStepUp:=xOnAndStepUp;
Fb_DaliDimmDoubleButton.xOffAndStepDown:=xOffAndStepDown;
END_IF
IF _04_Set_DimmLevel.xUpdate_PLC THEN (* command set dim level *)
Fb_DaliSendDimmValue.rDimmValue:= _04_Set_DimmLevel.rValue_OUT;
Fb_DaliSendDimmValue.xUpdate:= TRUE;
IF _04_Set_DimmLevel.rValue_OUT > 0 THEN
_02_SwitchSignal.xSwitch_IN:=TRUE;
ELSE
_02_SwitchSignal.xSwitch_IN:=FALSE;
END_IF
ELSE
Fb_DaliSendDimmValue.xUpdate:= FALSE;
END_IF
(* DALI Instance in oder to control the ballast*)
Fb_DaliDimmDoubleButton(
typBallast:=typBallast,
xOnAndStepUp:= ,
xOffAndStepDown:= ,
typConfigDimmer:=typ_ConfigDimmer ,
xReady=> ,
bFeedback=> ,
rActualLevel=> );
Fb_DaliSendDimmValue(
typBallast:= typBallast,
rDimmValue:= ,
rHysteresis:= ,
xUpdate:= ,
xReady=> ,
bFeedback=> ,
rActualLevel=> );
(*KNX instance in order to transmitt dimm signal feedback *)
_05_Status_DimmValue(
rValue_IN:= Fb_DaliDimmDoubleButton.rActualLevel,
xUpdate_KNX:= ,
dwIndex_DPT:=idx5 ,
tMinSendTime:=t#2s,
typDPT:=typDPT,
bKNX_Master:=bKNX_Master );
rActualLevel:=Fb_DaliDimmDoubleButton.rActualLevel;
(* KNX instance for transmitting the KNX on / off status*)
_03_StatusSwitch(
xSwitch_In:=(rActualLevel>0),
dwIndex_DPT:=idx3 ,
bKNX_Master:=bKNX_Master);
__________________________________________________________
Full KNX, même la sonnette ! Home Assistant, automate WAGO, DALI-2
Full KNX, même la sonnette ! Home Assistant, automate WAGO, DALI-2