Machsupport Forum
Mach Discussion => Mach4 General Discussion => Topic started by: rhtuttle on April 09, 2018, 01:19:25 PM
-
I have a macro that generates a string of gcode listed below. If I pass that string to mc.mcCntlGcodeExecuteWait(inst,s) it executes to the x1.320 then skips the rest of the gcode in the string and executes the remaining macro code after the mc.mcCntlGcodeExecuteWait(inst,s). Is there a limitation as to how many characters/commands that can be included and executed in a string with executeWait? This code executes as a gcode file so I know it is not the code.
m3 s1400
g1 x1.5800 f1.000
g1 z0.0000 f12.000
g1 x1.5600 f1.000
g1 z0.2000 f12.000
g1 x1.5400 f1.000
g1 z0.0000 f12.000
g1 x1.5200 f1.000
g1 z0.2000 f12.000
g1 x1.5000 f1.000
g1 z0.0000 f12.000
g1 x1.4800 f1.000
g1 z0.2000 f12.000
g1 x1.4600 f1.000
g1 z0.0000 f12.000
g1 x1.4400 f1.000
g1 z0.2000 f12.000
g1 x1.4200 f1.000
g1 z0.0000 f12.000
g1 x1.4000 f1.000
g1 z0.2000 f12.000
g1 x1.3800 f1.000
g1 z0.0000 f12.000
g1 x1.3600 f1.000
g1 z0.2000 f12.000
g1 x1.3400 f1.000
g1 z0.0000 f12.000
g1 x1.3200 f1.000 (executes up to and including this line)
g1 z0.2000 f12.000
g1 x1.3000 f1.000
g1 z0.0000 f12.000
g1 x1.2800 f1.000
g1 z0.2000 f12.000
g1 x1.2600 f1.000
g1 z0.0000 f12.000
g1 x1.2400 f1.000
g1 z0.2000 f12.000
g1 x1.2200 f1.000
g1 z0.0000 f12.000
g1 x1.2000 f1.000
g1 z0.2000 f12.000
m5
TIA
RT
-
Try adding an actual \n at the end of each line
-
All of them have a \n
-
I am having a problem with a GcodeExecuteWait in my M6 when I do a tool change. It used to work, and I am going to start a thread, Mine is with the new update, using a PMDX 411. In any case, when my is halting due "Requesting a stopped report for Axis 2 motors. The stop comes in for motors 0 and 1 but not 2. I also not that my Z location which is not at zero which is where it is commanded to go, it stops short. In any case you may want to see if your DRO is showing the correct location when it fails..
-
Hi,
could it be that Machs instruction buffer has filled up?
You could try changing the number of 'look ahead lines' in Machs Gen Setup page to 50 say and see whether extra lines from your file are read and executed.
Craig
-
I do not know if there is a limit to string length but imagine there is. Is there a reason you are not just creating a gcode file then loading it and running it?
-
Brett, that's a good idea. RT can make his macro a wizard to generate the code. I used the BH Wizard guts to make a wizard that generates lines of g code.
-
When I first started coding with Mach4 I put everything in the button mouse up script. I generated a line of gCode and then ran mcCntlGcodeExecuteWait for each line. I was told that was wrong that I needed to generate a string consisting of lines of gcode separated by newline characters. Which I did. I then started getting a huge amount of code included in the screen button scripts so I created a module to reduce the amount within the screens. I then thought I should just write macros that called the module's functions and create the string. That's when I ran into this 'new' limitation that nobody seems to know the answer to (lua defaults to 4096 characters for a string which this example doesn't exceed). No one knows if this is due to a look ahead problem or a line limit with mcCntlGcodeExecuteWait.
So I thought that I would just run the macro to generate and save it as gcode file, load and run it. No can do. Can't load a gcode file while running a macro (error: not now).
So I am back to button scripts that generate the gcode file, save, load and start it.
RT
-
Hi,
did you try increasing the 'look ahead lines' count to see if it makes a difference?
Craig
-
Hi,
I think there was a change in a release that came out about 6-9 months ago.
Prior to that release GcodeExecuteWait() could not be successive statements and as a consequence multiple lines of Gcode had to be concatenated together.
The current releases allow successive statements.
Craig
-
So I mentioned that I made a wizard to make G Code. I redid the wizard to do this, so it made a panel with buttons.
How do I Get it to save the G Code into a file from a Macro?
Here is a seriously stripped down section of code from the Bolt Hole Wizard. It is all I want to use for now... Just generating G Code from a button press.
function m501()
--Populate variables.
local x_center = 0
local y_center = 0
local Date = (os.date("%x %X "))
--First Line of G Code.
local gcode = string.format ("(Bolt Hole Wizard.) \n")
gcode = gcode .. string.format ("(File created on ").. tostring(Date) .. (")\n")
--Safe Line.
gcode = gcode .. ("G00 G90 G80 G40 G49 G54 \n")
--Go To Z Safe Height G53 Z0.
gcode = gcode .. "G00 G53 Z0.00 \n"
--Set Spindle Direction.
gcode = gcode .. "M3 \n"
--Set Coolant Type.
gcode = gcode .. "M8 \n"
--G Code Comment
gcode = gcode .. "(Begin Cycle.)\n"
--Go To Z Safe Height G53 Z0.
gcode = gcode .. "G00 G53 Z0.00 \n"
--Last Lines of G Code
gcode = gcode .. "G80\nM05M09\nG00 G53 Y0.00\nM30\n"
-----------------------------------------------------------
--local file = wx.wxFileDialog(panel, "Select Gcode File", "", "", "Text files (*.txt)|*.txt|Tap files (*.tap)|*.tap",
-- wx.wxFD_SAVE,wx.wxDefaultPosition,wx.wxDefaultSize, "File Dialog" );
--if(file:ShowModal() == wx.wxID_OK)then
local path = file:GetPath()
--wx.wxMessageBox(tostring(path))
io.output(io.open(path,"w"))
io.write(gcode)
io.close()
mc.mcCntlLoadGcodeFile( 0, tostring(path))
--end
--SaveSettings()
mc.mc
end--m501()
if (mc.mcInEditor() == 1) then
m501()
end
-
Does this help?
--Button script
CreateNewFile()
function CreateNewFile()
local MyNum = wx.wxGetNumberFromUser("Select or enter a feed rate", "Feed Rate:", "Enter Feed Rate", 50, 1, 1500) --Default, min, max
local MyGcode = string.format("(File created using CreateNewFile function)\nF%0.4f", MyNum)
local MyFile = wx.wxGetCwd() .. "\\GcodeFiles\\MyFile.tap" --Define the file name and location
file = io.open(MyFile, "w+") --Open the file in update mode, all previous data is erased
--file = io.open(MyFile, "a+") --Append update mode, previous data is preserved, writing is only allowed at the end of file.
file:write (MyGcode) --Write the Gcode file
file:flush (MyFile) --Save written data
file:close (MyFile) --Close file
end
-
Thanks Brett!
I got this to work! Pretty cool stuff.
Is there a way to make it open up the save dialog box? I can't figure out where/how to make it do that.
-
Saw this today, it should be pretty close I think.
local MyFile = wx.wxFileSelector("message", "C:\\Mach4Hobby\\GcodeFiles\\", "test.tap", ".tap", wx.wxFileSelectorDefaultWildcardStr, wx.wxFD_SAVE)
http://docs.wxwidgets.org/3.0.1/group__group__funcmacro__dialog.html