Technical Forum

STEP 7 / STEP 7 Lite

Muti-instance problem:Only the first instance works

Thread Starter: NA Simatic   Started: 4/7/2012 11:38 AM   Replies: 2

« Previous thread Next thread »
Page 1 of 1 (3 items)
  4/7/2012, 11:38 AM
Joined 10/19/2007
Last visit: 6/9/2013
Posts: 37
Rating:
Rated: no ratings [0 out of 5 / rated 0 time(s)]. (0) 
Rated: no ratings [0 out of 5 / rated 0 time(s)]. (0) 
Hello Colleagues,

I spent a long time trying to solve the problem without success. Here is a detailed description with a sample project in the attachement:cry

1. I wrote FB_Motor (FB1) to be called several times inside a multi-instance host FB called FB_HOST (FB2). the latter is called in OB1 with its IDB DB_HOST (DB2).

OB1  --->( FB_HOST,DB_HOST)  ----> (FB_Motor,#Motor1) and (FB_Motor,#Motor2)

Where #Motor1 and #Motor2 are local instances of FB_Motor declared in the STAT area of FB_Host.

2. FB_Motor consists of only one IN/OUT byte called "HMI_Interf_Byte" and serves as HMI interfacing tag that gathers several binary info in order to save tag count (license).

3. The code of FB_Motor also contains a single line of code that copies the fisrt bit in "HMI_Interf_Byte" in its last bit: DIX0.0 ----> DIX0.7

4. In the variable table, the two bytes from the two instances are shown. Normally if we write 16#01 in any of them ,they should become 16#81. BUT this works only for the FIRST instance and never for the SECOND EVEN  if we delete the FIRST instance (#Motor1) from the code and let only the SECOND one (#Motor2).
---------------------
I think that the access to the instance DB ( DIX0.0 ----> DIX0.7) lies behind the problem.

Would you please help me fix the issue.

Best regards.

Attachment: MultiinstanceProblem.zip  (4 Downloads)



=== Edited by NA Simatic @ 4/7/2012 11:40 AM [GMT ] ===



Top
  4/7/2012, 2:23 PM
Joined 10/7/2005
Last visit: 6/19/2013
Posts: 2367
Rating:
Rated: Excellent [4.26 out of 5 / rated 615 time(s)]. (615) 
Users with special expertise supervising conferences
Rated: Above avarage [3 out of 5 / rated 1 time(s)]. (1) 
Hello NA Simatic

the "simple" explanation for your problem is that you use an absolute Instance DB address (e.g. DIX1.0) in a Multi Instance FB which will not work.

What happens behind the scenes is this:
When you do a call of a Multi Instance capable FB, its Multi Instance DB start address is stored in AR2.
Any symbolic access that you have programmed inside the FB will automatically use the AR2 related offset into account and thus find the correct address in the Multi Instance DB (Step 7 will take care of this for you).
If you however "bypass" symbolic addressing and use an absolute Instance DB address instead, you will always access this absolute address in the Multi Instance DB and thus have the problem that you observe.

Possible Solutions:
1.) Use only symbolic access to the FB's variables.
2.) Use indirect addressing and take the AR2 related Multi Instance offset into account (have a look at THIS entry, specifcially at the end of it on how to take AR2 into account and note too the other indirect addressing related links at the top).

I hope this helps

Cheers

fritz

The advice and opinion given in this thread is that of the author and does not necessarily reflect the views of I S Systems Pty Limited.
To find out how I S Systems can help you with your automation needs please visit www.issystems.com.au.
Top
  4/9/2012, 7:18 AM
Joined 10/19/2007
Last visit: 6/9/2013
Posts: 37
Rating:
Rated: no ratings [0 out of 5 / rated 0 time(s)]. (0) 
Rated: no ratings [0 out of 5 / rated 0 time(s)]. (0) 
Many thanks Dear Fritz for your valuable advice!
I solved the problem using symbolic addresses.

Best Regards.
Top
Thank you for this post from:
Page 1 of 1 (3 items)
Actions