<!-- Source: https://docs.captron.com/application-notes/CaneoSeries4x5x-siemens-s7-scroll-text -->

# CANEO series4x / series5x + Siemens S7 — Scrolling Text Function Block

The displays of CANEO series4x and series5x sensors show only a few characters at a time: 4 on the 7-segment display of series4x, 5 on the 16-segment display of series5x. Longer texts such as `HELLO CAPTRON` do not fit. This guide shows a small SCL function block that moves any text across the display step by step, controlled entirely by the PLC through IO-Link process data.

By the end, you will have:

- the function block `"caneo_scroll_text"`, which works for both product series,
- an organization block `"Main"` (OB1) for either a series4x or a series5x device,
- a display that scrolls a text of up to 64 characters from right to left with adjustable speed.

:::info
This guide builds on [CANEO series5x + Siemens S7-1200](CaneoSeries5x-siemens-s7-1200-application-example). Follow steps 1 to 7 there to configure the IO-Link port in S7-PCT and to create the `PDin` and `PDout` tags. The steps are the same for a series4x device; only the IODD and the process data members differ.
:::

## One block for both series

The scrolling logic is the same for both series: a timer moves a window over the text, and the characters inside the window go to the display. Only the last step differs, the way the characters are written into the process data:

<table>
  <thead>
    <tr>
      <th></th>
      <th>series4x</th>
      <th>series5x</th>
    </tr>
  </thead>
  <tbody>
    <tr><td>Display</td><td>7-segment, 4 positions</td><td>16-segment, 5 positions</td></tr>
    <tr><td>Output field</td><td><code>Display Digit 1</code> … <code>Display Digit 4</code>, one ASCII code per byte</td><td><code>Text to display</code>, <code>StringT</code> with 6 bytes</td></tr>
    <tr><td>Text output enabled by</td><td><code>Display Mode</code> = 2 (Digits given)</td><td><code>Text Select</code> = 2 (Text given)</td></tr>
    <tr><td>Prerequisite</td><td>ISDU <b>LED Control Mode</b> = <code>Scene controlled by IO-Link Process Data</code></td><td>none</td></tr>
  </tbody>
</table>

The function block therefore has one generic output, `displayText : Array[0..5] of Char`, and an input `width` for the number of visible positions. The function block is called in the organization block `"Main"` (OB1), the cyclic main program of the CPU. OB1 copies the window into the process data of the respective series, see [OB1 for series5x](#ob1-series5x) and [OB1 for series4x](#ob1-series4x). This way there is only one block to maintain, and the series-specific mapping stays in a few lines of OB1.

## Prerequisites

- **TIA Portal** with a project for an S7-1200 or S7-1500 CPU and an IO-Link master, for example an **SM 1278 4xIO-Link master**.
- A **CANEO series4x Display** variant or a **CANEO series5x** variant with 16-segment display, configured in **S7-PCT**.
- The PLC tags `PDin` and `PDout` with the PLC data types exported by S7-PCT. For series5x, **Text to display** must be changed to `Array[0..5] of Char` (see [Fix the STRING error](CaneoSeries5x-siemens-s7-1200-application-example#fix-the-string-error)).

### Additional step for series4x

The series4x evaluates the display fields of the process data only in the LED control modes **Scene controlled by IO-Link Process Data** and **Advanced control by IO-Link Process Data**. In the default mode `Automatic Scene selection`, the process data output is unused.

In S7-PCT, open the **Parameters** tab of the port, set **LED Control Mode** to `Scene controlled by IO-Link Process Data`, and click **Load**. Export the PLC data types only after this change, because the layout of the process data output depends on the LED control mode. See [series4x LED Control](/trms/series4x/led-control) and [series4x Process Data](/trms/series4x/process-data).

## Function block `"caneo_scroll_text"`

```pascal
FUNCTION_BLOCK "caneo_scroll_text"
{ S7_Optimized_Access := 'TRUE' }
VERSION : 1.0
   VAR_INPUT
      run : Bool;                         // TRUE = scroll, FALSE = show the start of the text
      message : String[64];               // text to show
      width : Int := 5;                   // visible positions: 4 = series4x, 5 = series5x
      stepTime : Time := T#300MS;         // time per scroll step
   END_VAR

   VAR_OUTPUT
      displayText : Array[0..5] of Char;  // visible window, position 0 = left
   END_VAR

   VAR
      stepTimer {InstructionName := 'TON_TIME'; LibVersion := '1.0'} : TON_TIME;
      stepTick : Bool;                    // TRUE for one call when stepTime has elapsed
      pos : Int;                          // scroll position, 0 .. msgLen + w - 1
      lastMessage : String[64];
   END_VAR

   VAR_TEMP
      w : Int;
      msgLen : Int;
      i : Int;
      j : Int;
   END_VAR

BEGIN
   #w := LIMIT(MN := 1, IN := #width, MX := 6);
   #msgLen := LEN(#message);

   // Start again from the beginning when the text changes
   IF #message <> #lastMessage THEN
      #pos := 0;
      #lastMessage := #message;
   END_IF;

   // Step timer: restarts itself after each step.
   // Read Q only once per call, the CPU re-evaluates it on every access.
   #stepTimer(IN := #run AND NOT #stepTick,
              PT := #stepTime);
   #stepTick := #stepTimer.Q;

   IF NOT #run THEN
      #pos := #w;                         // first character at the left edge
   ELSIF #stepTick THEN
      #pos := #pos + 1;
      IF #pos >= #msgLen + #w THEN
         #pos := 0;                       // one blank frame, then the text enters again
      END_IF;
   END_IF;

   // Copy the visible part of the text into the window
   FOR #i := 0 TO 5 DO
      #j := #pos + #i - #w;               // 0-based index into message
      IF #i < #w AND #j >= 0 AND #j < #msgLen THEN
         #displayText[#i] := #message[#j + 1];   // STRING index starts at 1
      ELSE
         #displayText[#i] := ' ';
      END_IF;
   END_FOR;
END_FUNCTION_BLOCK

DATA_BLOCK "caneo_scroll_text_DB"
{ S7_Optimized_Access := 'TRUE' }
VERSION : 1.0
"caneo_scroll_text"
BEGIN
END_DATA_BLOCK
```

### Inputs and outputs

<table>
  <thead>
    <tr>
      <th>Name</th>
      <th>Data type</th>
      <th>Description</th>
    </tr>
  </thead>
  <tbody>
    <tr><td><code>run</code></td><td><code>Bool</code></td><td><code>TRUE</code>: the text scrolls. <code>FALSE</code>: the display shows the first characters of the text without moving.</td></tr>
    <tr><td><code>message</code></td><td><code>String[64]</code></td><td>Text to show, up to 64 characters. A new text starts scrolling from the beginning.</td></tr>
    <tr><td><code>width</code></td><td><code>Int</code></td><td>Number of visible positions: <code>4</code> for series4x, <code>5</code> for series5x.</td></tr>
    <tr><td><code>stepTime</code></td><td><code>Time</code></td><td>Time per scroll step, for example <code>T#300MS</code>.</td></tr>
    <tr><td><code>displayText</code></td><td><code>Array[0..5] of Char</code></td><td>Visible window. Position 0 is on the left. Positions from <code>width</code> onwards are always blank.</td></tr>
  </tbody>
</table>

:::tip[Scroll speed]
The scroll speed is set with `stepTime`: a shorter time scrolls faster, a longer time slower. The examples below use `T#300MS` for series5x and `T#400MS` for series4x.
:::

### How it works

The function block treats the text as a tape that runs through a window of `width` positions. The scroll position `pos` determines which part of the tape is visible:

- At `pos` = 0 the window is empty.
- With every step, the text moves one position to the left. It enters from the right edge.
- After the last character has left the window on the left, `pos` starts again at 0. There is always one blank step between two passes.

The step timer `stepTimer` restarts itself: when `stepTime` has elapsed, `stepTick` is `TRUE` for exactly one call, and the next call starts the timer again. One scroll step therefore takes `stepTime` plus one PLC cycle. The block reads the timer output `Q` only once per call and keeps the result in `stepTick`. The S7-1200 re-evaluates `Q` on every access, so a second read in the same call can return a different value and scroll steps get lost.

The block has no fixed addresses. For several displays, create one instance data block per display.

## Organization block `"Main"` for series5x {/* #ob1-series5x */}

```pascal
ORGANIZATION_BLOCK "Main"
{ S7_Optimized_Access := 'TRUE' }
VERSION : 1.0
BEGIN
   // series5x: 5 visible positions on the 16-segment display
   "caneo_scroll_text_DB"(run := TRUE,
                          message := 'HELLO CAPTRON',
                          width := 5,
                          stepTime := T#300MS);

   // Display: Text Color 3 = Blue, Text Select 2 = Text given
   "PDout"."Display Control - Text Color" := 16#03;
   "PDout"."Display Control - Text Select" := 16#02;
   "PDout"."Display Control - Text to display" := "caneo_scroll_text_DB".displayText;
END_ORGANIZATION_BLOCK
```

`displayText` and **Text to display** have the same data type, so a single assignment copies all characters. **Text Select** = **Text given** (2) makes the display show this text instead of a number or a scene text. See [series5x IO-Link Process Data](/trms/series5x/io-link-process-data).

## Organization block `"Main"` for series4x {/* #ob1-series4x */}

```pascal
ORGANIZATION_BLOCK "Main"
{ S7_Optimized_Access := 'TRUE' }
VERSION : 1.0
BEGIN
   // series4x: 4 visible positions on the 7-segment display
   "caneo_scroll_text_DB"(run := TRUE,
                          message := 'HELLO',
                          width := 4,
                          stepTime := T#400MS);

   // LED Control Mode = Scene controlled by IO-Link Process Data
   // LED Scene 255 = Automatic, Display Mode 2 = Digits given
   // Use the member names that S7-PCT shows for your device.
   "PDout"."LED Scene" := 16#FF;
   "PDout"."Display Mode" := 16#02;
   "PDout"."Display Digit 1" := CHAR_TO_BYTE("caneo_scroll_text_DB".displayText[0]);
   "PDout"."Display Digit 2" := CHAR_TO_BYTE("caneo_scroll_text_DB".displayText[1]);
   "PDout"."Display Digit 3" := CHAR_TO_BYTE("caneo_scroll_text_DB".displayText[2]);
   "PDout"."Display Digit 4" := CHAR_TO_BYTE("caneo_scroll_text_DB".displayText[3]);
END_ORGANIZATION_BLOCK
```

The series4x expects one ASCII code per display digit. `CHAR_TO_BYTE` converts each character of the window into its ASCII code. **LED Scene** = 255 leaves the LED ring to the automatic scene selection, and **Display Mode** = **Digits given** (2) makes the display show the four digits. See [series4x Process Data](/trms/series4x/process-data).

:::note
The member names of `PDout` depend on the IODD and on the LED control mode. S7-PCT may add a prefix to them, as it does for series5x (`Display Control - …`). Always use the names that S7-PCT shows for your device.
:::

:::warning[Character set of the series4x]
The 7-segment display cannot show all letters. For example, `K`, `M`, `N`, `R`, `V`, `W`, `X`, and `Z` are not displayable as capital letters, while `n` and `r` are displayable in lower case. Choose texts from the displayable characters listed in [series4x Display Content](/trms/series4x/display-content).
:::

## Generate the blocks and test

1. Add `caneo_scroll_text.scl` and **one** of the two OB1 files (`main_series4x.scl` or `main_series5x.scl`) under **External source files → Add new external file**.
2. Generate `caneo_scroll_text.scl` first, then the OB1 file, because OB1 refers to the instance data block `"caneo_scroll_text_DB"`.
3. Compile and download the hardware and software (only changes).
4. Go online, add `"caneo_scroll_text_DB".displayText` to a watch table, and click **Monitor all**.

The text moves across the display from right to left. Set `run` to `FALSE` to stop it: the display then shows the first characters of the text. A different `message` starts scrolling from the beginning.

The rules for external SCL sources (CRLF line endings, ASCII only) from the [series5x guide](CaneoSeries5x-siemens-s7-1200-application-example#generate-the-blocks) apply here as well.

---

## Troubleshooting

<table>
  <thead>
    <tr>
      <th>Symptom</th>
      <th>Cause and solution</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>series4x: the display ignores the process data</td>
      <td><b>LED Control Mode</b> is still <code>Automatic Scene selection</code>. Set it to <code>Scene controlled by IO-Link Process Data</code> in S7-PCT and load the configuration.</td>
    </tr>
    <tr>
      <td>series4x: some characters are shown incorrectly</td>
      <td>The character is not displayable on the 7-segment display. Use a different character or a custom segment pattern (see <a href="/trms/series4x/display-content">series4x Display Content</a>).</td>
    </tr>
    <tr>
      <td>series5x: the display shows a number or a scene text</td>
      <td><b>Text Select</b> is not 2. Check the assignment in OB1.</td>
    </tr>
    <tr>
      <td><code>displayText</code> changes in the watch table, but the display does not</td>
      <td>Check the IO-Link communication and the addresses of <code>PDout</code>, as described in the troubleshooting section of the <a href="CaneoSeries5x-siemens-s7-1200-application-example#troubleshooting">series5x guide</a>.</td>
    </tr>
    <tr>
      <td>The text does not move</td>
      <td><code>run</code> is <code>FALSE</code>, or <code>stepTime</code> is 0 or very long.</td>
    </tr>
  </tbody>
</table>

---

## Reference

- [CANEO series5x + Siemens S7-1200](CaneoSeries5x-siemens-s7-1200-application-example)
- [series4x Process Data](/trms/series4x/process-data)
- [series4x Display Content](/trms/series4x/display-content)
- [series5x IO-Link Process Data](/trms/series5x/io-link-process-data)

---

## Download: example sources

The SCL sources used in this guide: `caneo_scroll_text.scl` (function block and instance data block), `main_series4x.scl`, and `main_series5x.scl` (OB1 for each series). All files use CRLF line endings and can be added as external sources right away.

<a href="/downloads/SiemensS7CaneoScrollText.zip" target="_blank">SiemensS7CaneoScrollText.zip</a>
