Programming tips

Test and check your code

In any phase of the project, it is a good practice to regularly check variable values, function blocks or code segments. By doing that you can prevent any potential errors when starting the system, such as lighting switches not working due to a faulty variable setting, or a failure to switch heating due to a mistake in one of the function blocks. For the purpose of debugging, the Mervis IDE features a dedicated Debugging Mode; in this mode, all variable values are displayed in the IDE without the need of checking them individually, allowing you to quickly look for typos, wrong values or other types of mistakes. The system will also automatically highlight function blocks with incorrect configuration, preventing the system from working as intended. Last but not least, the debugging mode will allow you to display a graph of variable value changes over time. Mervis IDE with the Debugging Mode enabled, displaying both variable values and variable value change graph.

Anticipate issues and create fail-safes

Even the best system will sooner or later experience some kind of error. What will your heating system do if a temperature sensor fails? What will happen if a counter on a controller input overflows? Anticipate such issues in advance during the planning phase, from simple component failure to a serious functionality error caused by unauthorized access, and then create hypothetical scenarios for solving such problems. With these scenarios, you can then easily implement fail-safes, fall-backs or emergency modes. For example, if a temperature sensor fails in a heating system, you can program the controller to automatically maintain a pre-defined temperature. You can also use these scenarios to prevent human errors by limiting the access of external users to critical system functions.

Create and follow a naming convention

The random naming of valuables or function blocks, especially in complex projects, can make the work much harder not only for you but also for any other person working on the project. We thus strongly recommend creating a unified template for names of variables and/or function blocks and following that template during the entire work on the project. The Mervis IDE allows you to easily re-name variables, I/Os or controllers - this feature is especially valuable when searching through dozens of variables, where a unified naming convention can save you a lot of time and stress. The latest Mervis release also introduced the Search function, allowing you to search for a specific variable and all of its occurrences across the project.

Make notes, leave comments

During PLC programming, it is easy to lose track of the code, especially when working on complex projects containing dozens of function blocks or hundreds of lines of code. For easier orientation in the code, we recommend to write down notes describing I/O designations, the functionality of a function block, a short guide for the code etc. With such notes, you can easily orient yourself in the code even after a longer time period and also make the project accessible to other users such as colleagues, maintenance crews or customers. When used frequently, a string of comments can then form up a comprehensible "manual" for the project, describing in detail its functionality.  In the case of function blocks, you can insert comments into the Mervis IDE interface. ST users then can write their comments directly into the code. An example of a comment in the Mervis IDE

Follow the tried and tested coding methods and structural techniques

During the PLC programming, try not to create overly complex codes, no matter which method you use. For example, an unnecessarily high number of function blocks will make harder not only the orientation in the project but also the search for any potential errors. We thus recommend decomposing the code as much as possible by looking for repeating segments of the code and re-using them in other parts of the project. A practical example: if you are programming an automated heating system in several rooms, you can create a single code structure using the FBD and then simply paste it for each individual room. By doing that, you will save a large amount of time and the resulting code will have a high level of consistency. An example of repeated use of a single function block for multiple similar applications A detailed look into the contents of one of the function blocks shown on the previous picture

Choose the right programming method

Mervis supports a pair of programming methods - Function Block Diagram (FBD) and Structured Text (ST). Which one to choose? The choice should depend not only on your experience level but also on the type of your project, as both methods have their own pros and cons and are suitable for different kinds of projects. Function Block Diagram is based on so-called function blocks - segments of the pre-defined code made to perform a specific function. By using the FBD you can easily define the controller behaviour routines, set conditions, create input/output counters etc. Thanks to their intuitive design function blocks are a good choice for beginners or smaller automation project. FBD is, however, less suited to complex projects, as the high number of function blocks required may cause performance drops and longer response times. The Structured Text method, having a form of text code, is, on the other hand, suitable for complex mathematical functions or for repetitive conditional tasks. The main advantage of the ST is its ability to encompass even very complex functionality into only a few lines of code. The text code is, however, less user-friendly and is suited rather for the more experienced users. An example of a project using the Function Block Diagram An example of the Structured Text (ST)

Plan in advance

Thorough preparations and planning both on the hardware and the software level will save you a lot of time during the programming itself, reduce the number of errors and improve the overall flexibility of your project. We also recommend keeping in mind that in the future you may need to extend your project by adding new features or components. The more detailed your plan is, the less difficult the realization of your project will be.

iOS 13 & Swift 5 – The Complete iOS App Development Bootcamp

For those of you seeking to master programming for mobile, this next option is a great choice that can offer a variety of benefits. This course will meet the needs of both beginners and those who are already working in programming. At this moment, the price for this Bootcamp is only $12,99, which is a great price given the large number of programming secrets the instructor will reveal to you in the framework of this course. So, in case you are interested in creating software for mobile, this is a course you should try.

Introduction to Coding with HTML, CSS, and JavaScript

If you were looking for a fast and easy way to master the art of programming, our next option was designed right for you. This course covers everything a beginner should know, including the basics of coding with JavaScript, HTML, and CSS, as well as many tips and tricks frequently used by professionals. The course is provided by the International Open Academy, which has already helped over 1 million students around the globe to master the professions of their choice. So, don’t hesitate to check it out.

The Complete Java MasterClass

Want to learn from the best? Then this masterclass that can also be found on Udemy is a perfect bet for you. The instructor of this course, Tim Buchalka, has been in the field of programming for nearly 40 years and has worked for a large number of famous companies, including Mitsubishi, Saab, and many others. What is more, the tutor has 12 courses on this platform, over 1 million students, and a total rating of 4.5 stars out of 5. After taking this course, you will learn the programming best practices and find many handy tips and tricks to make your journey simple and enjoyable.