Machsupport Forum

Mach Discussion => Mach4 General Discussion => Topic started by: thespindoctor on April 01, 2017, 06:05:43 PM

Title: file i/o
Post by: thespindoctor on April 01, 2017, 06:05:43 PM
Why does this fail with error that the file cannot be created?
Not sure how to open and close files for probe data.

Quote

local rc=mc.mcCntlProbeFileOpen (inst, "KFCProbeFile.csv", "%.4Axis_X, %.4Axis_Y", TRUE)

local rc=mc.mcCntlProbeFileClose(inst)


Thanks
Title: Re: file i/o
Post by: joeaverage on April 01, 2017, 06:23:22 PM
Hi,
the file open statement requires a path in addition to the filename.

Have a look at m401 in Mach4Hobby/LuaExamples/ProbeToFile .

Craig
Title: Re: file i/o
Post by: thespindoctor on April 01, 2017, 06:43:01 PM
I don't understand the M401 code but how about this?  It still does not write to the file during the probe operation.
Quote

local path="c:\\Mach4Hobby\\Modules\\KFCProbeFile.csv"
mc.mcCntlProbeFileOpen(inst, path, "%.4Axis_X, %.4Axis_Y", TRUE)


Thanks Craig
Title: Re: file i/o
Post by: joeaverage on April 01, 2017, 09:54:08 PM
Hi,
I don't think you've got the path right yet...

This is a register I use to access a file which is subsequently used in a macro:
Quote
C:\Users\craig\Documents\eagle\fourthFOC\AEProbeData.txt

Try putting your probefile in the same directory as your Gcode, not your modules directory.

Craig

Title: Re: file i/o
Post by: thespindoctor on April 02, 2017, 11:32:10 AM
Got it?   TRUE is not valid but true is...  case sensitive!

Also  \\ double slashes is correct so this below worked great

mc.mcCntlProbeFileOpen(inst, "C:\\mach4Hobby\\GcodeFiles\\KFCProbeValues.csv","%.4AXIS_ %.4AXIS_Y\n", true)

only problem is that the G31 move will only run twice in a row then it kicks out...
Title: Re: file i/o
Post by: joeaverage on April 08, 2017, 04:29:11 PM
Hi,
in LUA a backslash, '\', is an escape character. Consequently if you wish to put a backslash in a LUA string the backslash
will have to be quoted or preceeded by an escape character ie another backslash.

Your instruction:
mc.mcCntlProbeFileOpen(inst, "C:\\mach4Hobby\\GcodeFiles\\KFCProbeValues.csv","%.4AXIS_ %.4AXIS_Y\n", true)
does require the double backslashes however if you have a path string with backslashes embedded:
mc.mcCntlProbeFileOpen(inst,path,"%.4AXIS_ %.4AXIS_Y\n", true)
will work.

Craig
Title: Re: file i/o
Post by: thespindoctor on April 08, 2017, 07:59:36 PM
Thanks!