S7: Calculate and output pointer using Function

Hey everybody,

I've been trying to write a function in STL that takes an indexnumber and a UDT type to calculate a pointer to specific UDT in a DB.

I do this by multiplying the indexnumber with the UDT size and using that as the offset in the DB.

L #IndexNumber
L "DB_Constants_Typicals".DigIn.Size
*I
SLD 3
T #Offset
OPN "SETTINGS_DigIn"
L DBW [#Offset]
T #ControlPointer

Where #ControlPointer is the pointer I want as the output of my function.

I based this largely on a previous post here by S7guy.
This code however gives me the error: "Make sure your global DB is set correctly". However just a line above it I state that I open DB "SETTINGS_DigIn". Am I missing something?

Thanks in advance
 
When I reopened the project to take the screenshot the error no longer showed up. It did show an error stating "Statement not permitted for DWORD/DINT indir. instruction addresses"

When I changed the #Offset variable to a DINT instead of an INT I was able to use the L DBW [#Offset] statement.

Now I just need to output the address of that databaseword. I figured using SLD 3 again and transferring that to #ControlOffset should work.
It's not giving me a syntax error for it, but I'm not sure if this will work. What are your thoughts on this?

Thanks!
 
Tbanks for you answers so far.

My code looks like the attached file. It doesn't give immediate compilation errors, just this error when I try to save.

screenshot.png
 
Noticed that myself after a while :)

I've been reading into ANY pointers with BLKMOV. I want to use my calculated offset to create an ANY pointer to a UDT and then outputting that UDT using BLKMOV with the pointer as input and the UDT as output.

This should be possible, correct? I just can't figure out how to construct this pointer. The examples I've seen seem to first create a pointer to the start of the DB, and then edit the pointer itself to get a correct offset. Am I reading this correctly?

The examples I've been looking at:
http://www.plctalk.net/qanda/showthread.php?t=25919
http://www.plctalk.net/qanda/showpost.php?p=169469&postcount=8
http://www.plctalk.net/qanda/showpost.php?p=157624&postcount=7
http://www.plctalk.net/qanda/showthread.php?t=39397
http://www.plcdev.com/siemens_s7_indirect_addressing

Note: I have to make this in STL since I don't have access to SCL.
 
I'm not quite sure what you want to achieve.

Am I correct in thinking that you would like to transfer a specific UDT instance specified by an index number, from a data block containing multiple instances, to a destination which is another instance of the same UDT?

Nick
 
what's the A( .. ) for, all the instructions after it are unconditional so I don't know what the A( .. ) is achieving.

It would be helpful if your screenshot showed the parameters so we knew what format each of the variables are.
 
@Manglemender:
That is correct, preferably I would have a function return a pointer to that UDT, so that I can edit it directly from within the calling FB, but I think this isn't possible (FC's can't output pointers as far as I understand?). So the next best thing would be to copy the UDT to a temporary instance, edit that one and later copy it back to the DB.

@PeterW:
You're right. I think the A( ) was a remnant of me starting the function in FBD and later converting that to STL. I've removed it now, it didn't have any function anymore.

Thanks for your quick replies

PDF with function attached.
 

Similar Topics

Hi. I have a Kwh meter with puls output. it give 1000 pulses for each Kwh. If I have the meter measuring 1 kw load, then it takes 1Hour to...
7
Replies
23,712
Views
I have motor/mechanical variable speed pulley/gearbox drive system that I do not know how to calculate the output torque capability of. The system...
4
Replies
5,469
Views
CALCULATION QUESTION If my machine is running 1000 fpm and my decel ramp rate is 30fps/sec does the calc 1000/30= 33.33334 = time in seconds to 0...
13
Replies
1,250
Views
D.OUT: 5000 -> 2214 ->662 -> -888; X = ACTUAL= -100; SET_POINT = 0; Error = 100; D.OUT = 5000 = 100 / 0.02; Y = 0.1*(100 + 0.04 * 5000) = 30; X =...
7
Replies
1,387
Views
Hi Everybody, i am beginner PLC programmer (i use ladder diagram Machine Expert Basic)). And i use Modicon M221 Plc. I have an Encoder for...
7
Replies
1,826
Views
Top