I’m trying to convert my codesys 2.3 function block to e!cockpit.
The function has 3 inputs from a physical switch Auto/Off/On. And Virtual Switch from HMI/BMS system on Bacnet. When the physical switch is in Auto then the virtual switch can be used to set auto/Off/On. But if the physical switch is in Off or On it should write to tha bacnet multistate value priority 10 and not let HMI/BMS do anything. They use priority 13.
I have thise working in codesys 2.3 but I need help converting it to e!cockpit
(*Codesys 2.3 This function block collects BacNet Multistate value values.
1 = Switch SD/VenderAuto
2 = Switch Off
3 = Switch On
The values say what position the turner is in.
The block writes the value in priority 10 when ON(3) or OFF(2).
When selected auto(1), the value in priority 10 is reset and the top system can take control.*)
VAR_IN_OUT
bacVenderValue :Bacnet_Multistate_value;
END_VAR
VAR_INPUT
VenderOff : BOOL;
VenderOn : BOOL;
VenderSD : BOOL;
END_VAR
VAR_OUTPUT
VenderValue :DWORD; (*Physically facing in blackboard. 0-IB, 1-Auto, 2-Off, 3-On*)
END_VAR
VAR
VenderValuePRI : FbBACnetPriorityArray_MV; (*Feature block to be able to zero priority 10*)
dwValue : DWORD := 0; (*Default value *)
bPriority : BYTE := 10; (*Priority, if 0 the function block will be disabled*)
dwPresentValue : DWORD; (*Present value*)
xOverride : BOOL; (*Override signal. TRUE->Present value is an override value*)
xError : BOOL; (*TRUE-> Out of range. dwValue> Number of states*)
xNull : BOOL; (*Resetter prioritet 10 verdier "NULL" TRUE->NULL*)
END_VAR
IF (VenderSD = TRUE) AND (VenderOff = FALSE) AND (VenderOn = FALSE) THEN
(*AUTO*)
IF (xNull = FALSE) THEN
xNull := TRUE;
VenderValuePRI(
dwValue:= 0,
xNULL:= xNull,
bPriority:= bPriority,
BACNET_MULTISTATE_VALUE:= bacVenderValue,
dwPresentValue=> dwPresentValue,
xOverride=> xOverride,
xError=> xError);
END_IF
VenderValue := 1;
ELSIF (VenderSD = FALSE) AND (VenderOff = TRUE) AND (VenderOn = FALSE) THEN
(*OFF*)
bacVenderValue.priority_array.PriorityArray[10].CHOICE :=3;
bacVenderValue.priority_array.PriorityArray[10].Value :=2;
VenderValue := 2;
xNull := FALSE;
ELSIF (VenderSD = FALSE) AND (VenderOff = FALSE) AND (VenderOn = TRUE) THEN
(*On*)
bacVenderValue.priority_array.PriorityArray[10].CHOICE :=3;
bacVenderValue.priority_array.PriorityArray[10].Value :=3;
VenderValue := 3;
xNull := FALSE;
ELSE
(*IF undifined - OFF*)
bacVenderValue.priority_array.PriorityArray[10].CHOICE :=3;
bacVenderValue.priority_array.PriorityArray[10].Value :=2;
VenderValue := 2;
xNull := FALSE;
END_IF