Sign in to follow this  
Followers 0
rswolff

Siemens S7-400

17 posts in this topic

short of going to Frankfort, anyone know how I can get a programming reference that includes addressing user types and arrays? there's nothing on the website, siemens itself is mute, and my vendors are useless. I'm semi familiar with both the S5 and S7, so I don't need help on standard instructions. I made a user defined type, and then created an array of this type. Now I can't find any method to address the individual components or copy a complete unit (type) from one to another similar type. any help greatly appreciated!!!

Share this post


Link to post
Share on other sites
Hi rswollf. I recommend the book "programming in STL and SCL" by Hans Berger. It covers extensively such things as addressing user defined data types. There is a CD with examples too. As to you specific questions. As long as the data type you want to address is one of the basic types, then you can just write for example L "myDB".myArray[23].int_setpoint T MW200 .. L 100.0 T "myDB".myArray[23].real_limit In STL you cannot index easily through the array without resorting to pointers. For this I strongly recommend SCL. In SCL you can indeed write FOR i:=1 TO 100 "myDB".myArray.int_actualvalue := "myDB_2".myArray.int_startvalue; END_FOR ; To copy complete structures in STL, LAD or FBD, use SFC20 BLKMOV.

Share this post


Link to post
Share on other sites
thanks, any idea where I can acquire the book. : I'm still amazed that there is no documentation available in the states from Siemens directly. Thats why I fire people who want to use this annoying stuff. I've been to Germany and there's plenty of it over there. bob

Share this post


Link to post
Share on other sites
Hi again Bob. Try to search for Hans Berger. I have the german version of the book, so the ISBN for that book is probably no good for ya. There is some info here and there in Siemens own help files and books, but the Berger book is the best. Apart from that, just ask here, and I or some one else can probably help you further.

Share this post


Link to post
Share on other sites
anyone using a siemens processor without having a gun put to your head is an idiot and not fit to call themselves an engineer. if anyone can give me a single application that is easier to do on the Siemens, or any function that is useful or well thought out....I'll eat one of my dirty socks.....(with ketchup of course)......bizzare programming, not existent documentation and support.....why in anyones right mind would they look at this and decide its the way to go....other than the aforementioned reason......its got a lot of hp...now only if my customers would like their projects after I study the Siemens for the next couple of years.......talk about a useless piece of technology....... and least i forget.....I can't use BLKMOV, its not supported in my customers processor....and they didn't purchase the SCL package....guess thats not a Siemens problem....i'll just tell my customer they're idiots (they actually aren't....their customer is) as well as the distributor (yes, he's an idiot too)......but not to worry...instead of writing some code that I could do on nearly any other platform in a day, I'll simply give up on the Siemens (i've already spent a week on this piece of crapola). I'll write it all out longhand....its ugly but it should work......

Share this post


Link to post
Share on other sites
The end-customer dont have to purchase SCL for their CPU to be able to run a program written in SCL.

Share this post


Link to post
Share on other sites
I wrote you a PM. I since decided to expand the sample code a bit: TYPE UDT1 STRUCT bi1, bi2, bi3 : BOOL; in1, in2, in3 : INT; r1, r2, r3 : REAL; END_STRUCT END_TYPE DATA_BLOCK DB2 STRUCT dataset1 : UDT1; dataset2 : UDT1; END_STRUCT BEGIN END_DATA_BLOCK DATA_BLOCK DB3 STRUCT dataset1 : UDT1; dataset2 : UDT1; END_STRUCT BEGIN END_DATA_BLOCK FUNCTION FC1 : VOID VAR_TEMP i1, i2 : WORD; struct1 : UDT1; struct2 : UDT1; END_VAR struct1.bi1 := TRUE; struct1.in2 := 123; struct1.r3 := 5.67; struct2 := struct1; DB2.dataset1 := struct2; // from TEMP to external DB DB3.dataset2 := DB2.dataset1; // from one DB to another DB DB3.dataset1.r2 := DB2.dataset2.r3; //from single element to single element END_FUNCTION

Share this post


Link to post
Share on other sites
yes, the forwarded code is nearly what I've been attempting to accomplish with no luck. And yes, I often to higher end math outside of the ladder environment. On the other platforms this usually means the addition of a Basic or CoProcessor module. processor is a CPU 416-3. I'm running STEP7 5.4 SP4. Mr. Bergers book seems to indicate that SCL is an option. When I add either an FB or FC block it only allows selecting STL, LAD or FBD. Do I simply type in the SCL syntax in an STL block? Here's exactly what I'm attempting to do. I have a set of parameters which I've grouped into a UDT. I've made a DB consisting of an array of this type. I would like to select a out of the array using an indexed instruction. I'd initially be selecting the entire group, not an individual component. db.param 'i' would be either a MW or a DBW. I would then move the selected parameters into a working group similar to your example except for the index db.working = db.param It appears you can use an indexed instruction for some commands such as OPN but not others. It does not appear that I can do a load instruction in this fashion. So I can do a L DB103.DBW10 but not L DB103.DBW[MW10] I can do indexing relatively simply on the AB, GE platforms, and of course in C, Pascal or Basic. If I can't get the indexing to work, I would need to write a FC block for every move I wanted to do. Thats the long and ugly way. I've tried doing this with pointers (Mr. Berger does not explain this very well. lots of detail on where the pointer exists in memory, but not a lot on using the pointer itself). I can't seem to get the syntax for a DB pointer correct, or I don't understand the explanation, which is also very possible. Hey, I never said I wasn't stupid too. I tried using the BLKMOV instruction but I receive an error that the block can't be placed.

Share this post


Link to post
Share on other sites
ok so I am stupid.....appears you use SCL in the source folder. Looking at the coding, can you use a variable instead of the array number? as example, could I use MW10 as the array index? myDB1.work := myDB.params[MW10] would this also work to select an individual item in the UDT? myDB1.work.param1 := myDB.params[MW10].param1

Share this post


Link to post
Share on other sites
oh yeah....i forgot to add....when I purchased the book there was no CD included.....so no, I don't get to look at any of the examples.

Share this post


Link to post
Share on other sites
That certainly reduces the value of the book. I shall see if I can locate the samples somewhere.

Share this post


Link to post
Share on other sites
I missed this post. When you attempt to download the SFC20, what message do you get ? In the dialog box that appear with the message, there will probably be a "Help" or "Details" button. This button will give you more specific explanation as to what goes wrong. SFC20 is one of the really fundamental blocks in S7. It MUST work. Another thing you can do, go online and view what blocks are on the CPU. A long list of SFBs and SFCs shall appear. SFC20 should be there with the other SFC blocks. Yes SCL is an option. Unfortunately STEP7 isnt exactly cheap, and SCL doesnt make it cheaper. If you over a period of 3 years work on more than 2-3 projects, then it is definitely worth it, and the expense is neglible anyway compared to what else you have to spend on hardware. Btw. if you have to purchase an upgrade to STEP7, you should consider to upgrade to Pro. It is a more favourable bundle than just buying SCL. The type of indexing you can do with AB even in Ladder is not possible in S7, except in SCL. In STL you have to use pointers, and even if I have programmed S7 for many years, I try to avoid them. This seems to vary from person to person. I know people that seems to love both STL and pointers. As to your requirements, here is yet another example with a complete structure copied into an array via an index: TYPE UDT1 STRUCT bi1, bi2, b3 : BOOL; in1, in2, in3 : INT; r1, r2, r3 : REAL; END_STRUCT END_TYPE DATA_BLOCK DB1 STRUCT struct1 : UDT1; struct2 : UDT1; END_STRUCT BEGIN END_DATA_BLOCK DATA_BLOCK DB2 STRUCT array1 : ARRAY[1..10] OF UDT1; array2 : ARRAY[1..10] OF UDT1; END_STRUCT BEGIN END_DATA_BLOCK FUNCTION FC1 : VOID VAR_TEMP index : INT; tempstruct : UDT1; END_VAR tempstruct.bi1 := TRUE; tempstruct.in2 := 123; tempstruct.r3 := 45.67; DB1.struct1.r2 := tempstruct.r3; // copying a complete structure DB1.struct1 := tempstruct; // a complete structure copied into an array structure DB2.array1[1] := DB1.struct1; // a complete structure copied into a structure via an index index := 3; DB2.array2[index] := DB1.struct1; END_FUNCTION

Share this post


Link to post
Share on other sites
You can do this in STL but it would entail using the ANY type pointer and (sorry) SFC20, at least that would be maintainable to someone without SCL programming package. I would do this by calling a FC or FB with the first UDT entry as one of the inputs and an integer offset value. In the FC/FB you can move the start address into a TEMP ANY address and then manipulate that to get to the offset you want. The TEMP ANY parameter would contain the starting point and the length which would help with the offset calculations. I'm not sure if this forum allows pointing to another forum, but LAR in another forum would probably write a very good routine for you quickly if you asked nicely and didn't call our 'precious' names Jesper knows who I mean

Share this post


Link to post
Share on other sites
Its a two week delivery for the SCL package, and the customer doesn't want to upgrade to the PRO version. I have no need as none of my other Siemens equipment requires it. I would upgrade because of the time savings, however its not practical at this time. As far as using the ANY POINTER, if anything could be less well described in a programming reference, I'd like to see it. Other than telling me where the pointer resides in memory (I'm at a loss as to why the physical memory location is of any importance in a programming reference), and some obscure information, its barely useful. It would be a complete waste of time to even attempt to try to implement and debug, even if someone else forwarded the code. I'm sure these functions have some purpose for a plc, for the life of me, I certainly can't fathom it (i'm a stupid american!!). I'm simply going to limit the amount of information I allow in the application and write a bunch of functions to copy the information from place to place longhand. Its a pain in the booty, but I simply don't have the time to spend figuring out how to actually invoke pointers, or why standard functions don't work. If I called Siemens, the engineer would probably want to know the impedance characteristics of my input devices so he could understand my application. When I didn't know he'd be amazed that I didn't do a full engineering study on my relays and push buttons before even attempting to program the cpu. Probably why the function doesn't work???

Share this post


Link to post
Share on other sites
Standard functions do work, they do not automatically reside in your project though, you have to put it in which is what I suspect is the problem with your program. Open the library folders and drag it into your project and it will work. As far as describing the ANY pointer, open the help and look in the index section (A.3.4.5), there is a very good description of the make up of the any pointer. There is a learning curve but its well worth it, it will reduce you code significantly, once you have the ability to move any offset UDT into a local TEMP area and back again it will make your code far more manageable. here is a link to a thread about the very thing that you request Dynamic data moving in step 7

Share this post


Link to post
Share on other sites
Hi again Bob. You are probably struggling with SFC20 BLKMOV. Here is the scoop: For the SRCBLK and DSTBLK parameters, do not enter the values with absolute addresses, use symbols. (Since you complain about absolute addressing, then why dont you switch to only using symbolic addressing.) And simply grab a complete structure, or substructure, and 'throw' it into another structure of the same size. For example // from one structure element into a similar structure inside an array CALL "BLKMOV" SRCBLK :="MyDB1".struct1 RET_VAL:=MW100 DSTBLK :="MyDB2".array1[1] NOP 0 or // from one full array into another similar array. Notice the missing []-brackets CALL "BLKMOV" SRCBLK :="MyDB2".array1 RET_VAL:=MW100 DSTBLK :="MyDB2".array2 NOP 0

Share this post


Link to post
Share on other sites
Yes, I did think of adding that as a suggestion, as it is easier and the UDT form and length is automatically put in.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0