Using Siemens Test Suite Advanced Style Guides in TIA Portal
9 min video
Siemens Test Suite Style Guides allow you to automate the enforcement of programming standards. You can set up your rules and share them with team members, contractors, OEMs, etc. to ensure that your code is consistent, readable, and accurate. In this video, we show you how to set everything up and check code for a few of our top rules.
Links mentioned in the video:
Questions? Get in touch!
Learn more about Siemens Industrial Automation Products.
Intro
Hey everyone, thanks for joining! I’m Liz, co-founder of Outlier Automation, a Control Systems Integrator. Today, we’re going to talk about Siemens’ Style Guides in TIA Portal. We’ll start by looking at why PLC programming styles matter and how Style Guides can help - and then we’ll go through an example of how to use it.
PLC Programming Styles
Let’s start by gaining a practical understanding of why programming style matters
Here’s an example of poor style choices:
First, we see inconsistent block naming which makes the project tree more difficult to read. Also, the name “MysteryDB” gives us no indication of whether the datablock is global or instance memory.
Second, we see that the “bMode” tag has no comment, so we don’t know if the normally-closed contact represents auto mode, manual mode, or something completely different.
Third, these tags are all directly linked to IO, but they all use different naming conventions. If all IO tags shared a common prefix, it would be immediately clear where the tag comes from just by reading its name.
Siemens Programming Guide
When we’re making decisions about programming styles at Outlier, we like to refer to this cheat sheet that Siemens’ released with their own style guide detailing best practices to optimize readability, performance, and memory usage. If you don’t have your own programming styles already check these out for a great starting point. There’ll be a link to the document in the description of this video
Best Practices
When it comes to best practices, here are some of the tips that we’ve come up with over the years:
Choose one naming convention and stick with it! There are many options, but consistency is the key to doing style right.
Communicate style requirements to all developers so that everyone is on the same page – and make sure you maintain a document with the requirements that can be quickly and easily referenced.
Carefully consider the use cases of any and all of your rules. Conforming to a style does create overhead for programmers, but the benefits should outweigh the inconvenience. Make sure you have a demonstrated reason to add rules.
Finally, to combat the overhead that comes with enforcing programming styles, use an automated tool to lighten the load
What are Style Guides in Portal
So, what are style guides in Portal? They’re Siemens’ integrated tool to automate the enforcement of programming conventions! The tool has access to metadata for code blocks, datablocks, udts, and tags so it can check rules like the length of the object’s name, the existence or content of comments, prefixes and suffixes, upper or lower casing, and quite a bit more.
Siemens Style Guide
Siemens has released their own best practices rule set which you can import directly into your project. You can download this rule set using the link in the description of this video.
Advantages
Combining Siemens’ style guides with a robust standard can bring some big advantages to your workflow:
Style guides make it much easier to enforce standards. You can export and send your rule set to OEMs, contractors, or your internal team.
Second, you can train engineers faster because the consistent rules make ramp-up simpler.
Third, you’ll find yourself spending less time in code reviews because you can check the syntax of the whole project with the click of a button.
Environment Setup
The best part about Siemens’ style guides is that they are easily integrated into TIA Portal. Check the video description for a link to our first video on Siemens’ Test Suite where we describe and show where to find the required downloads. Now I’ll pass it off to Nic to show us a demo.
Style Guides Demo in Portal
Alright let's get into this demo. To start, I've got open the same program that we looked at before. Let's go to Test Suite and then Style Guide to add a new rule set.
Block Name Length
So let's set up our first rule to catch this super long FB name. So we'll call it “Block Name Length”. Then, we have our type and object selector. Under the object selector you can see all the different types of objects that we can make rules about. Kind of like Liz was mentioning earlier we have the instance data blocks, datatypes, tags, constants… For this rule, we’ll just use the code block. Then, for type we’ll choose name length. So when we expand this caret that'll show us all the attributes of this rule so if the name is greater than 24 characters we should get an error. And there it is!
CamelCase Blocks
So let's attack casing next. We have this “FbCasingIsImportant”. We’ll call this rule “Camelcase Blocks”. Code blocks is already selected, but for the type we’ll put casing. Drop down the caret - camel casing is not set will be the violation and we’ll disable our first rule. Right, so now we can see that OB Main is a conflict and then FbCasingIsImportant, but actually I don't want to enforce this for Main so let me just make this a warning here in the category. I can set it to error or warning. If we run it again we'll see the violation still comes up but it reports it as a warning instead.
Block Prefix
Another convention that could clean up this tree is if we introduce prefixes on the FBs so let's make another rule called “Block prefix”. It'll be for code blocks but we'll choose the type prefix suffix. then if I drop down the caret, it starts with not equal to and I want them to start with “fb”. Now, I know that Main is gonna break this rule too so I'll just set it as a warning again. Let's see. OK yeah, so like I thought Main shows up and that “prefixes are nice” block.
Tag Comments
OK, now another thing that Liz pointed out is that our tags don't all have comments. So, let's go to the tag table, we see “bMode” does not have a comment so we’ll make a new rule and call it tag comments. This time we're going to point it at tags so we’ll use the object selector - here we go. Then for the type we’ll choose metadata which is kind of a catchall for a bunch of data about the tags. So for the specific property you can see there's these different entries. We're going to use comment and make sure that comment exists so the violation condition would be not exist. Let's run that. There it is.
IO Prefix
Now for this last one, let's go back to the tag table. Let's say for whatever reason we want to put the prefix “IO_” on these tags. So let's make another rule called “IO prefix”, this will be similar to the block prefix, but we’ll use the object selector again to point to the tags. The type will be prefix suffix and we just want to make sure that we start with and let's just say a capital “IO” with an underscore. Yep, so we can see these three tags didn't have the prefix but “IO_ProcessRunning” did.
Issue Correction
OK, so to put it all back together then let’s close this. I'll enable all the rules and let's run them all at the same time. So we can see, here's the results - it’s this huge print out, but actually I can disable the info messages by clicking right there and the warnings too so now we're just looking at errors. If I double click right here, it actually takes me straight to the issue so I can add my comment in. Then, if I go back to my rule set and run it again we see there are no errors related to the tag comment rule. And we pretty much follow the same process to fix the rest of the these errors. So this is definitely an interesting tool for project leads and project managers to make sure that all the developers on the project are following the right standards and then it's pretty useful for the developers too 'cause they can run the script so quickly and then just double click on the error or hit that go to arrow to take them straight to the violation.
Outro
And that’s all for today! Thanks for watching! If you have any questions, send us a message at info@outlierautomation.com and you can check out the other resources on the blog section on our website.