S7 (OPN DB) indirectly...?

Johnny T

Member
Join Date
Jul 2003
Location
Fife, Scotland
Posts
642
Hi

Does anyone know if you can use the OPN datablock command indirectly.

I have a number in an address at DB80.DBW6 and I basically want to open the DB that corresponds to this number.

I've tried...

 
DB[DB80.DBW6]
------------------------------------(OPN)



... but it doesn't accept it.

Any ideas on how to do this?

I know I could use some comparators to check the value of DB80.DBW6 and then use a marker and have a separate OPN command for each value but there are 32 different DB's I need to open so I was looking for a more elegant solution.

Cheers

JT :)
 
I may be wrong (it has been known :D) but I believe you can only do it in STL, then it would look something like this:

Code:
L #DB_Number //DB-Nr passed over as Parameter
T #DB_Number_TEMP //Temp store 
L P##Address //Address in the DB, e.g. DBWx.0, or P#10.0
LAR1 //Store in Address register 1
L D[AR1,P#2.0] //Load the Area Pointer
LAR1
OPN DB[#DB_Number_TEMP] //Open DB
L DBW[AR1,P#0.0] //Load value from DB
T #DB_Value

Hope I haven't dropped too many clangers there, but it should be something like that. If I have, Simon or S7Guy will correct it!
 
You can open a DB indirectly as follows. You can't use a static variable in an FB, it has to be a temp local.

L DB80.dbw6
T iTemp
OPN DB [#iTemp]

L DB80.dbw6
T MW100
OPN DB [MW 100]

OPN DB 80
OPN DB [DBW 6]
 
Out of interest, how does the DB number get into DB80.DBW6 ? If the DB's you are indirectly addressing do not appear in the cross-reference, it can be difficult to track down what is going on.
 
You can't use a static variable in an FB, it has to be a temp local.
I know that this is the case, what I don't know is why! I've been digging through the chapter in Berger about the way data is stored when parameters are passed over, but I still haven't sussed it out. I suspect that it might have something to do with the V-area memory copy, but this is one of those cases where I might have a slightly better chance if I'd bought the English version of Berger (wouldn't bet on it though!)

Any chance of another of your brilliant explanations Simon?
 
Sorry, don't know why, Berger just says you can't do it. (My guess is that when the editor was being designed, somebody decided not to have the extra complexity involved - bear in mind that L DB80.DBW6 is actally done as OPN DB80, L DBW6). You can use instance data, but you cannot reference it symbolically.

i.e. you can use

OPN DB[DIW 100]

as well.
 
Simon

The value gets into DB80.DBW6 via an OP7 HMI.

Basically, I have 16 motors. Their positional data is held in a datablock as a 'program'. There are 32 'programs' so that's 32 datablocks.

I have made a screen on the HMI whereby the operator can go in and access the positional data for any motor in any program and alter the value.

Obviously I could do this the long way round but its a lot easier to be able to have a tag on the screen for the program number (DB80.DBW6) and then program 1's data is held in DB1, program 2 is in DB2 etc etc.

Another question while we're on the subject (by the way, I've tried your last answer out and it works spot on!)...

I have a variable in my Variable Declaration Table of the type BLOCK_DB and its an 'in'. Its called #program.

Previously I was using OPN #program and then moving data block bytes into marker bytes.

However, now I want to move data block bytes in another data block.

So... instead of ...
OPN #program

L DBB0
T MB50

I want to move DBB0 into a different datablock

Is there a way I can do something like this...

L #program.DBB0
T #other_block.DBB0 (obviously #other_block is also in the Variable Declaration Table as a BLOCK_DB)

I've tried messing around with this configuration adding []'s and #'s etc to try and get it right but it won't accept it.

Cheers

JT :)
 
You can't use that format of instruction with block_db parameters. One method is to use the instance DB as the "other" db. This will only work in an FC, not a multiple instance FB.

OPN #DBb //opn global data DBb
CDB //opn instance data DBb
OPN #DBa //opn global data DBa
L DBB 0 //load from DBa
T DIB 0 //store in DBb
etc...

alternatively, use the following:
OPN DBa
L DBB 0
OPN DBb
T DDB 0
etc...
 

Similar Topics

Hi everyone, If I am writing a S7-300 program in STL, why would I need to use OPN DB2 L DBW1 when I could use L DB2.DBW1
Replies
10
Views
2,684
Hi I'm trying to decypher some step7 code which all seems pretty straight forward except that there are several instances of OPN DB100 but no...
Replies
4
Views
1,893
Hi All, I wish to Open a DB that will be constantly changing. Eg OPN DB [MW] My code will look at the data words/Dwords/Stings from this DB...
Replies
5
Views
3,139
What is diferent between S5 C DB and S7 OPN DB? I found that when i convert the program from s5 to s7 the function of OPN DB can only execute...
Replies
15
Views
9,667
What is diferent between S5 C DB and S7 OPN DB? I found that when i convert the program from s5 to s7 the function of OPN DB can only execute...
Replies
3
Views
4,358
Back
Top Bottom