S7: indirectly addressing Byte within DB?

Johnny T

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

Does anyone know how I can indirectly address a byte within an indirectly addressed Data Block?

Here's the code so far...

 
L MW 8 // MW 8 HOLDS DB No.
T #DB_TEMP // TRANSFER IT INTO TEMP STORAGE
OPN DB[#DB_TEMP] // OPEN THE DATABLOCK
L DBB 0 // ** THIS IS THE BYTE I WANT TO MAKE INDIRECT
OPN DB 100 // OPEN DESTINATION BLOCK
T DBB 3 // TRANSFER VALUE OF BYTE TO BYTE 3



Where I have the Load command looking at Byte 0, I want to make it indirect so I can either pass into the FB the byte to look at. Or use the value of a marker byte to tell it which byte to look at.

I've experimented with a few different ideas but can't get anything to work.... I'm still waiting for my Hans Berger book so, until that arrives, anyone got any ideas?

Thanks

JT :)
 
Well, there are a few ways. For instance:

L DBB[AR1,P#0.0]
or
L DBB[AR2,P#0.0]
or
L DBB[MD100]
or
L DBB[TempVariable]

It will be up to you to calculate the pointer, but any pointer format will work.
 
Johnny T said:
Hi

Does anyone know how I can indirectly address a byte within an indirectly addressed Data Block?

Here's the code so far...

 
L MW 8 // MW 8 HOLDS DB No.
T #DB_TEMP // TRANSFER IT INTO TEMP STORAGE
OPN DB[#DB_TEMP] // OPEN THE DATABLOCK
L DBB 0 // ** THIS IS THE BYTE I WANT TO MAKE INDIRECT
OPN DB 100 // OPEN DESTINATION BLOCK
T DBB 3 // TRANSFER VALUE OF BYTE TO BYTE 3

One other thing: Your code is kind of inefficient. If this is going to be called a lot, you may want to open an instance DB instead, and then you can use two data blocks at the same time:

 
L MW 8 // MW 8 HOLDS DB No.
T #DB_TEMP // TRANSFER IT INTO TEMP STORAGE
OPN DI[#DB_TEMP] // OPEN THE DATABLOCK
L DIB 0 // ** THIS IS THE BYTE I WANT TO MAKE INDIRECT
OPN DB 100 // OPEN DESTINATION BLOCK
T DBB 3 // TRANSFER VALUE OF BYTE TO BYTE 3



If DB100 was already open, you wouldn't have to open it again. It really depends on your application, but if you are shuffling a lot of data around, you should consider this.
 
S7Guy

I'm still struggling a bit with this indirect addressing. Please excuse both my ignorance and my stupidity...

I've changed the code to be...

 
L MW 8 // MW 8 HOLDS DB No.

T #DB_TEMP // TRANSFER IT INTO TEMP STORAGE

OPN DB[#DB_TEMP] // OPEN THE DATABLOCK

L DBB [MD130]

OPN DB 100 // OPEN DESTINATION BLOCK

T DBB 3 // TRANSFER VALUE OF BYTE TO BYTE 3



In the block that calls this FB I've set MD130 to be 0 thinking that this would equate to DBB 0 but the CPU is going to stop mode.

I'm assuming that I need to format MD130 somehow (pointer??) in order to get it to do what I'm asking.?

I've tried defining an 'in' variable in the Variable Declaration Table as the type 'pointer' and then using..

DBB [#IN0]

But this highlights in red and won't let me enter it...

What am I doing wrong? Can I not just move a value into MD130 that will equate to the byte number that I need to read?

As mentioned at the start of this post, apologies for my ignorance and thank you for any light you can shed on this

Cheers

JT :)
 
Have you looked at the value of MD130 online? Remember, it points to the byte.bit value, so if you are using something other than zero, you have to take that into consideration. For instance, to pointo byte 8, MD130 would have to be 64.

Try this for a test:

L MW 8 // MW 8 HOLDS DB No.

T #DB_TEMP // TRANSFER IT INTO TEMP STORAGE

L L#0
T MD130

OPN DB[#DB_TEMP] // OPEN THE DATABLOCK

L DBB [MD130]

OPN DB 100 // OPEN DESTINATION BLOCK

T DBB 3 // TRANSFER VALUE OF BYTE TO BYTE 3


and if that works, try other pointer values, i.e.:

L MW 8 // MW 8 HOLDS DB No.

T #DB_TEMP // TRANSFER IT INTO TEMP STORAGE

L L#24
T MD130

OPN DB[#DB_TEMP] // OPEN THE DATABLOCK

L DBB [MD130]

OPN DB 100 // OPEN DESTINATION BLOCK

T DBB 3 // TRANSFER VALUE OF BYTE TO BYTE 3

Also, instead of loading pure dint values, you could load P#0.0 and P#3.0, respectively.
 
Example Code

ftp://ftp.deltacompsys.com/public/S7/Rmc75_16.zip

This is example code that I used to test and show how to communicate with out motion controller over the Profibus. The key thing is there are a few instances of where one needs to copy to and from the motion controller. In this case I need to have a simple copy command where the parameters are:

S7 data block
S7 offset
RMC data block
RMC offset
count.

The only difference between what I am doing and you are doing is that I am copying 32 bit values instead of 8 bit values. The techniques are the same. The are plenty of comments to ge the general idea.
 
Right sorted it with your help.

S7Guy, you hit the sharp pointy thing on the end with your comment about the MD130 having to reflect the 'bit' and not the 'byte'.

Its working a treat now.

Peter, many thanks for the software. I had a good look through it and (although I hate to admit it) its a little bit beyond me at the moment. Although I was impressed with your RMC75RWDB block which breaks larger messages down into multiples of 7. It will certainly be some software I'll be revisiting when I've read and digested my berger book (STL and SCL) which should be here soon.

Once again, many thanks for your help

Cheers

JT :)
 

Similar Topics

Hello All, I wonder if anyone can help me? I'm working for a company within a sector that has virtually zero standards of work so i've started...
Replies
2
Views
1,894
Anyway to indirectly address I/O based on slot # instead of having to first map each point to a secondary tag? Prefer to be able to address based...
Replies
14
Views
3,997
Per title, I have an example string array Foo of datatype STRING[10] and index Bar of type DINT EQU('False',Foo[Bar]) works functionally but on...
Replies
8
Views
2,939
Hi all, I'm looking through some software that has LOTS of FCs that are 'orphaned' in the Program Structure (they have a cross through the box as...
Replies
5
Views
2,366
Maybe stupid question, but.. :huh: I need to read external status from Danfoss vlt, which is connected to S7/300 via profibus. I have done my...
Replies
1
Views
1,195
Back
Top Bottom