S7: Calculate and output pointer using Function

Hoffelhass

Member
Join Date
Sep 2011
Location
Home
Posts
13
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
 
Post a screen shot showing the error. A pointer is defined as 32 bits yet you are loading a 16 bit word from the DB
 
Last edited:
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!
 
Post screen shots or the code....

e.g. Here's my function with an output of type pointer - you cannot transfer to a pointer.

cccc.jpg
 
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.
 
Thanks L D[AR2,P#0.0]! My workday is ending now, so I'll have to take a closer look at it tomorrow. I'll post back after I've analyzed it :)
 

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...
Replies
7
Views
20,138
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...
Replies
4
Views
4,828
Hi everyone, This is my first time posting, so please forgive any omissions or mistakes. I am attempting to control the velocity of a stepper...
Replies
18
Views
986
Good morning, I have a question. I don't know much about ST yet I would like to calculate the average number of products per hour. how do I do...
Replies
22
Views
2,952
Can someone help me with this? I'm no good at SCL - virtually everything I've done so far has been ladder logic. The return value from the...
Replies
13
Views
1,104
Back
Top Bottom