desperately need simple sample programs or exercises for Step7 Professional

Certainly does... had an email earlier saying they had good news about my lottery ticket. I've vowed that the £10.63 I won isn't going to change me and therefore it looks like work is going to be getting in the way of fun for a while longer... ;-)
 
Final task to top off this thread - combine the flasher task and the array info task to create an FB that can be passed an array of up to 100 flashers - the actual number will be determined by the size of the array passed to the FB. The FB should process the flashers in a loop (instead of creating 100 calls to the flasher FB). If the byte address of the flasher Q address is -1, the flasher should be skipped and not control a Q output.

task8.JPG
 
Last edited:
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've had a go at this example and I've attached my attempt. I'm pretty sure I've gone off on a bit of a tangent here. It doesn't work 100%.

When it comes to working out how big the array is in 'elements' then it can't differentiate to say that there are 12 bools. It just says 16 bools (i.e. it rounds it up to the nearest byte).

Also, for some reason it adds 1 or 2 to the number of bytes in the array.

It seems to be ok for words and doublewords.

It also won't work for Complex datatypes like STRINGS in an array (can you have strings in an array?? I presume so...).

So... there are limitations. I would be very very interested in critical feedback. Especially on how to do this example better. I realise there are a few shortcuts with regards to some of the Load/Transfers
(i.e.)
Code:
L #divider
L 8
<I
JC ZERO
 
L #divider
L 8
/I
T #tempArrayInfo.wSizeOfElementsInBytes
JU M001
 
ZERO: L 0
T #tempArrayInfo.wSizeOfElementsInBytes
 
M001: NOP 0
 
*** Could become... ***
 
L #divider
L 8
<I
JC ZERO
 
L #divider
L 8
/I
JU M001
 
ZERO: L 0
M001: T #tempArrayInfo.wSizeOfElementsInBytes

... But I've tried to write it in a way that it would be easier to maintain, alter and read.

;-)
 
The reason your processing fails for strings/structures etc. is that you are not taking into account the size information for the array element. Here's an example where I am passing an array of string[10] - the element type is shown as byte and the length is w#16#C due to the two header bytes in a string.

soe.jpg
 
Thanks LD for the info.

I've had another go at it and it appears to work for STRINGS, WORDS, DWORDS etc. The only issue is that it counts an extra BYTE for arrays of that type.

However, there has to be a more efficient way of doing it rather than my way. I've had to start programming in lots of little "what if's" that make the program (I suspect) far more complex than it needs to be.

Anyway... here it is....
 
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.


I've attached my attempt at this example.

It's working fine. The only problem I've got is that I've had to use a fixed address (MB 20) to hold the temporary byte that is fetched from the DB for comparison.

I tried writing the area pointer to point at a STAT in the variable declaration table but I couldn't get it working right.

I wanted to get this posted before I finish (in 15 minutes) so thought I'd just put it up with MB 20.

Any comments / feedback etc on how this has been done (ways to do it better etc) would be very much appreciated.

Also, if someone knows how to formulate the Area Pointer to point at a STAT in the variable declaration table then that would be good too.

The only other problem with this example is that it addresses all DBs as global DB's. I'm not sure whether this will work with Instance DBs and the original example intimates that it should work with IDBs too...

Again... not sure about this so maybe someone could have a quick look through the code and let me know whether it would or not. Maybe the loop would have to be run through again but with 101 as the address area (Instance DB rather than 100 which is global DB) ???

Cheers

;-)
 
Here's my implementation. I checked 256 DBs per scan over 256 scans to check all possible 65535 DBs. I used SFC24 to determine if the DB existed before checking it. I used
Code:
L DBLG
to determine the length of the DB (in bytes) and as the comparison is a word, the loop count for comparisons is the db_length/2. I used the
Code:
+AR1 P#2.0
to increment the index into the DB whilst searching. I used a separate FC for checking the DB for the pattern match

Your use of SFC20 is equally valid but extra code is required to generate the any pointer inside the loop - you could have used the SFC20 return value to identify when the DB did not exist or you ran off the end of the DB.

You could have fetched a word for the comparison instead of a byte at a time (that's why I specifed the search to be on even byte addresses).
 
Hi!
I am desperately looking for some simple sample programs to learn Step7. Something like the manual of Working with Step7 (http://www.fer.unizg.hr/_download/repository/STEP7.pdf) but more advanced.
It can be some LAD or STL tasks, configuring HW, SCL and Graph language also!
Thank you very much for any help!
Miro


Anything to report - have you completed any of these sample programs?
 
Thanks must go to LD for all his efforts in providing these excercises; I know that he devotes much of his personal time to these projects. It would be great to hear from the OP! Many future users will find this thread and learn from it.

Learning SCL will be the challenge that occupies many of us over the next 5 years.

Nick
 
Expand and allow the user to specify the byte.bit of the Q that is to flash. Example shown will flash Q4.3

First, Thanks you L D for these excercises.

I´m having a little trouble figuring out how I should point to the right output.

Should this be done with a any pointer or how?
 
Compute the area address by combining the byte and bit addresses and then use indirect addressing to refer to the Q output. Here's an example using AR1

qqq.JPG
 
Here's my implementation. I checked 256 DBs per scan over 256 scans to check all possible 65535 DBs. I used SFC24 to determine if the DB existed before checking it. I used
Code:
L DBLG
to determine the length of the DB (in bytes) and as the comparison is a word, the loop count for comparisons is the db_length/2. I used the
Code:
+AR1 P#2.0
to increment the index into the DB whilst searching. I used a separate FC for checking the DB for the pattern match

Your use of SFC20 is equally valid but extra code is required to generate the any pointer inside the loop - you could have used the SFC20 return value to identify when the DB did not exist or you ran off the end of the DB.

You could have fetched a word for the comparison instead of a byte at a time (that's why I specifed the search to be on even byte addresses).

Hi LD,

I like your implementation. Very clean and easy to follow.

I take it the L DBLG command gets the length of Instance DBs as well then? The help file says 'Loads the length of shared DBs'.?

I had not heard of SFC 24 before for testing DB's.

Just out of interest, is there a way of searching the library of SFC's in order to try and find one that's suitable for your needs or is it just a case of trawling through them all and reading the help file for each one.

I've often wondered about the library and hows its split into TI-S7 Converting blocks and IEC Function Blocks etc etc. I just wondered how you know where to start looking for a function if (as in my case) I knew what I wanted to do but didn't know of any blocks that could achieve it ??

Thanks again for all your help. I'd like to echo Nick's comments that the work you put into these examples is very much appreciated.

;-)
 
I take it the L DBLG command gets the length of Instance DBs as well then? The help file says 'Loads the length of shared DBs'.?

L DBLG gets the length of the data block opened with OPN DBxx
L DILG gets the length of the data block opened with OPN DIxx

You can open a Data block as a DB or DI in your code irrespective of whether the Data Block was created as a DB or as a DI
 

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,340
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,691
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
25
Back
Top Bottom