Universal Function Block for toggling outputs via numeric code input on HMI (e.g. EasyBuilder / Weintek).
Use it to activate options, modes, access levels, or any feature that requires a numeric unlock code.
The operator enters a numeric code on the HMI screen and presses Confirm.
- If the code matches one of the configured codes → the corresponding output toggles ON/OFF and a success notification appears for 3 seconds.
- If the code does not match any entry → an error notification appears for 3 seconds.
- Entering the correct code a second time disables the output (toggle behavior).
| Variable | Type | Description |
|---|---|---|
xConfirm |
BOOL |
Rising edge triggers code check (HMI confirm button) |
| Variable | Type | Description |
|---|---|---|
rInputCode |
REAL |
Entered code — automatically reset to 0 after a match |
| Variable | Type | Description |
|---|---|---|
xOutput1 |
BOOL |
Output 1 active |
xOutput2 |
BOOL |
Output 2 active |
xOutput3 |
BOOL |
Output 3 active |
xOutput4 |
BOOL |
Output 4 active |
xCodeOk |
BOOL |
Notification: correct code entered (high for 3 s) |
xCodeError |
BOOL |
Notification: wrong code entered (high for 3 s) |
Activation codes are defined inside the FB as VAR:
rCode1 : REAL := 2134; // Output 1
rCode2 : REAL := 3421; // Output 2
rCode3 : REAL := 2314; // Output 3
rCode4 : REAL := 2341; // Output 4Change these values to your own codes before building.
// Global / HMI variables
VAR_GLOBAL
gConfirm : BOOL;
gInputCode : REAL;
gOut1 : BOOL;
gOut2 : BOOL;
gOut3 : BOOL;
gOut4 : BOOL;
gCodeOk : BOOL;
gCodeError : BOOL;
END_VAR
// PLC_PRG
VAR
fbCode : FB_CodeActivation;
END_VAR
fbCode(
xConfirm := gConfirm,
rInputCode := gInputCode,
xOutput1 => gOut1,
xOutput2 => gOut2,
xOutput3 => gOut3,
xOutput4 => gOut4,
xCodeOk => gCodeOk,
xCodeError => gCodeError
);| Code entries | State |
|---|---|
| 0 times | Output OFF |
| 1 time | Output ON |
| 2 times | Output OFF (reset) |
- CoDeSys V3 (tested on V3.5)
- Standard library:
Standard.library(R_TRIG, TON) - HMI: any panel that can write a REAL variable and a BOOL trigger (EasyBuilder / Weintek recommended)
Nikita Poliakov — Automation & Instrumentation Engineer
2+ years delivering end-to-end control systems for food and meat-processing equipment.
LinkedIn | work.nikita@bk.ru
MIT