81
Mach4 General Discussion / Re: File operations, reading a line of position data
« on: May 10, 2017, 08:29:22 AM »
Fantastic! Thanks so much. I will study. I am sure others will be helped as well.
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
local ProbeYWheel={}
local inst = mc.mcGetInstance()
local CSVPath= wx.wxGetCwd() .. "\\GcodeFiles\\KFCProbeWheelFLAT.csv" --1 line .csv file with x,y,z position from probing one time
--open file and read out the data
io.input(io.open(CSVPath, "r"))
local line;
for line in io.lines(CSVPath) do
tkz=wx.wxStringTokenizer(line,",");
ProbeYWheel[1]={}--make blank table to hold the data
local token=tkz:GetNextToken();
ProbeYWheel[1] ["X_Position"]=token;
ProbeYWheel1] ["Y_Position"]=tkz:GetNextToken();
ProbeYWheel[1] ["Z_Position"]=tkz:GetNextToken();
end
io.close()
--read data
local XPos = ProbeYWheel[1].X_Position
local YPos = ProbeYWheel[1].Y_Position
local ZPos = ProbeYWheel[1].Z_Position
mc.mcCntlSetLastError(inst,string.format(" X: %.4f | Y: %.4f | Z: %.4f", XPos, YPos, ZPos))
--program to retrieve one line of probe data from a prob file
--and display the x,y,z positions in the error line
-- it does not seem to work and I am not sure why
local ProbeYWheel={}
local inst = mc.mcGetInstance()
local CSVPath= wx.wxGetCwd() .. "\\GcodeFiles\\KFCProbeWheelFLAT.csv"
--open file and read out the data
io.input(io.open(CSVPath, "r"))
local line;
for line in io.lines(CSVPath) do
tkz=wx.wxStringTokenizer(line,",");
ProbeYWheel[0]={}--make blank table to hold the data
local token=tkz:GetNextToken();
ProbeYWheel[0] ["X_Position"]=Token;
ProbeYWheel[0] ["y_Position"]=tkz:GetNextToken();
ProbeYWheel[0] ["Z_Position"]=tkz:GetNextToken();
end
io.close()
--read data
local XPos = ProbeYWheel[0].X_Position
local YPos = ProbeYWheel[0].Y_Position
local ZPos = ProbeYWheel[0].Z_Position
mc.mcCntlSetLastError(inst,string.format(" X: %.4f | Y: %.4f | Z: %.4f", XPos, YPos, ZPos))
--program to retrieve one line of probe data from a prob file
--and display the x,y,z positions in the error line
-- it does not seem to work and I am not sure why
local ProbeYWheel={}
local inst = mc.mcGetInstance()
local CSVPath= wx.wxGetCwd() .. "\\GcodeFiles\\KFCProbeWheelFLAT.csv" --1 line .csv file with x,y,z position from probing one time
--open file and read out the data
io.input(io.open(CSVPath, "r"))
local line;
for line in io.lines(CSVPath) do
tkz=wx.wxStringTokenizer(line,",");
ProbeYWheel["0"]={}--make blank table to hold the data - Should this be "0"??
local token=tkz:GetNextToken();
ProbeYWheel["0"] ["X_Position"]=Token; --i assume the first line is line 0??
ProbeYWheel["0"] ["y_Position"]=tkz:GetNextToken();
ProbeYWheel["0"] ["Z_Position"]=tkz:GetNextToken();
end
io.close()
--read data
local XPos = ProbeYWheel["0"].X_Position --should this be "0" ??
local YPos = ProbeYWheel["0"].Y_Position
local ZPos = ProbeYWheel["0"].Z_Position
mc.mcCntlSetLastError(inst,string.format(" X: %.4f | Y: %.4f | Z: %.4f", XPos, YPos, ZPos))