User Tools

Site Tools


mycnc:global_variables:20000-20100

PLC program diagnostics via Debug Messages

When diagnosing the way in which a PLC program operates (for instance, checking some values from an arbitrary point within the PLC code, making sure the final output values are correct, correcting PLC logic, etc), it is often useful to utilize the debug global variables (#20000-#20100). This will allow for the PLC procedures to return some value(s) to the Log window:

In the image above, two variables (#20010 and #20011) are sent to the Log window by launching a PLC that contains a command that will be writing some value(s) to these variables. In this example, the Hardware PLC looks the following way:

main()
{
 
  gvarset(20010,100); //output 100 using variable 20010
  gvarset(20011,200); //output 200 using variable 20011
 
exit(99);
};

Note that in the program above, the values are static (100 and 200 respectively), so that every time we run this code, the resulting output in the Log window will be the same. However, the usefulness of the debug messages stems from the fact that they allow the operator to quickly monitor some value that may also be changing over time.

For instance, note that in the code below, the value of variable a will be changing over time, with a new value being produced every second (starting from 4, and ending at 1 in a do-while loop):

main()
{
 
a=4;
 
do {
 
gvarset(20010,a);  //output a debug message
a=a-1; //reduce the variable value by one 
timer=1000;do{timer--;}while(timer>0); //wait one second
 
} while (a>0);
 
exit(99);
};

Then, when we run the PLC containing this code, the following debug messages will be outputted to the Program Log window:

In the GIF above, the values for the variable a are sent to the Log window every second via global variable 20010. This allows for an easy way to debug PLC code and monitor changing variable values.

mycnc/global_variables/20000-20100.txt · Last modified: 2023/12/05 13:42 by ivan

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki