S7 fb to read in inputs and set outputs

A couple questions/comments. Your code has been very helpful, and I have been going through it very carefully so that I understand what is happening.

In OB1 you use FC20 and network 2 to extract the 300 out of IB300 and then use this variable as the StatusInputsAddress of FB4. Could you also simply place a constant of 300 on the FB4 instead of StatusInputsAddress, and eliminate the need for network 1 and 2?

In FB4 I understand how you use FC20 to extract useful information such as the count of the udt. In network 2 I get a little confused on some parts.

LAR1 P##pSrc Does this load AR1 with Pointer data psrc?
L W#16#1002
T W [AR1,P#0.0]
L #InputStatus.iCount
T W [AR1,P#2.0]
L 0
T W [AR1,P#4.0]
L #StatusInputsAddress I see why you have to shift left here
SLD 3
L P#I 0.0 But I don't understand loading P#I 0.0
+D
T D [AR1,P#6.0]

And then how does AR1 get transferred as P##pSrc?

Thanks for all your help so far!
 
In OB1 you use FC20 and network 2 to extract the 300 out of IB300 and then use this variable as the StatusInputsAddress of FB4. Could you also simply place a constant of 300 on the FB4 instead of StatusInputsAddress, and eliminate the need for network 1 and 2?

Yes you could use the constant 300, however, later when someone else wants to find out where IB300 is used in the program via the cross reference, it will not appear. Networks 1 & 2 are there to provide a reference to address IB300
 
L P#I 0.0 But I don't understand loading P#I 0.0

I could have used the alternative coding format (but produce the same code) as below.
Code:
L DW#16#81000000

The editor "knows" the coding for the areas I,Q,P,M,DBX,DIX so I used the constant pointer format for the I area, P#I0.0
 
In network 2 I get a little confused on some parts.

First of all, an anypointer occupies 10 bytes of memory and the only place it can exist as a "whole" is in memory. You can load certain parts of an any pointer into the accumulator or address register (AR1) which are 4 bytes wide, but not the whole thing.

When you call an FC (or SFC) with an any pointer as a parameter, what you actually pass is the location of the any pointer. The called FC/SFC is responsible for accessing the individual components of the any pointer and performing the required processing.

In my example, the any pointer pSrc is located at address 0 in the temp area, for coding purposes it is referred to as the L area.

l7.JPG
 
Given that pSrc is located at L0, I could have constructed the any pointer as follows:

Code:
      L     W#16#1002
      T     LW     0
      L     #InputStatus.iCount
      T     LW     2
      L     0
      T     LW     4
      L     #StatusInputsAddress
      SLD   3
      L     P#I 0.0
      +D    
      T     LD     6

Which is all well and good until someone adds a new variable to the temp area before pSrc meaning that pSrc is no longer located at L0, but someother address. You will be forced to look up the new address and then change all the insructions to match with the new address - of course if you had used several any pointers you would have to search for them all and update all the other any pointer construction instructions......
 
...which is where
Code:
      LAR1  P##pSrc
comes in.

This loads address register 1 with the start location of pSrc. In this example AR1 will contain L0.0 - the editor "knows" that pSRC is located at L0.0 and hence generate the correct code in the background. If you add a new variable in the temp area, the editor will automatically generate the correct address for pSrc for you. As the rest of the instructions access data offset from AR1, you only need to ensure that AR1 points to the start address of the any pointer for it to be contructed correctly.
 
I am finally starting to get a grasp on this now. I think I just have one more question, though. Is P#I 0.0 only 4 bytes in length to be loaded into accu, or is it 10 bytes and only the last four bytes get loaded into the accu?
 

Similar Topics

Hello, I am trying to write a program to simulate an ISSC IPC90. The IPC90 has some internal variables, I think the correct name is 'internal...
Replies
7
Views
1,850
Hello I need to message read the entire 16 channel raw analog inputs from a 1769-L33ER Compact Logic controller to another 1769-L33ER Compact...
Replies
8
Views
272
I am working with a Siemens 1500 in portal, and I want to know if my Profinet inputs can change during the scan of the PLC code. When do local...
Replies
8
Views
2,809
Hi everybody Does anybody have experience with the Analog input card 1746-N18? Cannot get the last 4 inputs (4-7) to work like the first 4 (0-3)...
Replies
4
Views
2,994
Trying to read analog inputs from 1746-NI8 card, but values show 0 and channel status LEDs never come on. Details: - SLC 5/05, 1747-L551...
Replies
6
Views
2,961
Back
Top Bottom