Macroloop - Log Gcode File Load + Log File Run Time

Here is where you can drop off Examples of WORKING macros,plugins,Gcode programs , macro Wizards etc.
Please give a brief description of what it is and how it works.

Macroloop - Log Gcode File Load + Log File Run Time

Postby Robertspark » Thu Jul 20, 2017 12:24 am

Macroloop - Log Gcode File Load + Log File Run Time

Please find attached two macroloops (you only need one loaded).

M1002.txt is the basic macroloop which will just log when a file is run (the time the file is started to run)

M1003.txt is a macroloop that will log when a gcode file is loaded and when the file is run.

Either macro could be altered to include when a gcode file was ended (let me know if you require this).

The default file location for the text file to be saved is the "C:\UCCNC\Example_codes\" folder although you can change this as you require....

M1002 and M1003 save to different files (so you could load both macro loops if you require or do so by error...)

You could also change the file extension to "csv" from "txt" should you wish to save the file to comma seperated value and open in MS Excel / orther spreadsheet application....

Save the files to the relevant profiles folder which matches your profile that you are running.

Load the macroloop files via the Configuration screen >> General Settings screen >> Macroloops button
Attachments
M1003.txt
macroloop that will log when a gcode file is loaded and when the file is run.
(1.34 KiB) Downloaded 60 times
M1002.txt
macroloop which will just log when a file is run (the time the file is started to run)
(707 Bytes) Downloaded 57 times
Rob

Einstein ― “If you can't explain it to a six year old, you don't understand it yourself”
UC400eth, UC300eth, UCCNC v1.2046, Neuron Lite.
UCCNC Macro Manual
Robertspark
 
Posts: 615
Joined: Sat Sep 03, 2016 4:27 pm
Location: Nr Liverpool, England

Re: Macroloop - Log Gcode File Load + Log File Run Time

Postby A_Camera » Thu Jul 20, 2017 7:25 am

Nice work, even if personally I don't have use for it, but if I was doing paid job or was concerned about tool wear I'd be very interested in it since I can see benefits with some small modifications.

One which you mentioned already, the end time, the other is the used tool numbers. This may be a little complicated since basically what you have to do is log start and stop time and tool number of each tool, not just the g-code start and stop. I don't know how much effort it takes, but I think such log function is useful if you want to calculate costs, machine and tool wear to be charged a customer. Even if you work with fixed rates it is important for you to know that your rates are right and covering the costs you have plus giving you the profit you want on a job.
A_Camera
 
Posts: 410
Joined: Tue Sep 20, 2016 11:37 am

Re: Macroloop - Log Gcode File Load + Log File Run Time

Postby Robertspark » Thu Jul 20, 2017 7:43 am

I can do all of that via macroloop, let's see if I can do 2 more macroloops logging the other two paramaters, because you could save a file per gcode file (job file) to log the time per job (gcode file)
Rob

Einstein ― “If you can't explain it to a six year old, you don't understand it yourself”
UC400eth, UC300eth, UCCNC v1.2046, Neuron Lite.
UCCNC Macro Manual
Robertspark
 
Posts: 615
Joined: Sat Sep 03, 2016 4:27 pm
Location: Nr Liverpool, England

Re: Macroloop - Log Gcode File Load + Log File Run Time

Postby dezsoe » Thu Jul 20, 2017 7:48 am

Nice and useful work. :)

I have some remarks on it.
1. The two macros use the same status variables: #900. This may cause missing log entries if both macros are running.
2. If you use the while(loop) technique then use should use a local boolean instead of #900, because the loop will not exit until it is not stopped or UCCNC exits.
3. You can omit the while(loop) and #900 if you use a static boolean as status variable. See my post: #Events: a little surprise from UCCNC
4. Instead of "C:\UCCNC\..." use Application.StartupPath + "\\Example_codes\\logfile.txt". E.g. I don't have C:\UCCNC folder at all. (At the moment I have 38 versions installed on E:\UCCNCNF\<versionnumber> folders. :))
dezsoe
 
Posts: 255
Joined: Sun Mar 12, 2017 4:41 pm
Location: Csörög, Hungary

Re: Macroloop - Log Gcode File Load + Log File Run Time

Postby Robertspark » Thu Jul 20, 2017 9:13 am

dezoe,

Thanks for the comments, much appreciated.

with regards to:
1. The two macros use the same status variables: #900. This may cause missing log entries if both macros are running.
2. If you use the while(loop) technique then use should use a local boolean instead of #900, because the loop will not exit until it is not stopped or UCCNC exits.


the use of var 900 was a carry over / remainder / leftover from when I was not using the while loop and needed a flag to keep track of if the previous status of the gcode file / run status had changed.

Yes, I should have changed it to a local variable bool / otherwise to

with regards to:
3. You can omit the while(loop) and #900 if you use a static boolean as status variable. See my post: #Events: a little surprise from UCCNC


You've mentioned this before to me, basically I don't understand it or how it works / see how to get benefit from it (remember I am a non-programmer.... day job is totally different)
I understand the tri-state button but don't see how it's of benefit to use it with a macroloop such as this. Any chance you could elaborate / explain a little more / given another example?


with regards to:
4. Instead of "C:\UCCNC\..." use Application.StartupPath + "\\Example_codes\\logfile.txt". E.g. I don't have C:\UCCNC folder at all. (At the moment I have 38 versions installed on E:\UCCNCNF\<versionnumber> folders. :))


Thanks (again as I'm not a programmer and am just learning this stuff from books + net + wherever) I wasn't aware that I could use that, I'll change my code from now on to use Application.StartupPath

Question..... I've never understood the purpose of the "@" before the path.... do I still need it with Application.StartupPath? The reason why I ask is I had problems running the macros before when I did not use the "@"

Thanks for taking the time to review and comment, again much appreciated.
Rob

Einstein ― “If you can't explain it to a six year old, you don't understand it yourself”
UC400eth, UC300eth, UCCNC v1.2046, Neuron Lite.
UCCNC Macro Manual
Robertspark
 
Posts: 615
Joined: Sat Sep 03, 2016 4:27 pm
Location: Nr Liverpool, England

Re: Macroloop - Log Gcode File Load + Log File Run Time

Postby dezsoe » Thu Jul 20, 2017 10:48 am

Rob,

First, about the "@". I also didn't know (I'm not a C# guru...), but Google says: it disables the escape sequences in strings. (That's why I have "\\" in my code and not "\". Now I know that I could write @"\foldername\filename". :))

Second. If you write a macroloop macro then it's called by the system every 50ms. If you don't use the while(loop) cycle the macro will exit after finished. Next time it starts it will declare its new variables without the last values. But! If you declare static variables (you must do it after the #Events) then the values of the static variables will not be lost when the macro exits. This way you can declare your status flag without using a memory location of g-code variables and without holding the macro in a while(loop) cycle. And you can use any type of variables, not only double.
dezsoe
 
Posts: 255
Joined: Sun Mar 12, 2017 4:41 pm
Location: Csörög, Hungary

Re: Macroloop - Log Gcode File Load + Log File Run Time

Postby Robertspark » Thu Jul 20, 2017 4:33 pm

i can't get this #Events to work,

tried static bool, static int, static double

I end up with this as an errorlog:

UCCNC macro compiler error log file
--------------------------------------
Last error dated: 7/20/2017 5:11:05 PM
In macro: M1007
--------------------------------------
CS1519 | in line: 30 | error text: Invalid token 'while' in class, struct, or interface member declaration
CS1519 | in line: 30 | error text: Invalid token ')' in class, struct, or interface member declaration
CS1519 | in line: 35 | error text: Invalid token 'if' in class, struct, or interface member declaration
CS1519 | in line: 35 | error text: Invalid token '(' in class, struct, or interface member declaration
CS1519 | in line: 38 | error text: Invalid token '!=' in class, struct, or interface member declaration
CS1519 | in line: 43 | error text: Invalid token 'using' in class, struct, or interface member declaration
CS1002 | in line: 43 | error text: ; expected
CS1519 | in line: 45 | error text: Invalid token '(' in class, struct, or interface member declaration
CS1519 | in line: 45 | error text: Invalid token '+' in class, struct, or interface member declaration
CS1519 | in line: 45 | error text: Invalid token ')' in class, struct, or interface member declaration
CS1519 | in line: 46 | error text: Invalid token '(' in class, struct, or interface member declaration
CS0116 | in line: 49 | error text: A namespace does not directly contain members such as fields or methods
CS1022 | in line: 50 | error text: Type or namespace definition, or end-of-file expected
--------------------------------------



Don't look too much into the code as I know it needs tidying up, although if I convert it to use #variables it will work fine (sort of, not tested the cycle stopped, cycle ended yet).

Code: Select all
// UCCNC Macroloop to log when gcode file was loaded and when running gcode file

// Robertspark

// Revised: 20/07/2017 (thanks to Dezsoe)
//      to use #Events
//       to use "Application.StartupPath + " for StreamWriter path (in case of non c:\uccnc path)


strCurrGcodeFilename = exec.Getgcodefilename(); // Get filename of current loaded gcode file

 if (strCurrGcodeFilename != strOldGcodeFilename)  // check if current gcode file has not been loaded / logged before
 {
   string strCurrDateTime = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss tt"); // get current Date & Time

         using (System.IO.StreamWriter writer = System.IO.File.AppendText(Application.StartupPath + @"\Example_codes\LoadRunLogFile.txt"))
         {
            writer.WriteLine("File Loaded: " + strCurrGcodeFilename + " , " + strCurrDateTime);
            writer.Flush();
         }
 
   strOldGcodeFilename = strCurrGcodeFilename;
 
 }


if (AS3.GetLED(54)) // Waits for the cycle start LED on the main screen.
{

   if (!bCycleStartFirstRun) // run only once per cycle start LED active event
   {

      string strCurrDateTime = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss tt"); // get current Date & Time

         using (System.IO.StreamWriter writer = System.IO.File.AppendText(Application.StartupPath + @"\Example_codes\LoadRunLogFile.txt"))
         {
            writer.WriteLine("File Running: " + strCurrGcodeFilename + " , " + strCurrDateTime);
            writer.Flush();
         }

      bCycleStartFirstRun = true ;  // set flag
   }
}
else
{

         if (AS3.GetLED(232) && bCycleStartFirstRun )
         {
            
            string strCurrDateTime = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss tt"); // get current Date & Time
      
         using (System.IO.StreamWriter writer = System.IO.File.AppendText(Application.StartupPath + @"\Example_codes\LoadRunLogFile.txt"))
         {
            writer.WriteLine("Cycle Ended: " + strCurrGcodeFilename + " , " + strCurrDateTime);
            writer.Flush();
         }
         
         if (!AS3.GetLED(232) && bCycleStartFirstRun )
         {
            string strCurrDateTime = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss tt"); // get current Date & Time
      
         using (System.IO.StreamWriter writer = System.IO.File.AppendText(Application.StartupPath + @"\Example_codes\LoadRunLogFile.txt"))
         {
            writer.WriteLine("Cycle Stopped: " + strCurrGcodeFilename + " , " + strCurrDateTime);
            writer.Flush();
         }
   
         }
         
   bCycleStartFirstRun =  false ; // clear flag (when cycle start not active)
}
   

#Events
// define static variables

static bool bCycleStartFirstRun = false ;
static string strCurrGcodeFilename = "" ;
static string strOldGcodeFilename = "";
Rob

Einstein ― “If you can't explain it to a six year old, you don't understand it yourself”
UC400eth, UC300eth, UCCNC v1.2046, Neuron Lite.
UCCNC Macro Manual
Robertspark
 
Posts: 615
Joined: Sat Sep 03, 2016 4:27 pm
Location: Nr Liverpool, England

Re: Macroloop - Log Gcode File Load + Log File Run Time

Postby cncdrive » Thu Jul 20, 2017 5:13 pm

Hi Rob,

One issue what I've quickly noticed is this line:

Code: Select all
//      to use #Events


The problem with this line is that the macro compiler will find the #Events keyword in this line and so it will think your Events start after this line.
It does not know that it is a comment, so do not type the #Events word anywhere in your macro anywhere else, only where your Events really starts.
cncdrive
Site Admin
 
Posts: 1467
Joined: Tue Aug 12, 2014 11:17 pm

Re: Macroloop - Log Gcode File Load + Log File Run Time

Postby Robertspark » Thu Jul 20, 2017 5:52 pm

Thanks,

I'll keep re formatting / editing it, untill I figure it out

My post below is one of frustration with the long load of errors being flung up
Rob

Einstein ― “If you can't explain it to a six year old, you don't understand it yourself”
UC400eth, UC300eth, UCCNC v1.2046, Neuron Lite.
UCCNC Macro Manual
Robertspark
 
Posts: 615
Joined: Sat Sep 03, 2016 4:27 pm
Location: Nr Liverpool, England

Re: Macroloop - Log Gcode File Load + Log File Run Time

Postby Robertspark » Thu Jul 20, 2017 6:37 pm

Hey, fixed.... well sort of thanks cncdrive,

(I didnt know that it ignores the comment // when you put a # after it ..... too many comments.....)

Note, it's not working right, I'll update the two macros below with a complete working set shortly


Code: Select all
    // UCCNC Macroloop to log when gcode file was loaded and when running gcode file

    // Robertspark

    // Revised: 20 07 2017 (thanks to Dezsoe)
   

    strCurrGcodeFilename = exec.Getgcodefilename(); // Get filename of current loaded gcode file

     if (strCurrGcodeFilename != strOldGcodeFilename)  // check if current gcode file has not been loaded logged before
     {
       string strCurrDateTime = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss tt"); // get current Date & Time

             using (System.IO.StreamWriter writer = System.IO.File.AppendText(Application.StartupPath + @"\Example_codes\LoadRunLogFile.txt"))
             {
                writer.WriteLine("File Loaded: " + strCurrGcodeFilename + " , " + strCurrDateTime);
                writer.Flush();
             }
     
       strOldGcodeFilename = strCurrGcodeFilename;
     
     }


    if (AS3.GetLED(54)) // Waits for the cycle start LED on the main screen.
    {

       if (!bCycleStartFirstRun) // run only once per cycle start LED active event
       {

          string strCurrDateTime = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss tt"); // get current Date & Time

             using (System.IO.StreamWriter writer = System.IO.File.AppendText(Application.StartupPath + @"\Example_codes\LoadRunLogFile.txt"))
             {
                writer.WriteLine("File Running: " + strCurrGcodeFilename + " , " + strCurrDateTime);
                writer.Flush();
             }

          bCycleStartFirstRun = true ;  // set flag
       }
    }
    else
    {

             if (AS3.GetLED(232) && bCycleStartFirstRun )
             {
               
                string strCurrDateTime = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss tt"); // get current Date & Time
         
             using (System.IO.StreamWriter writer = System.IO.File.AppendText(Application.StartupPath + @"\Example_codes\LoadRunLogFile.txt"))
             {
                writer.WriteLine("Cycle Ended: " + strCurrGcodeFilename + " , " + strCurrDateTime);
                writer.Flush();
             }
         
          }
         
             
             if (!AS3.GetLED(232) && bCycleStartFirstRun )
             {
                string strCurrDateTime = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss tt"); // get current Date & Time
         
             using (System.IO.StreamWriter writer = System.IO.File.AppendText(Application.StartupPath + @"\Example_codes\LoadRunLogFile.txt"))
             {
                writer.WriteLine("Cycle Stopped: " + strCurrGcodeFilename + " , " + strCurrDateTime);
                writer.Flush();
             }
       
             }
             
       bCycleStartFirstRun =  false ; // clear flag (when cycle start not active)
    }
       

    #Events
   
    static bool bCycleStartFirstRun = false ;
    static string strCurrGcodeFilename = "" ;
    static string strOldGcodeFilename = "";


Rob

Einstein ― “If you can't explain it to a six year old, you don't understand it yourself”
UC400eth, UC300eth, UCCNC v1.2046, Neuron Lite.
UCCNC Macro Manual
Robertspark
 
Posts: 615
Joined: Sat Sep 03, 2016 4:27 pm
Location: Nr Liverpool, England

Next

Return to UCCNC TOOL BOX

Who is online

Users browsing this forum: No registered users and 2 guests