# I/O Panel

Source: https://rungs.dev/docs/studio/io-panel

> Operate the inputs of your Add-On Instruction in Rungs Studio as real pilot devices — push buttons, emergency stops, selector switches and potentiometers — and watch what your logic does with them.

An Add-On Instruction (AOI) does nothing on its own. Something has to call it and hand it values: a start button, a door switch, a level reading. On a real machine those values come from devices wired to the controller. In Rungs Studio they come from the I/O Panel, which stands in for the program that calls your AOI.

The panel is the `I/O Panel` tab in the right sidebar. It lists every tag with its current value. You can change **Input** and **InOut** tags, because those are the values a caller supplies. **Output** and **Local** tags are read-only, because your logic sets them.

## Inputs are pilot devices [#inputs-are-pilot-devices]

A real input is never just a 0 or a 1. It comes from a button or a switch on a control panel, and that device decides how the value changes. A start button gives a 1 only while a finger is on it. An emergency stop stays pressed until someone releases it by hand. Logic that works with a switch you click on and off can fail with a real push button, so the panel lets you try your logic with the device it will meet.

The buttons and switches that a person operates on a control panel are called **pilot devices**. The part of a pilot device that switches one input is a **contact block**. A pilot device can have several contact blocks, and it moves them together.

Every `BOOL` Input is one contact block on one of these pilot devices:

| Pilot device    | How it moves                                                   |
| --------------- | -------------------------------------------------------------- |
| Push button     | Pressed while you hold it. It springs back when you let go     |
| Emergency stop  | Stays pressed until you click it again to release it           |
| Selector switch | A knob with two or three positions. It stays where you turn it |
| General switch  | Stays where you put it, like a door switch or a limit switch   |

A new `BOOL` Input is a general switch: one click turns it on, and the next turns it off. How it is drawn depends on the view you choose, described below. To make it another pilot device, right-click its row and choose from the menu. You can do this while the program runs: it keeps running, and only the pilot device you changed starts over.

## Normally open and normally closed [#normally-open-and-normally-closed]

Each contact block is **normally open (NO)** or **normally closed (NC)**. "Normally" means at rest, with nobody touching the pilot device. Your program reads 1 while the contact block is closed.

| Contact block        | At rest | Operated |
| -------------------- | ------- | -------- |
| Normally open (NO)   | 0       | 1        |
| Normally closed (NC) | 1       | 0        |

A stop button is usually wired normally closed. It reads 1 all the time and drops to 0 when pressed. If the wire breaks, the input also drops to 0, and the machine stops. That is why stop circuits are built this way, and why your logic for a stop button usually looks for a 0.

For example, make `In_Stop` a push button with a normally closed contact block. It reads 1 until you press it:

| What you do     | `In_Stop` reads |
| --------------- | --------------- |
| Nothing         | 1               |
| Hold the button | 0               |
| Let go          | 1               |

## Operating a pilot device [#operating-a-pilot-device]

- **Push button:** hold it down to press it and let go to release it. To keep it pressed without holding, Shift-click it, or choose `Keep pressed` in its menu. The next click lets it go.
- **Emergency stop and general switch:** click to turn it over. It stays.
- **Selector switch with two positions:** click to turn it to the other position.
- **Selector switch with three positions:** click one of its inputs to turn the switch to the nearest position that changes that input.

## The positions of a selector switch [#the-positions-of-a-selector-switch]

On a selector switch, each contact block sits in a position: left or right, and on one with three positions also the centre. The switch operates a contact block while it stands in that position. So a normally open contact block reads 1 there and 0 in every other position. A normally closed one reads 0 there and 1 in every other position.

For example, a selector switch with two positions has a normally open contact block for `In_Run` at the right:

| Position | `In_Run` |
| -------- | -------- |
| Left     | 0        |
| Right    | 1        |

You choose the position of a contact block in the `Position` part of the menu. A position holds one contact block, so a selector switch takes as many contact blocks as it has positions. If you choose a position that is taken, the two contact blocks swap places.

The menu lists `2-position selector switch` and `3-position selector switch` as two pilot devices. A switch with three positions can become one with two as long as no contact block is at the centre, because a switch with two positions has no centre. Until then the menu shows `2-position selector switch` greyed out with the reason. Move that contact block to a side first.

You can always make a selector switch another pilot device, such as a push button. Each contact block keeps whether it is normally open or normally closed.

A selector switch can **spring back**, like a jog switch that returns when you let go. On a switch with three positions, tick `Springs back from left` or `Springs back from right` in the menu, and that side returns to the centre. On a switch with two positions, tick `Springs back from right`, and it returns to the left. A side that springs back works like a push button: hold it, or Shift-click to keep it.

## One pilot device, several inputs [#one-pilot-device-several-inputs]

Some pilot devices switch more than one input. A two-channel emergency stop has two normally closed contact blocks and opens both at once. A Hand/Off/Auto selector switch has one contact block for Hand and one for Auto, and the centre closes neither.

To put two inputs on one pilot device, right-click one of them, choose `Link with`, and pick the other. The input you right-clicked joins the pilot device of the one you picked, and keeps its own contact block. The panel then shows them as one block, and one click moves them together. `Unlink from` makes an input a pilot device of its own again.

For example, to make a two-channel emergency stop from `In_EStopCh1` and `In_EStopCh2`:

1. Right-click `In_EStopCh2`, choose `Link with`, and pick `In_EStopCh1`.
2. Right-click either input and choose `Emergency stop`. Choosing a pilot device does not change a contact block, so both are still normally open.
3. On each of the two inputs, choose `Normally closed (NC)`.

The stop now starts pressed, because the Default Value of both inputs is 0 (see [Where a pilot device starts](#where-a-pilot-device-starts)):

| What you do               | `In_EStopCh1` | `In_EStopCh2` |
| ------------------------- | ------------- | ------------- |
| Nothing                   | 0             | 0             |
| Click to release the stop | 1             | 1             |
| Click to press it again   | 0             | 0             |

Another example is a Hand/Off/Auto selector switch with three positions, `In_Hand` at the left and `In_Auto` at the right, both normally open:

| Position | `In_Hand` | `In_Auto` |
| -------- | --------- | --------- |
| Left     | 1         | 0         |
| Centre   | 0         | 0         |
| Right    | 0         | 1         |

A selector switch takes one contact block for each position. A push button, an emergency stop and a general switch take any number.

## Where a pilot device starts [#where-a-pilot-device-starts]

When you press Start, each pilot device goes to the position that matches the **Default Value** of its inputs. A general switch whose input has a default of 1 starts closed. A Hand/Off/Auto selector switch whose `In_Auto` default is 1 starts at Auto. A pilot device only starts in a position it can stay in, because nobody is holding it when the simulation starts. A push button therefore always starts at rest: a normally closed one starts at 1, whatever its default is. A selector switch that springs back from one side never starts on that side. When no position matches the defaults, the pilot device starts at rest.

While the simulation is stopped, you cannot change an input, because Start would put it back where it starts anyway. Point at an input and the panel says so. Press Start, or Step to start it paused, and then work the inputs. The menu of an input still works while the simulation is stopped, so you can choose its pilot device first. For an input that should start at another value, change its **Default Value** in the Tags tab. Its pilot device then starts in the position that matches it, if it can stay there, as described above.

An [AOI unit test](https://rungs.dev/docs/studio/aoi-unit-tests) does not use the panel's pilot devices. It starts every input from its Default Value and sets the inputs it needs itself.

## When your logic writes to an input [#when-your-logic-writes-to-an-input]

A pilot device is hardware. Your logic can write to an Input, but it cannot move the pilot device. Before every scan, the panel gives each Input its value again: what its pilot device reads, or the number you typed. So what your logic writes to an Input lasts until the end of that scan, and the next scan starts from the panel's value again. The panel always shows the value it gives. The ladder editor and the Trend show the value the tag holds after the scan, so there you see what your logic wrote.

For example, `In_Start` is a switch that is on, and the logic has the line `In_Start := 0;`:

| Moment                         | `In_Start` |
| ------------------------------ | ---------- |
| Start of a scan                | 1          |
| After the line `In_Start := 0` | 0          |
| Start of the next scan         | 1          |

An [AOI unit test](https://rungs.dev/docs/studio/aoi-unit-tests) does not set an Input again before every scan. It sets an Input only at a step that has `in`. So in a test, a value your logic writes to an Input stays until a later step sets that Input. In the example above, `In_Start` would stay 0.

## Three ways to see the inputs [#three-ways-to-see-the-inputs]

Three icons on the `Inputs` row switch how the `BOOL` Inputs are drawn. Studio starts with North American symbols. The choice is yours and is not saved with the AOI.

- **Switches:** every input is an on/off switch that shows its value.
- **North American symbols:** contact blocks as North American wiring diagrams draw a contact, with two terminals and the bar or blade that joins them.
- **IEC symbols:** contact blocks as IEC wiring diagrams draw a contact, with a blade that closes a gap in the line.

While the simulation runs, an input that is 1 is green, the colour of a rung that has power: a switch that is on has a green track, and in the symbol views a closed contact block is green. While the simulation is paused, that green is amber. While the simulation is stopped, nothing has power, so every switch and every contact block is grey. The thumb of a switch and the shape of a contact block still show its value. A switch that is off and an open contact block are grey all the time. A selector switch shows its knob: click the knob to turn it one position.

## With the keyboard [#with-the-keyboard]

Every input is one Tab stop. The keys do what the mouse does.

| Key                   | What it does                                                                |
| --------------------- | --------------------------------------------------------------------------- |
| Space or Enter        | A click on that input. A push button is pressed while the key is down       |
| Shift+Space           | Keeps a push button pressed. Space lets it go                               |
| Left and Right arrows | Turn a selector switch one position                                         |
| Shift+arrow           | Keeps a selector switch on a side that springs back. The arrow back lets go |
| Shift+F10             | Opens the menu of that input                                                |

On a phone or tablet, hold a finger on the name of an input to open its menu. Holding a finger on the switch itself presses the pilot device.

## Number inputs [#number-inputs]

A number Input (`SINT`, `INT`, `DINT` or `REAL`) starts as a fixed value: type a value and press Enter, and it stays there. That is fine for a preset or a count. But many number inputs are measurements, such as a tank level or a temperature, and a measurement does not jump from one value to another. It rises and falls, and it is never perfectly steady. To try your logic against that, right-click the input and make it a potentiometer or a ramp. On a real panel, a potentiometer is a knob that sets a value in a range.

| Choice        | What it does                                                               |
| ------------- | -------------------------------------------------------------------------- |
| Fixed value   | You type the value, and it stays there                                     |
| Potentiometer | You drag the value inside a range, and can still type it                   |
| Ramp          | A potentiometer that moves to where you put it at a speed, not all at once |

### The potentiometer [#the-potentiometer]

A potentiometer draws the field on a bar. The filled part shows where the value is in its range. Drag anywhere on the bar: the whole width is the whole range, so the value follows the pointer and stops at each end. A click without a move opens the field for typing.

A new potentiometer gets a range without any typing: 0 to 100, or 0 to 32767 for an `INT` and 0 to 127 for a `SINT`. To change it, choose the range in the menu. A small box opens under the row with the lowest and the highest value. Press Enter to keep them or Escape to give them up.

Dragging stays inside the range, but typing does not have to. This lets you try a faulty sensor. Type 150 into a potentiometer that runs from 0 to 100 and your logic gets 150, shown in amber so you can see it is outside the range.

The `Set to` part of the menu puts the value at its lowest, its default or its highest in one click.

### The ramp [#the-ramp]

A ramp is a potentiometer with a speed. Choose how long the whole range takes: 3, 10 or 30 seconds. When you put the value somewhere, it moves there at that speed while the program runs. A thin line on the bar shows where it is going, and the filled part shows where it is now.

For example, a level from 0 to 100 with a speed of 10 seconds rises by 10 every second. Put it from 20 to 60 and it arrives 4 seconds later, so you can watch your high-level alarm come on as the level passes it.

A ramp moves on the simulation's own clock, so it waits while the simulation is paused.

### Noise [#noise]

A real measurement flickers. Tick `Noise` in the menu and the value your logic reads moves a little around where you put it: three times a second, by up to one hundredth of the range. On a range of 0 to 100 that is up to 1 either way. Use it to check that an alarm does not switch on and off when the value sits right at its limit.

Noise is only there while the program runs. A small sign in the row shows when a ramp or noise is on, so a value that moves by itself is never a surprise. A value that moves never overwrites a field you are typing in.

You can change the speed, the range and the noise while the program runs. The simulation carries on.

### Number inputs with the keyboard [#number-inputs-with-the-keyboard]

| Key                | What it does                                       |
| ------------------ | -------------------------------------------------- |
| Tab                | Goes to the next input and selects its whole value |
| Enter              | Keeps what you typed                               |
| Escape             | Gives up what you typed                            |
| Up and Down arrows | Step the value                                     |
| Shift+arrow        | Steps ten times as far                             |
| Shift+F10          | Opens the menu of that input                       |

A step is 1 for a whole number. For a `REAL` potentiometer it is about one hundredth of the range, rounded to a round number: 1 for 0 to 100, 2 for -40 to 150, and 0.01 for 0 to 1. Stepping stays inside the range.

A tag shown in Hex, Binary or another style than a plain number stays a fixed value. A potentiometer needs a number line to drag along.

## InOut tags [#inout-tags]

An InOut tag belongs to the caller, so it has no default value. Instead, what you type into an InOut while the simulation is stopped is its **start value**. Studio saves it with the AOI and puts it back every time you press Start.

Every InOut can have a start value, arrays included. For a structured InOut, such as a `TIMER`, you type it into the members, such as `PRE`.

## Outputs and Local tags as lamps [#outputs-and-local-tags-as-lamps]

Your logic sets the Output and Local tags, so the panel only shows them. A `BOOL` is a single bit: it is 0 or 1. On a real machine a bit that is 1 often lights a lamp, and the panel can show it that way.

Two buttons on the `Outputs` and `Local` headings choose how a bit looks. They are one setting for both groups:

- **`0101`** shows each bit as its digit, `0` or `1`.
- **The four small rectangles** show each bit as a lamp: grey for 0, and green for 1, or amber while the simulation is paused. These are the same colours as a powered contact in a ladder rung. While the simulation is stopped, a lamp for 1 is a stronger grey than a lamp for 0, so you can still tell them apart.

One of the two is always on. With both on, each lamp has its digit on it.

A whole number shown in the Binary style gets a lamp for each of its bits. An `INT` that holds 5 reads `2#0000_0000_0000_0101`, so its first and third lamps from the right are lit. The members of a timer or a counter that are bits, such as `DN`, are lamps too.

The buttons do not change Input and InOut tags, because those are yours to set. The choice is kept in your browser, not in the AOI.

## What is saved [#what-is-saved]

The pilot devices and the start values are saved in the [`.rungs` file](https://rungs.dev/docs/studio/rungs-file-format#the-inoutstartvalues-and-pilotdevices-sections), so they come back when you open it again. An `.L5X` export leaves them out, because they describe the caller and not the instruction.

When you press Start, every pilot device goes back to where it starts: the position or the value that matches the tag's Default Value.