User Tools

Site Tools


debugging_complex_programs

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
debugging_complex_programs [2018/12/26 11:12] – [Running backup on the new device] emozolyakdebugging_complex_programs [2022/01/15 20:50] (current) – ↷ Links adapted because of a move operation 127.0.0.1
Line 1: Line 1:
 +
 +
 ====== Debugging complex scripts ====== ====== Debugging complex scripts ======
  
 ===== Project initialization ===== ===== Project initialization =====
 +
 +
  
 ==== Non - volatile registers ==== ==== Non - volatile registers ====
Line 29: Line 33:
 Remember that registers such as Dxx, CDxx and other internal registers, except for DSxx, return to the initial state (usually 0) after initializing the project (which happens when editing project elements - scripts, registers, connections, etc.). If such registers are used as variables to generate event triggers or conditions for executing other scripts, this can lead to a violation of the execution logic. You should consider this feature when choosing registers as input and output script variables. Remember that registers such as Dxx, CDxx and other internal registers, except for DSxx, return to the initial state (usually 0) after initializing the project (which happens when editing project elements - scripts, registers, connections, etc.). If such registers are used as variables to generate event triggers or conditions for executing other scripts, this can lead to a violation of the execution logic. You should consider this feature when choosing registers as input and output script variables.
  
-===== Differences between write function for internal registers and external =====+===== Differences between write function for internal/external registers =====
  
 There are some differences in the operation of the SetReg and WriteReg functions with respect to internal registers (Dxx, DSxx). These functions directly change the values ​​of the internal registers inside the scan, and do not delay WriteReg writing to the next scan start. Thus, at the end of the scan, the internal register can have a value different from the one at the scan input. Then, for example, a situation is possible where: There are some differences in the operation of the SetReg and WriteReg functions with respect to internal registers (Dxx, DSxx). These functions directly change the values ​​of the internal registers inside the scan, and do not delay WriteReg writing to the next scan start. Thus, at the end of the scan, the internal register can have a value different from the one at the scan input. Then, for example, a situation is possible where:
Line 46: Line 50:
 ===== Debug messages ===== ===== Debug messages =====
  
-It is desirable after the key moments of logic or calculations in scripts to immediately put the functions INFO, ERROR, DEBUG, TRACE, with respectve values at this point, script's name, line number at the beginning. Then these fragments are conveniently searched and analyzed in the communication log. +It is desirable after the key moments of logic or calculations in scripts to immediately put the functions INFO, ERROR, DEBUG, TRACE, with respectve values at this point, script's name, line number at the beginning, etc. Then these fragments are conveniently searched and analyzed in the communication log.  
 + 
 +When there is a lot of records in the communication log, you can filter out unneccerary output from scripts with this [[http://docs.webhmi.com.ua/useful_programs#debug_printing|method]]. 
 + 
 +In the script editor, there is a debugging console, which always prints out the functions INFO, DEBUG, ERROR, TRACE regardless of the system log level settings. If the output changes too quickly to analize, you can slow down the script by changging in execution type to "Execute on register's value change" and link to system time register or another one, slower. 
 + 
 +There are also messaging functions like [[ http://docs.webhmi.com.ua/scripts#writing_to_message_log|AddInfoMessage]], which can be used to write in a separate Messages log. Just take care of using them in logic transition points, otherwise you will get huge number of records generated in every scan from these functions. 
 + 
 +===== Modular principle ===== 
 + 
 +It is recommended that you split complex scripts into simpler and more frequently used functions that you can reuse. Dividing tme into simpler parts, arranging them in the right order and grouping helps to control the logic of the system and makes it easier to set up the system.  
 + 
 +===== Proper commenting ===== 
 +Use commenting you will understand next time you or someone will see you code. 
 +<code lua> 
 +----------------------------------------CALC. DAY ECONOMY -------------------------------------------------- 
 +    LimitMonthDayYesterday = GetReg("LimitMonthDayYesterday1"             -- Yesterday's limit 
 +    HeatEnergyDay = GetReg("HeatEnergyDay"                                -- Heat qty. for yesterday 
 +    WriteReg("SavingDay1", (LimitMonthDayYesterday - HeatEnergyDay))        -- Economy for the day                           
 +------------------------------------------------------------------------------------------------------------  
 +</code> 
 + 
 +===== Step over trick =====
  
-When there is a lot of records in the communication log, you can filter out unneccerary output from scripts with this [[http://docs.webhmi.com.ua/useful_programs#debug_printing|method]]+When you need to run once your script and inspect its result in the console, you can do this as follows: 
 +  *make extra bit register, like "Debug step over bit" 
 +  *change run mode of the script being debugged - execute upon the register's (you've created in the previous step) change 
  
-In the script editor, there is a debugging console, which always prints out the functions INFO, DEBUG, ERROR, TRACE regardless of the system log level settings.+{{ network:2021-08-02_13-51-50.gif?nolink |}}
  
-However, in a large system with many interrelated scripts, when there is a lot of debugging data, it becomes inconvenient to look for the necessary data, especially if you need to track a specific chain of execution of several scripts that can not be called at specific moments, not in each scan. 
  
-In addition, filtering unnecessary information in logs is also useful from the point of view of performance, since operations of permanent recording on a flash card of a large amount of information can reduce system performance. 
  
-You can proceed as follows - assign your debugging function, which will be called only if the debug printing of this script is allowed. For example, you can write the ids of the scripts in the 'debug_ID' string in which debug printing is needed at the moment, and the print function inside the script will look at this number and turn it on or off. For example: 
  
debugging_complex_programs.1545822738.txt.gz · Last modified: 2018/12/26 11:12 by emozolyak

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki