S7, Function calls, and DB's...

rdrast

Lifetime Supporting Member
Join Date
Apr 2003
Location
South Carolina Lowcountry
Posts
5,544
I know there is a way to do this...but I'm sufferring from brain-lock at the moment, and can't remember how :)

I need to be able to pass a word value to a function call, and open up a datablock referenced by the word value for manipulation.

Essentially, I have DB100 through DB140, all very large, and identical. I want to pass say 100 to a function call to work with DB100 in it.

Passing BLOCK_DB doesn't work, as FC's can't take that as IN/OUT.

Can anyone point me in the right direction?

Thanks in advance
 
I just did something exactly like that.
I had to pass the DB number via an intermediary variable (MW100)

In declaration section:
CIM211_INBOX_DB INT

In code sction:
L #CIM211_INBOX_DB // Open the CIM 2.11 INBOX DB
T MW 100
OPN DB [MW 100]

 
Agree, there should be a more elegant way... but, uhhh...

You are only half a lifesaver I'm afraid. Now I find that I can indeed open the DB properly, and transfer values out of it, but nothing I write to it stays. /sigh

This is for the FM355-2 Temp/PID control module by the way, and interfacing many of them to an HMI. It seems now that while I can directly write the HMI value to the DB:

L DB30.Z1.Temp_SP
T DB100.OP.SP_RE

That works. So does the direct form of:

L DB30.DBD44
T DB100.DBD12

However, OPN'ing the DB in my function call and using it similarly:

L Temp_SP
T DBD12

doesn't work. I know I have the right DB open, as moving the actual PV out is fine.

Think this could be a problem that DBD12 (OP.SP_RE) is defined as static by the DB?

-- Edit...
In monitoring the actual values in the FC, the proper setpoint is being moved to the DB, but on exiting the FC, it reverts. I can also change it using a variable table. This is wierd.
 
I am using a shared DB, and I think you are using an instance DB.
If so you should use OPN DI in stead of OPN DB.
Dont know if that will make the difference though.

Also, if it would mean that you have to write with T DID in stead of T DBD, I dont know.
 
Hello Rdrast;

However, OPN'ing the DB in my function call and using it similarly:

L Temp_SP
T DBD12

If you OPN'ed DB30, this will write to DB30.DBD12. Is this what you nwant to do? You might have to complete the address to
T DB100.DBD12

Hope this helps,
Daniel Chartier
 
Okay, Yes, indeed, after exprimenting, I found I had to open the stupid data block as an INSTANCE (DI) block to allow writes to it.

Very strangely, moving values into it worked fine all through the function call (SP was constant inside the FC), but it would revert to the original values on exiting the FC.

This seems to imply to me that opening it as a DB was creating a local copy of it, whereas opening it as a DI acted more as a pointer to the actual Datablock.

/shrug... My head hurts, I'm going to run with it now.

Thanks for the help all :)
 
I think Daniel nailed it.

By the way, do you need to open ONE or TWO DBs "dynamically".
If you need to open TWO, then you could make use of OPN DB (shared) and OPN DI (instance). Together with L DBD, T DBD, L DID, TDID etc.. it allows you to manipulate two DBs.
 

Similar Topics

So I have a program for an Omron CJ1M PLC that I have to reverse engineer for a customer. This PLC is meant to control a water pump station...
Replies
2
Views
1,840
Is this possible? I'll use this scenario as an example. I have a function block that represents the behavior of an I/O card, say a 2 channel...
Replies
8
Views
2,209
I am new to programming the Siemens Step 7 Micro/Win software. But I found a useful subroutine albeit Function Call on the internet to provide...
Replies
5
Views
5,840
im having some trouble in one of my labs, what im stuck on is this... i need to turn on 3 outputs when the plc goes into run mode, using only two...
Replies
15
Views
6,273
Hi, I have attached herewith one image which our programmer has been used in S7 1500 PLC. Now we need to use the same instructions in S7 1200 PLC...
Replies
4
Views
118
Back
Top Bottom