Page 1 of 1

Last bit of code being placed first

Posted: Mon Jul 29, 2019 7:09 pm
by David_Lelen01
I seem to be having a very strange problem of whatever the last code written to a g-code file is being placed first in the code. Attached is the output code and the post-processor code. This problem occurs regardless of the exact code written last. Does anyone have any insight? I'm sure there are better ways to write the post also and i am open to suggestions, but that is not the focus.

Re: Last bit of code being placed first

Posted: Tue Jul 30, 2019 2:04 pm
by Les Newell
The post only writes to the file when you get to the end of the line. For example in your case OnFinish() does not output an end of line so 'END' gets stuck in the buffer until you run the post again. Use

Code: Select all

post.Text ("END\n")
instead. It is quite common to see this issue if your post throws an error. The current line being worked on stays in the buffer. I really must get around to fixing this bug.

Your doxy functions make the code a bit hard to understand. You may be better off with something like this:

Code: Select all

function doxy(prefix, fva)
   post.Text(prefix)
   if(endX < 1e17) then
	  post.NonModalNumber(" X",endX * scale,"0.00##")
   end

   if(endY < 1e17) then
	  post.NonModalNumber(" Y",endY * scale,"0.00##")
	  post.Text (fva)
   end
-- should post.Text (fva) be here instead?
end
Now OnMove() could look like this:

Code: Select all

function OnMove()
   if (math.hypot(endX - currentX, endY - currentY) < 0.06) then return end
   if (leadinType == curLead) then
      if (leadinType == 0) then
         doxy("G1", " FVA1\n")
      else
         doxy("G1", " FVA14\n")
      end
   else
      if (leadinType == 0) then
         post.Text("G147\n")
         doxy("G1", " FVA1\n")
      elseif (leadinType == 1) then
         post.Text("G146\n")
         doxy("G1", " FVA14\n")
      elseif (leadinType == 2) then
         post.Text("G148\n")
         doxy("G1", " FVA14\n")
      end
      curLead = leadinType
   end      
end
In OnArc your doxy calls would mostly be like this: doxy("G3", "")

As your programming skills improve you find yourself writing less code to achieve the same result in a more readable way. At the end of the day if your code works, that is what matters most. Style and readability helps maintenance but if something works that is often good enough.

By the way, what controller are you using?

Re: Last bit of code being placed first

Posted: Tue Jul 30, 2019 2:48 pm
by David_Lelen01
Ahh, that makes sense. It just threw me off since i havent seen this happen with the other post for our plasma machine. I didnt even notice that post has the "\n" in the OnFinish() function.

Yes, i am quite new to programming and have a lot to learn for efficiency and simplicity in code. Thank you very much for the suggestions, that does make it much easier to understand! And yes, the "post.Text (FVA)" should be relocated. Usually i just get the code working and then go back and look for improvements. Sadly the looking for improvements stage doesnt happen often.

I honestly do not even know what the controller for this machine is. It is an italian waterjet machine and all the code and programs are in broken english. There are no help files, so it is very difficult to use. I am writing this post by looking at the g-codes we have been running and trying to get the same result. It has been a challenge for sure. The machine software is by Taglio Software House, called LogoTag WaterJet.

Thank you again for your help, i'm sure you stay quite busy between the forum and further development of the software.

Re: Last bit of code being placed first

Posted: Tue Jul 30, 2019 2:59 pm
by Les Newell
The Italians are terrible for mangling g-code in their controls. They do all sorts of odd stuff for no apparent reason.

Re: Last bit of code being placed first

Posted: Tue Jul 30, 2019 3:38 pm
by David_Lelen01
Yes, i totally agree, it is quite a confusing mess and lots of redundant code. Also no help files for machine specific codes.