S7-300 SCL String Copy

Dan123

Member
Join Date
Sep 2014
Location
California
Posts
17
I feel like I'm going crazy, new to Siemens, coming from AB, and I cannot get a dang string copied in SCL.


This is a S7-300, V16 PLC. I have a FB with an Input tag #StringA that is String[98], that I'm trying to store into a Static tag #StringB (that is also String[98]).


This works great

Code:
#StringB := 'hi';


This doesn't work at all
Code:
#StringB := #StringA;
 
Lots of questions.
Since this is in a FB, the String value is stored in an instance DB.
Have you tried assignment of the DB value to StringB? Have you declared StringB correctly?
 
How are you monitoring the string assignment result?


Does stringB stay at 'Hi' from the previous edit when you then use stringB:=stringA ?
 
Have you tried assignment of the DB value to StringB?
I think I'm getting somewhere -- the input value appears to actually be hexadecimal, it has the format X#(A0 A0 ...), up to 98 hex bytes. So I can't actually assign that as a constant to StringB. I'm not sure how it gets that format, and it seems like this might point to the issue, but I figure if the input string can hold that data, the static string should as well.


There is actually some other code in ladder that uses BLKMOV to copy String data to 'Array of Byte' data and back to String data, which appears to work. But when I try to do the same thing in SCL, it does not work (getting error 8122).


I have declared StringB correctly as a static tag, matching StringA data type.


Does stringB stay at 'Hi' from the previous edit when you then use stringB:=stringA ?
Yes.
 
Last edited:
I think I'm getting somewhere -- the input value appears to actually be hexadecimal, it has the format X#(A0 A0 ...), up to 98 hex bytes. So I can't actually assign that as a constant to StringB. I'm not sure how it gets that format, and it seems like this might point to the issue, but I figure if the input string can hold that data, the static string should as well.
Not sure where you get this from.
Maybe you are observing in a watch table ? You cannot observe a STRING in a watch table, but you can observe the individual CHARs by their absolute addresses. Maybe this is what you are referring to.

Whatever the old code does, it is higly recommended to work 100% with STRINGs and not mix with for example ARRAYs of CHARs or something like that - unless one knows what one is doing.

There is actually some other code in ladder that uses BLKMOV to copy String data to 'Array of Byte' data and back to String data, which appears to work. But when I try to do the same thing in SCL, it does not work (getting error 8122).
Is this code that is converted from an S7-300 Classic program ? Maybe written in LAD and not in SCL ?
I recommend to simply ditch the old code and write new in SCL.
STRINGs are easy and best programmed in SCL. The SCL compiler will take care of converting to BLKMOV or similar as needed. Dont write code with BLKMOV in SCL. Have you looked at LD's suggestions ?

If you cannot get it to work (by using LD's suggestions) then post your code.
 
I've made a separate block as simple as possible, to match LD's code, and attached it. The only difference I can see is that in his Monitor view, it's a normal string, whereas the data I'm trying to copy is in this X#(00 00 ...) format.



I believe the input data to the FB is being written externally, so possibly that is why it's in the weird format?



I'm still coming up to speed on Siemens terminology, if by Classic you mean like an older Step7 version, then I believe the answer is yes. Most of the code is in LAD and STL, and this is actually part of an effort to move to SCL. I was hoping that string manipulation would be much easier in SCL, but this simple example is giving me headaches, so I'm wondering if it should just be left in LAD with the BLKMOVs.

stringcopy.jpg
 
Ah I think I'm getting closer -- I believe I read somewhere that the first 2 characters of a string are supposed to be length or something? So this input is throwing the PLC off because it just starts right at the data. If I do RIGHT or LEFT (with length 98), it gives me the same set of data, starting at 'S' (ASCII 53 in Hex), dropping off the first 2 characters that it incorrectly interprets as 'length'. Those aren't the actual length, which explains why the string copy doesn't work. Which is probably also why it is done with a BLKMOV elsewhere.


So now the question becomes -- how do I copy the FULL set of data (including the first 2 characters) in SCL?
 
You are doing it correctly already
#StringB := #StringA ;

I am not used to work with the old-style S7-300 CPUs with TIA.
In STEP7 Classic you cannot monitor a STRING online, except for as stated before by the individual CHARs. It looks like TIA automatically display the individual chars.
If you have an HMI, you can display the STRINGs on the HMI and they will display correctly, as STRINGs and not as CHARs.
 
It is possible that TIA cleverly ignores the first two bytes when displaying the string value online.
The hexadecimal character array 2450534D3331 converts to the characters $PSM3.
Does $PSM3 look like something that could be in StringA ?
 
We need to see the code that calls your FB. Here's my example.
It will be a lot quicker if you create a cut down project that only contains the blocks giving the problem and post it as an attachment.

strg2.jpg
 

Similar Topics

I am trying to take several individual CHAR bytes and turn them into a string. The CHAR bytes are located in a DB. I am trying to figure out the...
Replies
4
Views
3,465
Dear Sir, I try to write a function use SCL to read the string from a DB and convert it to real and transfer to another DB. But the simple...
Replies
34
Views
24,922
How to realize transformation functions : 1/s and 1/(1+s) into SCL inside S7-300
Replies
0
Views
933
Hi. I tryid to make a shiftregister with 31 entry's. the string array are declared in the Static area of the FB. When I run the code its not...
Replies
1
Views
1,272
Looking for some help with an array of strings in SCL. I have an array of 99 string[98] I also have an array of 99 INT My first 4 chars of the...
Replies
9
Views
2,403
Back
Top Bottom