Hi DTG,
unfortunately that little code alteration didn't work either. The macro entry and two of the internal function are:
function M41()
inst = mc.mcGetInstance();
mc.mcCntlProbeFileClose( inst );-- Close Mach4 ProbeFile
--
-- FUNCTION OpenRPF
-- arguments: inst
-- return data,numdata,pathRPF,error
--
function OpenRPF(inst);
local error=0;
local hreg=mc.mcRegGetHandle(inst,"iRegs0/ALfile");
if hreg==0 or hreg==nil then;
wx.wxMessageBox("register ALfile not found...Abort");
error=1;
return error;
end;
local pathRPF=mc.mcRegGetValueString(hreg);
if pathRPF=="" then;
wx.wxMessageBox("Filepath not found...Abort");
error=1;
return error;
end;
local handRPF=assert(io.open(pathRPF,"r"));
if handRPF==nil then;
wx.wxMessageBox("File not opened...Abort");
error=1;
return error;
end;
local data=handRPF:read("*all");
if data=="" then;
wx.wxMessageBox("No Data...Abort");
error=1;
return error;
end;
local i,j,numdata;
numdata=0;
i=1;
j=1;
while i do;
i=string.find(data,"\n",j+1);
if i==nil then break end;
j=i;
numdata=numdata+1;
end;
return data,numdata,pathRPF,error;
end;
--
-- FUNCTION OpenGcode
-- arguments: inst
-- return: code,error
--
function OpenGcode(inst)
local error=0
local code,rc= mc.mcCntlGetGcodeFileName(inst) ;
if rc ~=0 then;
wx.wxMessageBox("G code file not loaded");
error=1;
return error;
end;
local hcode=assert(io.open(code,"r"));
if hcode==0 or hcode==nil then;
wx.wxMessageBox("G code file could not be opened");
error=1;
return error;
end;
code=hcode:read("*all");
if code=="" then;
wx.wxMessageBox("G code file empty");
error=1
return error;
end;
hcode:close();
return code,error;
end;
As you can see I've tried to detect and report any errors.
This macro, M41 and its partner M40 are intended to be used with Autoleveller, a crafty software utility that generates a Gcode job to probe a circuit
board blank and then apply Z corrections to the PCB-Gcode file to ensure near perfect accuracy of cut depth when 'etching' circuit boards. I've used it
with M3 and PP and have found it so useful I can't do without it. There are quite a number of M3 users and over time more will migrate to M4 and these
macros may come in use.
As it stands if the M40 and M41 macros are called from the Gcode probe job it works well. I had hoped that if a user tried to run M41 as a stand alone
file processing job that would also be possible. I would need to add navigation windows to get the two files but not insurmountable. Given that there may in
time be a number of people using these macros I've tried to make them as flexible and yet robust as possible. In particular if a file open/read/write op
is going to fail try to detect/report and shut gracefully rather than leaving a user in suspense not knowing if it failed or why.
I may be accused of 'trying to run before I can walk'. All of the other error traps seem to work but for the one trying to get the filename/path of the loaded
probe job in the situation where the job is not loaded or accidently been closed before M41 gets a chance to run.
Must be said that I'm a complete newb with LUA. There was a couple of days there when I was SHOUTING EXTEREMLY LOUDLY the most unprintable
profanities I could imagine. I'm surprised you didn't hear it, after all you're only 14000 naut miles away and I was LOUD! Have slowly come to some understanding
of syntax. When I think back it was no worse than when I started with VB and is still better than I am with C/C++.
I was of the opinion that Artsoft had made a mistake with LUA. Having suffered the 'hump' I'm beginning to see how powerful and flexible LUA is with such a remarkably
simple instruction set and libraries. I feel that I've just scratched the surface of the flexibility that can be achieved with such a simple language. Same sort of argument
about RISC processors. The upshot is I wont be going back to VB.
I have a couple more bits to write, one extracts the mesh points from a Gcode probe job in one 'dialect' of Autoleveller, and another, a user definable/editable tolerance
applied in the search/replace applied to the numerical values. The tolerance I intend to save in iRegs0 and so can be kept between sessions. If it goes well and live tests
goes as well as my debugging should be able to post in a few more days.
Craig