====== Direct Switch ======
{{ :files:img_warning-line_b.png?nolink |}}
{{ :en:hw:08_safety-instructions_pseudo-ISO-7010-info.png?nolink |(i)}}
This function works only for following Inputs & Outputs:
* **digital inputs**
* **digital outputs**
* **relay outputs**
/*
The DirectSwitch function can be used on any unit or extension module equipped with digital inputs and digital or relay outputs within a single section.
*/
This function allows logical connection of digital input to digital output or relay output to automatically perform one of the available operation. DirectSwitch is independent on the control software running on unit and is suitable for control of lighting or any other time-critical applications (typically, the output response time matches the input response).
===== How it works =====
{{ :files:img_warning-line_b.png?nolink |}}
{{ :en:hw:09_safety-instructions_pseudo-iso-7010-attention.png?nolink |(!)}}
**Attention:** \\
If DirectSwitch is applied to an output, it is not possible to write onto output (DO) in a regular way. Instead, you need to set the ForceOutput register to TRUE for approx. 1 second.
The software detection of changes is far from being instantaneous. And there are applications, where even 20 ms delay can cause problems, or represent some discomfort at least. A typical example is a switch controlling a light. What we expect from the behaviour is the instant change of the lighting upon pressing the switch. That, as demonstrated above, is not possible to achieve in the software by simple wiring the DI to DO.
The direct switch is the configuration of digital input in a way it will directly control digital or relay output of the same name. The wiring of the input and output is fixed and cannot be changed, only turned on or off. On Group 1, the DIs are wired to DOs. On other Groups and Unipi extensions, the DIs are wired to ROs.
DirectSwitch function can be configured only for the corresponding input and output, ie. only for **DIy.x** input and **DOy.x** (**ROy.x**) output, where **x** and **y** (if the **y** is given) numbers must match. It is not possible to use DirectSwitch simultaneously for input and output with mismatched labels, eg. **DIx.y** and **DOv.z.** It is also not possible to use the function for a single input and multiple outputs at the same time.
{{ :files:img_warning-line_b.png?nolink |}}
{{ :en:hw:08_safety-instructions_pseudo-ISO-7010-info.png?nolink |(i)}}
**Please note:** \\
The **Direct switch** depends on the [[.:description-of-debounce-hidden|debounce]] settings. To have an instant change, you need to set the **Debounce** to value which doesn't deny the purpose of the **Direct switch** and yet to value, which doesn't deny the purpose of the **Debouncing**. 5-10 ms should be OK.
===== Enabling the Direct Switch =====
In the **left panel**, right-click on the name of your Unipi controller under the Modbus TCP channel and select Open editor.
{{ .:direct-switch:direct-switch_00-open-controler-definition.png?direct |}}
Write ''DI_'' in the search bar and select the ''DI_1.01'', click on it and in the **Properties** panel find the **Direct Switch** field.
By selecting more than one digital inputs you can change the direct switch settings on multiple inputs at once.
{{ .:direct-switch:direct-switch_01-direct-switch-modes.png?direct |}}
As you can see, the option has a dropdown menu with different modes.
* **Disabled**: the direct switch is disabled. This option is selected by default.
* **Copy**: The status of the DI is copied to the DO/RO. So when the DI is ''TRUE'', the DO/RO is ''TRUE'' and when the DI is ''FALSE'' the DO/RO is also ''FALSE''
* **Copy (Invert)**: Same as above but inverted. When the DI is ''TRUE'' the DO/RO is ''FALSE'' and vice versa.
* **Toggle**: This mode toggles the DO/RO on the rising edge of the DI. Handy for controlling light with a momentary switch for example
Demonstration on how the LED will look while **Direct Switch** is enabled on Patron units is [[en:hw:007-patron:led-indication#directswitch_function|here]].
Select the copy option.
{{ :files:img_warning-line_b.png?nolink |}}
{{ :en:hw:09_safety-instructions_pseudo-ISO-7010-attention.png?nolink |(!)}}
**Important:** \\
We just changed the configuration of the PLC modules, which is not applicable by simply uploading the solution. To save the configuration, follow the [[en:sw:01-mervis:unipi-configure-module-hidden|Unipi - Configure Module]] tutorial.
Now, that the ''DI_1.01'' input is linked to ''DO_1.01'' you can try to changing states of ''DI_1.01'' with wired switch or button. You should see the output ''DO_1.01'' changing to same state as input you are changing.