STL programming seems to shift 2 characters

drip

Member
Join Date
Jan 2009
Location
canada
Posts
59
Hello,
I need some help with some STL programming for siemens simatic 5.4. I am bring in an ascii code from a module and it is being stored into a DB as individual characters. I am trying to convert these select a range of characters to make a string. I want to take the first 10 characters and store them as one string then take characters 12-23 to store as another string.

I am using the code below as a FC and entering the source and target DB as well as the start position. The problem is when I convert the characters to a string my position is off by 2 characters. I am pointing to the character located in db4.dbx0.0 but I get the character located in
db4.dbx2.0. So I can never bring in the first 2 characters from my serial number because I am reading the 3rd character with the 0 placement.

EX- serial - 123456789 in db 4 starting at 0.0
target db5
source db4
target position 0
source position 0

serial in db 5 starting at 0.0 is 3456789









L B#16#10 // Load the syntax ID and
T LB 0 // transfer it to the "Source" ANY pointer

L B#16#2 // Load data type Byte and
T LB 1 // transfer it to the "Source" ANY pointer

L #NumberOfBytes // Load number of bytes to transfer
T LW 2 // transfer it to the "Source" ANY pointer

L #SourceDB // Specify source DB
T LW 4 // transfer it to the "Source" ANY pointer

L #StartAdrSource //Start of the source
SLD 3
OD DW#16#84000000
T LD 6 // transfer it to the "Source" ANY pointer


Network 2

L B#16#10 // Load the syntax ID and
T LB 10 // transfer it to the "Target" ANY pointer

L B#16#2 // Load data type Byte and
T LB 11 // transfer it to the "Target" ANY pointer

L #NumberOfBytes // Load 160 bytes
T LW 12 // transfer it to the "Target" ANY pointer

L #TargetDB // Specify target DB
T LW 14 // transfer them to the "Target" ANY pointer

L #StartAdrTarget //Start of the source
SLD 3
OD DW#16#84000000
T LD 16 // transfer it to the "Target" ANY pointer


Network 3
CALL "BLKMOV"
SRCBLK :=#Source
RET_VAL:=#Errorcode
DSTBLK :=#Target
NOP 0


Network 4
A L 20.7
SAVE
BEC


Network 5

CLR
SAVE
 
Look at string datatype in s7 help. There is lenght information stored in it, so your first char in string is at offset of 2.
 
I think you are making it unnecessarily complicated with the ANY pointer.
You can manipulate the individual characters of a string, just make sure that max length is set in byte 1, and actual length are is set in byte 2.

Here is an example.
#str1 is a locally declared STRING address in an FB.
Code:
      L     B#16#20                     // max length 20hex=32dec
      T     #str1[1]
      L     B#16#5                      // actual length 5hex=5dec
      T     #str1[2]
      L     'h'                         // 'hello'
      T     #str1[3]
      L     'e'
      T     #str1[4]
      L     'l'
      T     #str1[5]
      L     'l'
      T     #str1[6]
      L     'o'
      T     #str1[7]
 
str1[1] references the first char in the string, not the first byte that contains the max string length.
 
You are right LD.
Dont know how I could get it to work the first time.
The 1st and 2nd byte cannot be accessed symbolically.
It must look something like this:
Code:
      L     B#16#20                     // string max length. May be omitted if the stringth if already initialised.
      T     DB1.DBB    0
 
      L     B#16#5                      // string actual length
      T     DB1.DBB    1
 
      L     'h'                         // 'hello'
      T     "test_DB1".string1[1]
      L     'e'
      T     "test_DB1".string1[2]
      L     'l'
      T     "test_DB1".string1[3]
      L     'l'
      T     "test_DB1".string1[4]
      L     'o'
      T     "test_DB1".string1[5]
 

Similar Topics

I'm new in STL programming, today I was checking some example codes and found this: L 1 L QB 4 SLW T QB 4 SET SAVE...
Replies
5
Views
2,559
Dear experts, I m new to the STL programming and I have a problem that I can not solve. I'm working on a program that controls the...
Replies
2
Views
2,700
Hello everyone! I've just stared with programming on STL and I have problem which I can't understand. I'm writing programs on Step 7 and I'm...
Replies
2
Views
2,176
Hello everyone! I've just stared with programming on STL and I have problem which I can't understand. I have this piece of code:
Replies
1
Views
1,939
I have a programming problem. I was originally asked to read and display a flowmeter with a 4-20mA o/p and display a continuous flow reading. The...
Replies
4
Views
2,344
Back
Top Bottom