Handling Strings in Siemens S7

ThePortLion

Member
Join Date
Oct 2007
Location
Ireland
Posts
58
Hi

I have been using Siemens S7 317 PLC's for quite a while
but this is the first time i've had to do anything with strings.
I basically need to load a text string into a db. I have
the string field defined in the db but cant seem to work out
how to write text into it.

Any help would be appreciated
Thanks
 
In a Strig, you can not use the first 2 Bytes. Byte 0 is used for the total length of the string and Byte 1 is used for the total length of the of the text.
 
Thanks for the response. ok. I'm aware of the structure of String type, but can you tell me exactly how to write (in STL) a text string into the data area?
i.e. I'm not familiar with the syntax used on strings
 
Last edited:
It's ok. Could i see a couple of lines of code where text is written
to a db string address? I ask because any examples i've seen are to do with reading string values. I just need a starting point.

Thanks again.
 
If you PM me your email, I can send you a sample project from Siemens. It's about 5 MB
 
You will have found out by now that you cannot morely write
L 'some text"
T "MyDB".MyString

You can handle strings in STL by manipulating the individual BYTEs as CHARs. But it is very cumbersome.
If the strings can be predefined in another DB, then it is fairly simple to copy the strings about with SFC20.

If you need to do a lot of string handling, then it is one of the reasons to get SCL. It is very easy in SCL.
You can really write for example
"MyDB".MyString := 'some text" ;
 
Hi

I basically need to load a text string into a db. I have
the string field defined in the db but cant seem to work out
how to write text into it.

Specify the processing you require in more detail - the above description does not require SCL. Here's a DB with some text loaded into it. No processing required.

fox.jpg
 
okay. I am running a wash process on a plant. I need to loadd
the wash step descriptions into the DB (e.g. "Rinsing" or
"Circulating") as the wash steps occur. I am only using one string db address. I am not using HMI for this.
 
Last edited:
I am guessing you have one or more addresses that require the string content to vary dynamically.
I.e. "VisuStrings".string1, "VisuStrings".string2 etc.

There are two ways:

1. Define all the strings in a dedicated DB, like in LD's example above.
Then, whenever you need to transfer a string to the address you copy from the predefined texts to the active text with SFC20:
Code:
      CALL  "BLKMOV"
       SRCBLK :="FixedStrings".string1
       RET_VAL:=MW10
       DSTBLK :="VisuStrings".string2
The disadvantage is that you have to look up the strings in the "FixedStrings" DB when you are coding.

2. To code the content of the string together with the other code could be done by manipulating the individual chars and the length byte. But it is way too cumbersome.
In stead you can use SCL where you can write in code
Code:
      "VisuStrings".String1 := 'Hi there' ;

edit: I recommend that you use method 1. You are probably coding some sequences for your washing proces, and for that you are probably using regular STL, LAD or FBD.
 
Last edited:

Similar Topics

I am trying to get Codesys to work with a couple of Moxa ioLogik E1200 series DIO devices (E1210 and E1211). I am able to write to the E1211 DOs...
Replies
2
Views
173
The objective: Reach about 10’ horizontally into a 1300F furnace, and pick up a 140lb rectangular container, then pull the container back out of...
Replies
15
Views
1,870
Hello All, I don't so much have a problem more my OCD. I have a project, with over 1000 alarms. I create arrays in the PLC/HMI for my alarm...
Replies
0
Views
566
I hope somebody might be able to help me who has done some IO-Link messaging using an S7-1500 (TIA Portal 17) and the CMx8 IOLink module for the...
Replies
11
Views
1,794
Just a little bored, so I thought I would start a thread in one way of using recipes in batching processes, I'm aware there are probably many ways...
Replies
0
Views
589
Back
Top Bottom