Skip to main content

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. 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:

series4xseries5x
Display7-segment, 4 positions16-segment, 5 positions
Output fieldDisplay Digit 1 … Display Digit 4, one ASCII code per byteText to display, StringT with 6 bytes
Text output enabled byDisplay Mode = 2 (Digits given)Text Select = 2 (Text given)
PrerequisiteISDU LED Control Mode = Scene controlled by IO-Link Process Datanone

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 and OB1 for 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).

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 and series4x Process Data.

Function block "caneo_scroll_text"​

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​

NameData typeDescription
runBoolTRUE: the text scrolls. FALSE: the display shows the first characters of the text without moving.
messageString[64]Text to show, up to 64 characters. A new text starts scrolling from the beginning.
widthIntNumber of visible positions: 4 for series4x, 5 for series5x.
stepTimeTimeTime per scroll step, for example T#300MS.
displayTextArray[0..5] of CharVisible window. Position 0 is on the left. Positions from width onwards are always blank.
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​

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.

Organization block "Main" for series4x​

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.

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.

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.

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 apply here as well.


Troubleshooting​

SymptomCause and solution
series4x: the display ignores the process dataLED Control Mode is still Automatic Scene selection. Set it to Scene controlled by IO-Link Process Data in S7-PCT and load the configuration.
series4x: some characters are shown incorrectlyThe character is not displayable on the 7-segment display. Use a different character or a custom segment pattern (see series4x Display Content).
series5x: the display shows a number or a scene textText Select is not 2. Check the assignment in OB1.
displayText changes in the watch table, but the display does notCheck the IO-Link communication and the addresses of PDout, as described in the troubleshooting section of the series5x guide.
The text does not moverun is FALSE, or stepTime is 0 or very long.

Reference​


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.

SiemensS7CaneoScrollText.zip