You are not registered yet. Please click here to register!


 
 
plc storereviewsdownloads
This board is for PLC Related Q&A ONLY. Please DON'T use it for advertising, etc.
 
Try our online PLC Simulator- FREE.  Click here now to try it.

New Here? Please read this important info!!!


Go Back   PLCS.net - Interactive Q & A > PLCS.net - Interactive Q & A > LIVE PLC Questions And Answers

Reply
 
Thread Tools Display Modes
Old April 16th, 2021, 04:15 PM   #1
Dan123
Member
United States

Dan123 is offline
 
Join Date: Sep 2014
Location: California
Posts: 17
S7-300 SCL String Copy

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;
  Reply With Quote
Old April 16th, 2021, 05:15 PM   #2
Ken Moore
Lifetime Supporting Member
United States

Ken Moore is offline
 
Ken Moore's Avatar
 
Join Date: May 2004
Location: North, West, South Carolina
Posts: 3,070
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?
__________________
Certified Siemens Functional Safety Professional,
ID: SFSP17010238
https://azr.com/
  Reply With Quote
Old April 16th, 2021, 05:52 PM   #3
L D[AR2,P#0.0]
Lifetime Supporting Member
United Kingdom

L D[AR2,P#0.0] is offline
 
Join Date: Nov 2006
Location: UK
Posts: 6,241
How are you monitoring the string assignment result?


Does stringB stay at 'Hi' from the previous edit when you then use stringB:=stringA ?
__________________
S7-300 to 1500 conversions done - email to s7conversions@hotmail.com
  Reply With Quote
Old April 16th, 2021, 06:06 PM   #4
L D[AR2,P#0.0]
Lifetime Supporting Member
United Kingdom

L D[AR2,P#0.0] is offline
 
Join Date: Nov 2006
Location: UK
Posts: 6,241
Here's my working example (plcsim)
Attached Images
File Type: jpg strg1.jpg (177.6 KB, 58 views)
__________________
S7-300 to 1500 conversions done - email to s7conversions@hotmail.com
  Reply With Quote
Old April 19th, 2021, 09:13 AM   #5
Dan123
Member
United States

Dan123 is offline
 
Join Date: Sep 2014
Location: California
Posts: 17
Quote:
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.


Quote:
Does stringB stay at 'Hi' from the previous edit when you then use stringB:=stringA ?
Yes.

Last edited by Dan123; April 19th, 2021 at 09:16 AM. Reason: added clarification
  Reply With Quote
Old April 19th, 2021, 09:29 AM   #6
JesperMP
Lifetime Supporting Member + Moderator
Denmark

JesperMP is offline
 
JesperMP's Avatar
 
Join Date: Feb 2003
Location: Copenhagen.
Posts: 14,742
Quote:
Originally Posted by Dan123 View Post
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.

Quote:
Originally Posted by Dan123 View Post
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.
__________________
Jesper
See my profile interests for Q&A
  Reply With Quote
Old April 19th, 2021, 10:00 AM   #7
Dan123
Member
United States

Dan123 is offline
 
Join Date: Sep 2014
Location: California
Posts: 17
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.
Attached Images
File Type: jpg stringcopy.jpg (156.7 KB, 42 views)
  Reply With Quote
Old April 19th, 2021, 10:35 AM   #8
Dan123
Member
United States

Dan123 is offline
 
Join Date: Sep 2014
Location: California
Posts: 17
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?
  Reply With Quote
Old April 19th, 2021, 11:10 AM   #9
JesperMP
Lifetime Supporting Member + Moderator
Denmark

JesperMP is offline
 
JesperMP's Avatar
 
Join Date: Feb 2003
Location: Copenhagen.
Posts: 14,742
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.
__________________
Jesper
See my profile interests for Q&A
  Reply With Quote
Old April 19th, 2021, 11:25 AM   #10
JesperMP
Lifetime Supporting Member + Moderator
Denmark

JesperMP is offline
 
JesperMP's Avatar
 
Join Date: Feb 2003
Location: Copenhagen.
Posts: 14,742
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 ?
__________________
Jesper
See my profile interests for Q&A
  Reply With Quote
Old April 19th, 2021, 12:32 PM   #11
L D[AR2,P#0.0]
Lifetime Supporting Member
United Kingdom

L D[AR2,P#0.0] is offline
 
Join Date: Nov 2006
Location: UK
Posts: 6,241
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.
Attached Images
File Type: jpg strg2.jpg (119.1 KB, 24 views)
__________________
S7-300 to 1500 conversions done - email to s7conversions@hotmail.com
  Reply With Quote
Reply
Jump to Live PLC Question and Answer Forum

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Topics
Thread Thread Starter Forum Replies Last Post
S7 string challenge. Mike_Fantastic LIVE PLC Questions And Answers 3 March 11th, 2011 01:12 PM
s7 300 and 400 master slaving moazzim LIVE PLC Questions And Answers 16 April 10th, 2007 06:52 AM
S7 300 to wonderware connection gherz817 LIVE PLC Questions And Answers 1 January 25th, 2007 10:47 AM
Siemens S7 -> Copy RAM to ROM ? doowahdiddy LIVE PLC Questions And Answers 0 June 30th, 2005 04:29 AM
Siemens S7 300 sparky64 LIVE PLC Questions And Answers 3 May 5th, 2003 04:50 AM


All times are GMT -4. The time now is 06:06 AM.


.