desperately need simple sample programs or exercises for Step7 Professional

Write an FC that determines the following data for an array:
1.DBNumber where array is located
2.Area pointer of start address of the array
3.The size of the array in bytes
4.The size of an array element in bytes
5.The size of the array in elements

The FC will have two any pointer input parameters, the first points to the array, the second points to an element of the array. The FC will use an any pointer return value to point to a udt containing the determined data for the array as detailed above.

Example call and UDT shown below:

I'm lost as to what I'm meant to be doing on this example and wondered if you could elucidate a little more on what is required.

So...
I'm going to create a DB (say DB 2) that holds an array.

The array will have x number of elements of the type 'byte' (for instance).

I then pass in the start of the array to an FC (i.e. P#DB2.DBX0.0)

And also the first element (i.e. P#DB2.DBB0)

attachment.php



Then, within the FC, I isolate the DB number where the array is located, the area pointer of the start address of the array, the size of the array in bytes, the size of the array element in bytes and the size of the array in elements.

Then... (assuming I'm correct so far) what do I do with the information?

Your example shows a UDT with all that info. So I presume that I create that UDT and put it into a Datablock.

I then pass the information about the array into the UDT in the Datablock?

Do I put it into the UDT in the datablock from within the FC (i.e. T DB4.DBW 0 etc etc...)

Or is all the info contained within the return value (i.e. is DB2.ArrayInfo (in your example) an array so that DB2.ArrayInfo[0] contains the DBNumber, DB2.ArrayInfo[1] contains the start of the Area Pointer etc etc ) ?

Sorry for all the questions but I love stuff like this and so I want to do it right.

Cheers

;-)

questions1.jpg
 
ArrayInfo is a UDT - the UDT layout is shown in the original post. The RET_VAL from the FC is of type UDT (UDT12 in my example posting)
 
New task. Write an FB that will search all DB's in the plc for a given word. Report the DB number and Area pointer for the first occurrence of the word. Exclude the instance DB used for the FB from the search. Search the DB only on even byte addresses. If the word is not found, set the DB number to zero. A risng edge on bStart will start the search and clear bFinished. The search may take place over several scans of the FB. When the search is complete bFinished should be true.

mt2.JPG
 
New task. Write an FB that will search all DB's in the plc for a given word. Report the DB number and Area pointer for the first occurrence of the word. Exclude the instance DB used for the FB from the search. Search the DB only on even byte addresses. If the word is not found, set the DB number to zero. A risng edge on bStart will start the search and clear bFinished. The search may take place over several scans of the FB. When the search is complete bFinished should be true.

Can't believe these are still being classed as "medium" !!!

Christ!! What's the hard one's going to be like....

New Task (medium to difficult)

Write an FB that will ascertain the weaknesses of the Iranian Uranium Enrichment programme and use them to form the basis of a peace accord between the Palestinians and the Israeli's......
 
Write an FC that determines the following data for an array:
1.DBNumber where array is located
2.Area pointer of start address of the array
3.The size of the array in bytes
4.The size of an array element in bytes
5.The size of the array in elements

The FC will have two any pointer input parameters, the first points to the array, the second points to an element of the array. The FC will use an any pointer return value to point to a udt containing the determined data for the array as detailed above.

Example call and UDT shown below:

Right.. I'm struggling with this one.

I've got the following blocks in my project:

attachment.php


My UDT is the same as yours and I'm hoping to put the RET_VAL into DB 1 (arrayResults).

I have put the following code in to try and work out what is getting passed into the function:

attachment.php


When I monitor MD 50 and MD 54 they look like "Cross Area Pointers".

MD 50 gives me the following bit pattern...

1000_0111_0000_0000_0000_0000_0000_1010_1000

As far as I was aware the MSB indicates that this is a Cross Area Pointer.

Berger kindly informed me that the bit pattern of three 1's at 24,25,26 indicates that this is pointing to "Temporary local data of the predecessor block".

The Byte/Bit combination of 21.0 doesn't give me anything.

So... I'm stuck.

I thought that the first pointer I passed in would have the DB embedded somewhere in it and that I'd be extracting some bits from this to pass into the DB address in the RET_VAL UDT but I must be mistaken.

This has kind of driven me into a dead end and I wondered if you could give me a 'pointer' (excuse the pun) in the right direction.

Cheers

;-))

Image1.jpg Image2.jpg
 
All FC parameters are passed as area pointer - what you are seeing is a pointer to the location of the any pointer (the local data of the preceeding block). Load this pointer into AR1 and then you can fetch the indivual components of the ANY pointer for processing.
 
Thanks for getting back to me LD.

Do you mean:
Code:
L P##pArray
LAR1
 
L D [AR1, p#0.0]
T MD 50

??

I presume not as this just gives me zeroes in MD 50.

I see when I go online that AR1 is pointing to V21.0 (I presume this is local memory in OB 1 ?)

I'm missing something on how to turn the Pointer that is pointing to a pointer, back to the actual data... ?

Another prod ?

;-)
 
It's not letting me enter that code...

There's obviously something wrong at this end...

Here's what I've got:

My FC declaration table has UDT 1 (called "arrayInfo") in the RET_VAL of the FC.

(UDT 1 is the same as your UDT 12)

I have a datablock (DB 1) that has one UDT 1 inside it.

In OB 1 the RET_VAL output has P#DB1.DBX0.0 on it (symbolically called "arrayResults".thisArray

When I try:
Code:
L W [AR1,P#2.0]
T #arrayInfo.wDBNumber

The "#arrayInfo.wDBNumber" just appears in red.

As does every combination I've tried.

I'm not sure what I'm doing wrong here?

Any ideas?

Cheers

;-)
 
ArrayInfo is in the temp area of type udt12 in my code. I only posted it to show that you can monitor AR1 and the accumulators instead of copying the data to an MD
 
Hi Nick, hope you're well mate. I've sorted it now. I didn't have the IN's as ANY (I had them as Pointers).

Also, I didn't have the UDT in the TEMP area for me to split AR1 to.

Keep getting dragged off to do other stuff but still working on it, thanks.

;-))
 

Similar Topics

hi,i'm an undergrad student frm india exposed to a KOYO plc for the first time.i basically joined the forum for some tips to program the...
Replies
2
Views
3,341
Hello let me explain my problem. I just got tossed into a somewhat complicated job because the person that normally does the writing is on...
Replies
5
Views
3,832
Hi. I tried to find help in for documenting or migrating Pilz Pitouch HMI projects (in 2007) in this thread...
Replies
1
Views
1,500
Hi all. I am trying to find safety application examples for an inspection door with electromechanical interlock. I can find many door switches...
Replies
39
Views
13,692
So i've been at this for a long while, i have Citect Scada 2018, i have full access to everything but i can't seem to find any option or...
Replies
0
Views
36
Back
Top Bottom