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.

---------->>>>>Get FREE PLC Programming Tips

New Here? Please read this important info!!!


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

PLC training tools sale

Reply
 
Thread Tools Display Modes
Old June 5th, 2015, 01:32 PM   #1
Mark Whitt
Member
United States

Mark Whitt is offline
 
Join Date: Jan 2013
Location: Columbus, OH
Posts: 30
S7: Add offset to Any Pointer for BLKMOV

Hello Folks!

I have an application where I need to copy a string into various locations within a DB. So, I've set up a Function Block to accept an Index number (I've called this #BO), an Any Pointer to the String to be copied (I've called this PTR_STRING) and a pointer to the BASE location within the DB where the indexing will start (add 84 bytes for every Index Increment).

What's happening is that the address offset is ignored and the string always gets copied to the Base Address. Obviously, there's something wrong with my STL code, but my inexperience with it is keeping me from seeing the problem. So, any help (pointers to those inclined towards puns) would be greatly appreciated!

Here's a pseudo code version of what I've done, with the STL code taken verbatim from the function.

IN Area:
PTR_BASE = Any Pointer // Any Pointer to DB base position (Index 0, the copy to here, Index 1 copy to [here + 84 bytes], etc).
BO = Int // Index value from 0 to 3. Used to calculate offset into DB.
PTR_STRING = Any Pointer // Any Pointer to string that we want to copy.


TEMP area:
pPTR_STRING = Any Pointer // Local Any Pointer to the string that will be copied.
pPTR_BASE = Any Pointer // Local Any Pointer that will be offset by an index times 84 bytes
dwtar2 = DWord // Save for AR2 register
Address_Offset = Int // Calculated Byte Offset
Return_Val = Int // Return value for BLKMOV
DB_no = Int // Data Block number. Not sure that this is needed.



// Convert pointer to string that we want to copy to a
// local pointer that BLKMOV can use.

TAR2 #dwtar2
L P##PTR_STRING
LAR1
LAR2 P##pPTR_STRING
L W [AR1,P#0.0]
T W [AR2,P#0.0]
L W [AR1,P#2.0]
T W [AR2,P#2.0]
L W [AR1,P#4.0]
T W [AR2,P#4.0]
L D [AR1,P#6.0]
T D [AR2,P#6.0]


// Use a Ladder rung to calculate offset in 84 bytes increments.
// So, if index comes in at 1 then add 84 bytes to the pointer
// that we'll be writing to.
//
MUL_I
IN1= #BO
IN2 = 84
OUT = #Address_Offset


// Now, take the destination pointer that was passed, convert it
// to a local pointer that BLKMOV can use, and add the Offset calculated above.
//
L P##PTR_BASE
LAR1

LAR2 P##pPTR_BASE // Pointer to the Array base we're writing to.
L W [AR1,P#0.0]
T W [AR2,P#0.0]
L W [AR1,P#2.0] // count

T W [AR2,P#2.0]
L W [AR1,P#4.0] // DB number
// Do I need an OPN DB here??
T W [AR2,P#4.0]
L D [AR1,P#6.0]
T D [AR2,P#6.0] // fetch area pointer
L #Address_Offset // Get the calculated Addres offset.
SLD 3 // Convert pointer to bytes
+AR2 // Add pointer to AR2

// Using Ladder for BLKMOV
SRCBLK = #pPTR_STRING // String to be copied
RET_VAL = #Return_Val // return code
DSTBLK = #pPTRBASE // Pointer into DB where the string should go.

Of course, there is a SAVE instruction at the end, and a LAR2 #dwar2 as well.

I did NOT put an open for the DB because I'm pretty sure that the BLKMOV already handles that - and the fact that the string shows up at the base address seems to confirm that.

I'm sure this is a simple matter of not understanding how to add an offset to the Any Pointer. Many thanks in advance!
__________________
Mark Whitt
  Reply With Quote
Old June 5th, 2015, 01:58 PM   #2
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: 5,477
Adding the offset to AR2 makes no sense, you have to add the offset to the area pointer of the anypointer, viz:
(untested).


Quote:
Originally Posted by Mark Whitt View Post

LAR2 P##pPTR_BASE // Pointer to the Array base we're writing to.
L W [AR1,P#0.0]
T W [AR2,P#0.0]
L W [AR1,P#2.0] // count

T W [AR2,P#2.0]
L W [AR1,P#4.0] // DB number
// Do I need an OPN DB here??
T W [AR2,P#4.0]

L #Address_Offset // Get the calculated Addres offset.
SLD 3 // Convert pointer to bytes
L D [AR1,P#6.0] //fetch area pointer
+D // Add offset
T D [AR2,P#6.0] // updated area pointer for block move

// Using Ladder for BLKMOV
SRCBLK = #pPTR_STRING // String to be copied
RET_VAL = #Return_Val // return code
DSTBLK = #pPTRBASE // Pointer into DB where the string should go.

Of course, there is a SAVE instruction at the end, and a LAR2 #dwar2 as well.

I did NOT put an open for the DB because I'm pretty sure that the BLKMOV already handles that - and the fact that the string shows up at the base address seems to confirm that.

I'm sure this is a simple matter of not understanding how to add an offset to the Any Pointer. Many thanks in advance!
  Reply With Quote
Old June 5th, 2015, 02:15 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: 5,477
Any particular reason you've used a function block as opposed to a function?

If you use the function block as a multiple instance your indirect addressing of the IN area will not work.

Also, you have modified AR2 and then attempted to access BO. Once you have modified AR2 in a function block, you cannot access any of the interface variables except the temp area. Create a temp variable TEMP_BO and copy BO to it at the start of your block - use TEMP_BO for the multiply.
  Reply With Quote
Old June 5th, 2015, 02:53 PM   #4
Mark Whitt
Member
United States

Mark Whitt is offline
 
Join Date: Jan 2013
Location: Columbus, OH
Posts: 30
Smile

Hello L D[AR2,P#0.0],

Once again you've saved my day (week?). I almost had it at one point myself, but put the +D in the wrong place so it didn't work. I AM learning, but very slowly!

I misspoke earlier. It was a function that I was using, not a function block. But I'm glad that you mentioned about the multiple instance causing the indirect addressing of the IN area to not work. While that's not a problem now, I'm sure that's a trap that I would have eventually fallen into.

Many thanks again!

BTW, shouldn't you be in the Pub by now? What are you doing answering questions on the forum at this hour? But I'm glad that you did!
__________________
Mark Whitt
  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 pointer queiry(contiued) lad_stl LIVE PLC Questions And Answers 12 February 2nd, 2014 12:48 PM
S7 Extract information from an ANY pointer in STL Rogier89 LIVE PLC Questions And Answers 5 December 19th, 2013 01:59 PM
S7: Problem with Pointer and indirect addressing douyi LIVE PLC Questions And Answers 18 February 2nd, 2010 04:17 AM
Reading pointer format in S7 Plc_User LIVE PLC Questions And Answers 1 June 15th, 2008 06:08 PM
S7 - Converting an INT to Byte.Bit Pointer Format RMA LIVE PLC Questions And Answers 10 February 18th, 2005 02:44 AM


All times are GMT -5. The time now is 04:33 AM.


.