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 March 10th, 2011, 06:20 PM   #1
Mike_Fantastic
Member
Canada

Mike_Fantastic is offline
 
Join Date: Dec 2010
Location: Toronto
Posts: 8
S7 string challenge.

Hey Guys.

I am creating a FB which has a STRING (254) in the STAT. I was able to create the string without seeing red in STAT. However I cannot Load it to Memory.

I can:
// I can move 4 Bytes into MD.
L ‘MIKE’
T MD0

But I CANNOT:
Local symbol in STAT: First_Ch | String(254) | 48.0 | ‘THIS IS MY STRING. HELP!!!’
L #First_Ch
T ??????

S7 Help tells me: “If a temporary variable of the data type STRING was defined, the byte "max. length" must be written with the defined length before using the variable in the user program.”

1. 1) What does this help mean?
2. 2) Is it possible to put a string larger than a Double Word into a Memory Adddress?
3. 3) If possible can you please show me how?


Huge thanks in advance!!!
  Reply With Quote
Old March 10th, 2011, 06:59 PM   #2
JesperMP
Lifetime Supporting Member + Moderator
Denmark

JesperMP is offline
 
JesperMP's Avatar
 
Join Date: Feb 2003
Location: Copenhagen.
Posts: 14,834
Coding STRINGs in STL is a real pain.
For copying STRINGs from adresses to adresses you should use SFC20 BLKMOV. For other tasks there are lots of STRING functions in the IEC library.

The
L 'Mike'
doesnt really load a STRING. It really just loads 4 CHARs into a doubleword address. Thats why it cannot be longer than 4 bytes / 4 CHARs.

In STL it is not possible to directly write
L 'hi there'
T #MyString

You can only copy STRING values that already exist, predefined in a DB.
To modify STRING values in STL will require that you write each CHAR in the STRING, and set the second byte to the actually used number of CHARs.
It is really a chore.

The bit about the STRING TEMP is because the 1st byte MUST be the max length of the STRING. And since TEMPs dont have memory or initial values, you have to do it manually in code.

If you have SCL, it is dead easy.
You can really write something like
MyString := 'Hi there' ;
MyString2 :=MyString ;
__________________
Jesper
See my profile interests for Q&A
  Reply With Quote
Old March 10th, 2011, 07:05 PM   #3
JesperMP
Lifetime Supporting Member + Moderator
Denmark

JesperMP is offline
 
JesperMP's Avatar
 
Join Date: Feb 2003
Location: Copenhagen.
Posts: 14,834
Just as an example, here is how you would have to load a fixed text value into a STRING:

Code:
      L     B#16#20                     // max length
      T     #str1[1]
      L     B#16#5                      // actual length
      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]
__________________
Jesper
See my profile interests for Q&A
  Reply With Quote
Old March 11th, 2011, 01:12 PM   #4
Mike_Fantastic
Member
Canada

Mike_Fantastic is offline
 
Join Date: Dec 2010
Location: Toronto
Posts: 8
Thank You Jasper.
I have started using SFC20.
  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 Output from FC pethoek LIVE PLC Questions And Answers 2 March 30th, 2010 07:05 AM
S7 Copy string from DB to Local pethoek LIVE PLC Questions And Answers 4 April 9th, 2009 09:35 AM
Problem reading string using IBH S7 Link (mpi to ethernet) using IBH OPC Server islman1975 LIVE PLC Questions And Answers 4 December 9th, 2008 08:14 AM
S7 224 - Storing String variables in a program ltrail LIVE PLC Questions And Answers 4 November 30th, 2004 07:18 PM
Problem with S7 STRING to REAL conversion RMA LIVE PLC Questions And Answers 55 October 4th, 2004 10:51 PM


All times are GMT -4. The time now is 02:11 PM.


.