Hello Guest it is May 06, 2021, 03:51:14 PM

Author Topic: File operations, reading a line of position data  (Read 2476 times)

0 Members and 1 Guest are viewing this topic.

Re: File operations, reading a line of position data
« Reply #10 on: May 09, 2017, 03:04:29 AM »
Reinhard, Thanks for the warning!  Don't worry, I am using the Api for ini and reg file access.  Only using direct file io for .txt and .csv files.

Thanks
Keith
Re: File operations, reading a line of position data
« Reply #11 on: May 09, 2017, 07:56:28 PM »
Hi,
I reused a piece of LUA code I found in one of the LUA Examples folder that ships with Mach4.
It is a file navigation panel which allow you to browse for a file and open it. Its structure and
operation owe more to wxWigets than LUA or Mach4....
Code: [Select]
inst = mc.mcGetInstance();
    -- create the wxFrame window
    mainframe = wx.wxFrame( wx.NULL,          -- no parent
                        wx.wxID_ANY,          -- whatever for wxWindow ID
                        "DummyFrame", -- frame caption
                        wx.wxDefaultPosition, -- place the frame in default position
                        wx.wxDefaultSize,     -- default frame size
                        wx.wxDEFAULT_FRAME_STYLE ); -- use default frame styles

    -- create a panel in the frame
    panel = wx.wxPanel(mainframe, wx.wxID_ANY);--We are not going to show it but we need to have this to use the File dialog

local file = wx.wxFileDialog(panel, "Select Probe 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 pathRPF = file:GetPath();
-- Edit this format statement at your own risk   
mc.mcCntlProbeFileOpen(inst, pathRPF, "X%.4AXIS_X Y%.4AXIS_Y Z%.4AXIS_Z\r\n", true);

Maybe of use.

Craig
My wife left with my best friend...
     and I miss him!
Re: File operations, reading a line of position data
« Reply #12 on: May 10, 2017, 05:22:27 AM »
Thanks Craig, I have done the same thing.  It is very helpful.   Thatt and stealing the wx.messagebox is about the exrent of my widgets prowess!
Re: File operations, reading a line of position data
« Reply #13 on: May 10, 2017, 07:28:09 AM »
Hi,
I have written a macro that reads a Gcode file line by line, makes a  correction to each line, adds the corrected line
to a new file until the end of the input file.
To get the file uses a file navigation panel as above and uses the following to open:
Code: [Select]
local file = wx.wxFileDialog(panel, "Select G code File", "", "", "All files (*.*)|*.*",
                             wx.wxFD_SAVE,wx.wxDefaultPosition,wx.wxDefaultSize, "File Dialog" );
    local pathCode;
    if(file:ShowModal() == wx.wxID_OK)then;
        pathCode = file:GetPath();
    end;

I use this line to open the file:
Code: [Select]
local hin=assert(io.open(pathCode,"r"));
And these lines to read line by line until the end of the file:
Code: [Select]
while true do;
        inline=hin:read("*L");
        if inline==nil then break end;

The body of the loop has LUA string statements necessary to effect the correction I need made.
The description of the string manipulation tools can be found at:
https://www.lua.org/pil/contents.html
While the string functions seem a bit simplistic they can be combined to offer nearly all the ANSI string functions. They could very handily
be used to extract data points from a comma separated file for instance.

In fact this link is my primary resource for LUA coding help. Doesn't have any Mach API stuff or any wxWidgets but everything else LUA.

Craig
My wife left with my best friend...
     and I miss him!
Re: File operations, reading a line of position data
« Reply #14 on: May 10, 2017, 08:29:22 AM »
Fantastic!  Thanks so much. I will study.  I am sure others will be helped as well.