S7-300 opn db

jwilcoxson

Member
Join Date
Sep 2014
Location
Georgia
Posts
31
Hi everyone,

If I am writing a S7-300 program in STL, why would I need to use

Code:
OPN DB2
L DBW1

when I could use

Code:
L DB2.DBW1
 
Ok, so maybe I would just use OPN if I was going to use the particular DB several times and wanted to save myself some typing?
 
Please be aware that there is an implicit OPN with any fully qualified DB access. In the example below, the transfer will write to DB2, not DB1

Code:
OPN DB1
L DBW 0
L DB2.DBW2
+ I
T DBW 2
 
Thanks, that is really good to know, I wouldn't have assumed that. So that means that this:

Code:
L DB2.DBW1

Is exactly equivalent to this

Code:
OPN DB2
L DBW1
 
Thanks, that is really good to know, I wouldn't have assumed that. So that means that this:

Code:
L DB2.DBW1

Is exactly equivalent to this

Code:
OPN DB2
L DBW1

That is correct.

I believe that
Code:
L DB2.DBW0
L DB2.DBW2

is also the same as
Code:
OPN DB2
L DBW0
OPN DB2
L DBW2

You might theoretically save a tiny bit of processing by using OPN, but it is negligible. Most people find that using the fully qualified name (DB2.DBW0) is much clearer and easier to read. The hardest part of STL is making code that other people can follow. I think there are a very few specific situations where using OPN allows you to do something you couldn't program other ways, but most of the time I think people prefer the DB2.DBW0 style.
 
Execution time and memory useage may become important to you at some stage. Using DB numbers 255 and below also uses less memory.

Code:
OPN DB1
L DBW 0 
L DBW 2
+I
T DBW 4

uses less memory than:

Code:
L DB1.DBW0
L DB1.DBW2
+I
T DB1.DBW4
 
One important note.

With "OPN" etc. you wont have any symbols, apart from the DB symbol.

Code:
OPN "myDB"
L DBW 0 // absolute addressing !
L DBW 2
+I
T DBW 4

Code:
L "MyDB".MyINT1 // symbolic addressing !
L "MyDB".MyINT2
+I
T "MyDB".MyINT3

IMO the eventual gain in execution speed is far less important than that abolute adressing is more error prone and more difficult to maintain.

Btw. You can program symbolically with SCL, and the SCL compiler will take of when to use "OPN" in the generated STL code.
 
You need to try the different examples listed above in debug mode

You can see the DB register gets changed with the OPN DB1 or with the L DB1.DW0. The DB register stays the same until changed again.

L D[AR2,P#0.0], I forget. What restores the DB to the original state after a return from a call? Upon entering a FB or FC I would save the old DB away if I needed to change it and restore the DB before returning so that it would be in its original state.
 

Similar Topics

Hi Siemens guys! I am experiencing SF fault on our S7-300 (6ES7 315-2AH14-0AB0) CPU from time to time. I've checked the diagnostic buffer and...
Replies
13
Views
129
Have a system that has been running for over a year and all of a sudden getting a ExcessiveVelocityFault on one of the drives when the MSO command...
Replies
2
Views
142
Hello PLCS.Net Forum, First time posting. Let's assume I am a novice. BASIC PROBLEM: My servo/linear piston is no longer zeroed to the...
Replies
9
Views
211
hi... i have an issue in s7 300 plc, while we run the machine(in idle there is no fault) , plc cpu goes in SF mode, after restart the power cycle...
Replies
2
Views
116
gents, I am trying to configure communication with EMERSON PK300 controller through port A1 using generic ethernet communication module . I could...
Replies
0
Views
93
Back
Top Bottom