S7 Pointer Help

The Byte address takes up Bytes 7 (3 bits of it), all 8 and half of byte 9.

If you put the address of the byte into word 8, firstly it is over-writing you bit address that you have already loaded into byte 9, no great shakes as your example and 100% of the jobs I have worked on you have zero for the bit when using an ANY.

So the only reason your code works is:

1. All your bit addresses (as mine) are zero.

and

2. Your byte address is less than the value which would overflow into byte 7 (4095 or less).



Look at post 11 in this thread, I copied the format of the pointer from the siemens help pages.
 
Last edited:
PeterW is right. Your example will work in most cases because usualy bit offset is 0. And you don't use byte 7 in fact.
Correct form of your function:
L p##MyPointer
LAR1
L B#16#10
T LB [AR1, P#0.0]
L #Data_Type
T LB [AR1, P#1.0]
L #GentagelsesFaktor
L LW [AR1, P#2.0]
L #DBNr
T LW[AR1, P#4.0]
L #StartByte
SLD 3
L #StartBit
OD // Peter, OD must be used, not AD
T LD [AR1, #P.6.0]
L #RegisterType
T LB[AR1, #P6.0]
 
PeterW

I Cant't follow you!

Eks:

L#StartByte = 20 =>ACC1:0000000000010100
SRD 3 = 2 => ACC1:0000000000000010
L#StartBit = 0 => ACC1:0000000000000000 =>ACC2:0000000000000010
AD = 0 => ACC1:00000000000000000000000000000000
T D [AR1,P#6.0] => Nothing, I'am I right?
 
[FIN]Pete said:
Hi Guys

I just want remind for You one thing. If You handle FB's and You have several block calls into same multi-instance FB/DB -> You must remember to add TAR2 into ANY-variable, then you can get the correct start-address.
TAR2 // Start-address of current FB-call
L P##ANY_VARIABLE // Variable address
+D
LAR1 // Start-address of ANY_VARIABLE in current FB-call

If You use only P##ANY_VARIABLE, then the each FB-call must have own(individual) instance-DB.

Pete 🍺


I am trying to understand indexed adressing and I am having troubles with multiple-instance-FB's. I've written a program with and without them.

FB5 is a normal FB and works fine.

FB3-FB4-DB3 (multiple-instance) is were the problems start.

If, in FB4, I write:

L #count_loop
SLD 3
LAR1 P##lijst
+AR1
only lijst[1] is written too.

When I try to use the info from this topic and start to work with AR2 (see code FB4) the cpu goes into STOP.

Can somebody help me?
 
Cut/paste typo in network 3, correct as below:

typo1.JPG
 
Anypointer To FB Static Area

Hello!

I'm trying to determine the start address of an array (240 bytes) declared as static in a FB (To Initialize it and avoid hard coding). I've tried the following code (I know, I've got a few extra lines in there..!)but get totally bogus values. Can anyone please tell me what exactly I'm doing wrong here?


TAR1 #Temp_AR1_Store
L P##Stat_Rob_RX_Buffer
LAR1

L B [AR1,P#1.0]
T #Temp_RXArray_DataType
L W [AR1,P#2.0]
T #Temp_RXArray_DataLength
L W [AR1,P#4.0]
T #Temp_RXArray_DBNo
L W [AR1,P#8.0]
SRW 3
T #Temp_RXArray_StartByte

LAR1 #Temp_AR1_Store

Any feedback would be greatly appreciated. Thank you kindly!

Cheers!

R.K.
 
Although this doesn't answer your question, have you considered using SFC21 to fill the data area ?

As to your code - you are a long way off. See below for the first part of the story - more to come.


Code:
	  L	 P##Stat_Rob_RX_Buffer
	  LAR1  
// AR1 will contain the area pointer to the variable stat_Rob_Rx_buffer. Thats all you can
// establish by loading a pointer to a variable - the area it is in and where it starts.
// Any STAT variable will be located in the instance DB area, the result will be DIXa.0
// Where "a" will depend on where you have declared the variable in the STAT area and if there
// are any parameters for the FB.
// As AR1 is now pointing to the area, any accesses using L B[AR1,P#0.0] type instructions
// will read data from the Stat_Rob_RX_Buffer
 
Last edited:
Here's some example code which may assist. FC2 will accept an any pointer input and copies the any pointer values to another any pointer (which must be declared in the temp area) - you can then read out the individual components of the any pointer for use elsewhere.... I've shown a few examples.

anyoldiron.JPG


anyold009.JPG
 
Hey! Thank you kindly for the reply. Wow, it seems I really was way off with my code!

Ok, so regarding the pointer (not any) to #Stat_Rob_RX_Buffer, how can I actually read the start byte of the data array by breaking up the pointer inside the FB without a call to FC2.

If I understand correctly, you use the input in FC2 to assign an anypointer to #Stat_Rob_RX_Buffer so that you can deconstruct it and determine type,qyt,db and the area pointer. My error, I guess was that I assumed P##Stat_Rob_RX_Buffer represented an any pointer to the array. This brings me the part that I find confusing. Why is it exactly that P##Stat_Rob_RX_Buffer loaded into AR1 and used with, for example L B [AR1,P#0.0] actually represents the data in the array, wereas loading P##Stat_Rob_RX_Buffer into FC2 and deconstructing it via L W [AR1,P#0.0] ect.. actually now represents the data in the any pointer. I'm guessing it's becuase the input to FC2 is defined as an anypointer..is this correct?

Seriously, thank you so much for the help. It's greatly appreciated!

Cheers!
 
You are correct.

Code:
L P##Stat_Rob_RX_Buffer

The start byte for the current instance of the FB is loaded into the accumulator using the above. Can you elaborate more on what you are going to do to fill the data area ?
 
Last edited:
Hey!

Sorry, dont follow. I loaded P##Stat_Rob_RX_Buffer in ACCU1 but when I look at it online the value doesn't make any sense. Am I missing something here?

Yeah, I needed to initialize an array with zeros and your suggestion of SFC21 was on the money. I've used it now in my code but I still need to understand why exactly my original code didn't work. It looks like my understanding of pointers needs to deepen!

Cheers!
 

Similar Topics

i write code STL and simulate but result Q2.7 not set , i dont know why :scratch: , help me plz thanks LAR1 P#Q2.7 S [AR1,P#0.0] or LAR P#2.7...
Replies
3
Views
1,703
Hi Folks, I'm having problems completing a FB and suspect my pointer programming maybe the issue. The purpose of the FB is to transfer a...
Replies
13
Views
10,618
I just want to set db2.dbx0.0 when q100.0 is on, just trying to learn pointer. Please help what i m doing wrong. thank for help..... L 2...
Replies
8
Views
1,650
Hi all, I have the following FC: FC100 INPUT TRACK_NR := dint FUNCTIE_NR := dint BITJE := bool INPUT/OUTPUT FUNCTIE_WOORDEN :=...
Replies
5
Views
2,055
Hi I am looking into code to set a block of 8 booleans within a datablock, depending on the condition of 8 'flags'. The start bit of the 8 bools...
Replies
13
Views
3,583
Back
Top Bottom