Have you ever encountered such a situation: when your PLC program is getting bigger and bigger, the names of thousands of elements such as program blocks, variables, background data blocks, etc. in the gradually expanded project begin to become more and more confusing, and in the end even you can't figure out which is which. Don't worry, this is a common worry for many engineers.
In fact, the naming rules of PLC programs are like an invisible order symbol, which prevents you from getting lost in the complex world of programs. So the question is, how can we name these programs in a standardized and efficient way to avoid unnecessary "naming disasters"? Today we will talk about the three common naming rules commonly used by experts.
Why are naming conventions important?
Naming is a small detail, but it can determine the neatness and maintainability of the program. Imagine that without a clear set of rules, your PLC program will become like a mess of noodles, and both you and other engineers will be in a mess when maintaining and modifying it. Especially in the case of multiple modules and multiple programs, the naming must not only be standardized, but also be self-explanatory enough, so that when others look at your program, they can directly understand the role of each element.
Rule 1: Length, characters, and special symbols cannot be ignored
The first step of naming conventions sounds simple, but if not followed, the consequences can be serious.
1. Length limit: up to 24 characters In order to avoid names that are too long and affect the clarity of the program, PLC program names are usually limited to 24 characters. It may not seem like a lot of words, but it is a critical number in the naming process - you can't write a long novel to describe all the variables. Simple and concise, but not without expression, are the elements of a good name.
2. Use English characters We all know the benefits of English characters, the most important of which is that they are case-sensitive, so you can distinguish different meanings in the name. For example, if a variable is named motorSpeed, you can directly see the "speed" of the "motor" from the uppercase and lowercase letters - this is much more intuitive than Chinese names that use mixed uppercase and lowercase letters.
3. Avoid special characters When naming, be sure to avoid using special characters. Why? Because these characters may interfere with the program's parsing and even cause some unexpected errors. Imagine that you added a "#" or "@" to the variable name, and the program might be confused when it sees it - this small mistake can cause a lot of trouble.
Rule 2: Nomenclature competition, choose the right one
At this point, we will enter more specific naming rules. Depending on the different programming elements, we will use different naming methods. By the way, don't forget that today we are going to talk about the naming skills that "experts use", and the simple and crude naming method is no longer applicable.
1. Camel Case Camel case naming is one of the most common rules in PLC program naming. What are its characteristics? Simply put, except for the first word, the first letter of other words should be capitalized. For example, motorSpeedControl, positionSensorData, etc.
Applicable scenarios:
Global variables
Interface parameters of the block
Multiple instance data blocks
UDT type and other elements
This naming method is popular because it has a great advantage: the meaning of each word can be clearly distinguished by distinguishing between uppercase and lowercase letters. In addition, there are no spaces, so the program processing is smoother.
2. Pascal Case PascalCase is similar to CamelCase, the biggest difference is that the first letter of all words should be capitalized, like MotorSpeedControl, PositionSensorData, etc.
Applicable scenarios:
Global DB
Single background DB
Program Blocks
Variable table
Monitoring table and other elements
The advantage of Pascal case naming is its uniformity. The first letter of each word is capitalized, which looks more standardized visually. However, relatively speaking, it is not as easy to distinguish the boundaries of each word as Camel case naming, so it is generally suitable for some relatively fixed elements.
3. Special nomenclature: naming of array variables If you are dealing with array variables, remember a small detail: array variable names should use plural form! Like axesData, motorsSpeed, this not only better expresses the meaning of the array, but also makes the program more intuitive.
Rule 3: The key is the skill of prefix naming
Prefixes are a very useful tool when naming, especially when you have a large number of variables or blocks, prefixes can help you quickly identify and categorize them.
Static variables: Use the stat prefix, such as statMotorSpeed.
Temporary variables: Use the temp prefix, such as tempPositionData.
UDT type: Use the type prefix, such as typeMotorControl.
Multiple instance data blocks: Use the inst prefix, such as instPositionSensorData.
These prefixes can clearly tell you the type and purpose of the variable or block, making the program more standardized and not confusing during maintenance.
In general, although the naming rules of PLC programs seem simple, they are the cornerstone of building high-quality programs. Following these basic naming rules can not only help you avoid naming confusion, but also make the program more readable and maintainable. Next time, you can try to adjust your naming method to make the program naming standardized and efficient.