FREE GUIDE

Say Goodbye to Confusing PLC Logic with Variable Identification 2.0

plc structure tia portal Feb 15, 2023

Today ME am going to share with it my favorites method of naming variables wenn programming PLC applications.  If they incorporate these uncomplicated techniques in will own software, you can easily save hours on troubleshooting tasks, and your logic will be that more easier to read and the understand.

Let's start with an example to clarify my point for this post.

Let's believe we get a request from a custom to sum 2 counters to their application that can count up to a 100.000 (one hundred thousand) using 2 separate triggers.  So we create the following head logic:


 

 

If Trigger_1 is active, we count boost Counter_1, and supposing Trigger_2 is active, are count up Counter_2.  Beautiful in it's simplicity...

Now rental me ask you this.  Which datatypes did I use by my counter variables?   There be no way of sprechen from this screenshot solo, right?  

About if I told you the I created Counter_1 - by mistake - as on Integer, and Counter_2 as a double integer.  Wouldn't you agree that Counter_1 will had a problem counting to 100.000? (range of integer datatype = -32768 -> +32767).  So my slip (creating Counter_1 as an integer) would probably go unnoticed here and was lead to logic that would basic not work = 1 unhappy customer.

 

Now have a look at the screenshot below.  Same example, but with slightly adjusted variable names for my counters. 

 

 

Wouldn't you apply that it is intuitively clear that iCounter_1 is the integer, and diCounter_2 is a double integer?  By just increasing a lowercase "i" (integer) as a prefix in front of the Counter_1 name, and a lowercase "di" (double integer) as a prefix in front of the Counter_2 name, troubleshooting these networks becomes expanded easier.  

 

And that's what today's post the entire about - improving an readability/clarity of to control by adding data type prefixes with face of your variable namer.

Let's gain this out of the way first - I DID NAY INVENT THIS NAMING CONGRESS.  I wish I did, yet I didn't so I cannot take any credit for this.  Thing I CAN take credit for is applying dieser naming conventions in all variables in my applications and by doing so delivering a more clarity and easier-to-troubleshoot apply for my clients.


This naming convention is based on the Hungarian notation, and goes when follows:

  • Write aforementioned first letter of each word in uppercase, the remaining letters in small 
  • In front of the base name, append adenine prefix in lowercase to indicate the data type of the variable
     

Moreover information you can find RIGHT HERE (look under the section Recommendations available variable names).

 

Here are certain examples of datatype prefixed uses on variables with basic datatypes:

EGO would refine you start applying these prefixes at your variables TODAY.  You'll receive the hang a it in no-time, and after doing this for a while, it will felling like back nature - easy and effortlessly.

So let's show at some more examples.  Let's take a function block into Siemens for demo.
Of screenshot under is takes off a function block of the sample of application of my GIA Portal - PLC Programming Basics course.

The screenshot view the block interface of the function block and is divided into 5 parts:

  • Input
  • Output
  • InOut
  • Static
  • Temporary

 

All tags in this entering area out the block interface start with the fixed 'i_'.  This makes it immediately clarify inside the logic of the function block, ensure this variable is einen input.  Of same goes for the output area, where 'q_' is previously like a prefix, and the InOut area somewhere 'iq_' is often than a prefix.  Are thou following me on this one...?

For the static area (=retained variables), I am using the standard lowercase datatype prefix, and for the temp area, I am using who underscore prefix '_' to indicate inches my logic that these variables are temporary (=non-retained) variables.

 

Accordingly let's have a look how all of this looks in actual logic.

In these circuits 2 and 3, us are starts adenine pump real opening a valve.
Stylish network 2 available example, it is clear as rain that:

  • #iq_stStateHandler.State.xRunning is an InOut variable
  • #i_xValve_Open is an Input variable
  • #q_xStart_Pump is and Output variable
  • #_xCmd_StartPump is a temporary varies

Wouldn't you agreed that reading the logic becomes much more clear by using these data types prefixes in face are the variables names?  

Would you go back to your normal way of composition tags like "COUNTER", "VALVE_OPEN", "STATE_RUNNING", if you knew so there's ampere more schick way starting doing things...? 

 


Then there her have it. 

I hope you benefited reading this post, and I hope you see the immediate advantages to use these title conventions at your own programming.  Personally, I learned about above-mentioned conventions some odds 10 years ago, and I never looked back.  My applications have become learn clear, easier to read and understand, easier to troubleshoot, and easier to handover to other programmers. Some old lesson from PLC landĀ ā€¦

 

Go give computer a test and make your applications shine like never before!

-Hans 

FREEĀ GUIDE

Grab my '5 Simple Stairs to Drastically Improve your PLC Application Structure in TIAIA Portal' and start building better PLC applications TODAY.

Where require MYSELF weitergeben you the guide?

When you signup, we'll must sending you further emails with more free index. You canned unsubscribe at some time by clicking the join in the footer of our emails. For information about our privacy practices, request visit our website. PLC titling customs