Hello Guest it is April 20, 2024, 09:21:42 AM

Author Topic: call to new gcode from end of exisst gcode  (Read 892 times)

0 Members and 1 Guest are viewing this topic.

call to new gcode from end of exisst gcode
« on: August 28, 2018, 11:14:35 PM »
hi
i have now new machine with auto loading ,that mean when machine finish one board ,its unloading the parts and load the new board
for that reason i want chain all files together
that mean in the end of one gcode there will be some M function that will call the next file(sure M function will folow the path or the name for the next file)
how can i write that M function in Mach?
(the  insert of the M function will be done in my pp  )
thanks
Re: call to new gcode from end of exisst gcode
« Reply #1 on: November 20, 2018, 01:31:12 AM »
It doesn't sound like you want to be trying to do what you are doing with just g code.  If you have many different discreet files that you need to load, you will have to use a macro and do the whole thing in Lua.  You can run subroutines in g code but it sounds like you probably need more than that. 
Here is an example of a function in Lua that will open a file and place each line of code (could be g code) into an array called file_data:

function populate(filename)                 --function to put saved parameters in appropriate boxes
   local rc            --return code     
   local file_data = {}      --array for holding data
   local file_path = c:\your directory .. filename
   if io.open(file_path,"r") == nil then   --if the file cannot be opened       
      error("error loading file: " .. filename)
      return nil, nil
   else   
      io.input(io.open(file_path,"r"))              --open the file
   end                                         
   for i = 0, 200 do                                 --read the file line by line, and place each line in the next position of the array
      file_data = io.read("*line")         
   end
   io.input():close()        -- close current file
   return file_data, mc.MERROR_NOERROR
end

or, more simply you can just dump the entirety of a file into a string called gcode

            io.input(io.open(file path,"r"))   --open file in read mode
            gcode = gcode .. io.read("*all")  --copy the whole thing to a variable called gcode
        end
        io.input():close()        -- close current file

then use mc.mcCntlGcodeExecuteWait(inst, gcode)   to execute the file


Just in case you think subroutines in g code would work, here is an example:

m98 p010 L2 (call subroutine 010, repeat 2 times)

O010           (subroutine 010) (this could be the code for your first part?)
 g0 x1
 g0 x0
M99             (end of subroutine)

O011           (subroutine 011)(second part?)
etc.

Hope that helps!