Hello Guest it is March 28, 2024, 01:10:29 PM

Author Topic: Return Codes  (Read 2500 times)

0 Members and 1 Guest are viewing this topic.

Return Codes
« on: September 17, 2016, 06:52:00 AM »
Hi All,
yet another dumb question from a  Lua virgin...

Have written this code in a file dialog:

rc=mc.mcCntlLoadGcodeFile(inst, path)
            if(rc==MERROR_NOERROR)then wx.wxMessageBox("success")

When debugging the path variable is good, it correctly indentifies a Gcode file
but the return code is a number, value=0.

The API.chm reference:

rc = mc.mcCntlLoadGcodeFile(
      number mInst,
      stringFileToLoad)

and the return codes are:

MERROR_NOERROR No Error.
MERROR_INVALID_INSTANCE The mInst parameter was out of range.
MERROR_INVALID_ARG FileToLoad is NULL.
MERROR_FILE_EXCEPTION Exception while loading file.
MERROR_FILE_EMPTY No data a in file.
MERROR_FILE_SHARING Violation sharing file.
MERROR_FILE_INVALID Not a valid file type.
MERROR_FILE_BADSIZE Invalid file size (over 1.5GB).
MERROR_FILE_NOT_FOUND The file cannot be found in the file system.
MERROR_FILE_BADFORMAT The file had a line end without a new line character. The file may be incomplete.

How is it that the return code from my function call is numeric?

Is MERROR_NOERROR=0
and MERROR_INVALID_INSTANCE=1
and MERROR_INVALID_ARG=2

etc.

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'

Offline DazTheGas

*
  •  778 778
  • DazTheGas
    • View Profile
Re: Return Codes
« Reply #1 on: September 17, 2016, 09:22:55 AM »
It is always easier for a function to return an int than char, the more common codes are,

 MERROR_NOERROR            0
 MERROR_INVALID_INSTANCE      -1
 MERROR_INVALID_ARG         -2
 MERROR_INVALID_DIR         -3
 MERROR_INVALID_PROFILE      -4
 MERROR_FILE_EXCEPTION      -5
 MERROR_FILE_EMPTY         -6
 MERROR_FILE_SHARING         -7
 MERROR_FILE_INVALID         -8
 MERROR_FILE_BADSIZE         -9
 MERROR_REGEN_DONE         -10
 MERROR_NODATA            -11
 MERROR_GRID_ACTIVE         -12
 MERROR_NOT_IMPLEMENTED      -13
 MERROR_MOTOR_NOT_FOUND      -14
 MERROR_INVALID_PARAM      MERROR_INVALID_ARG
 MERROR_AXIS_NOT_FOUND      -16
 MERROR_API_INIT            -17
 MERROR_NOT_NOW            -18
 MERROR_NOT_CREATED         -19
 MERROR_SIGNAL_NOT_FOUND      -20
 MERROR_IO_NOT_FOUND         -21
 MERROR_SPIN_RANGE_NOT_FOUND -22
 MERROR_PLUGIN_NOT_FOUND      -23
 MERROR_DEVICE_NOT_FOUND     -24
 MERROR_INVALID_STATE        -25
 MERROR_AXIS_NOT_ENABLED     -26
 MERROR_REG_NOT_FOUND        -27
 MERROR_IPC_NOT_READY        -28
 MERROR_NO_ROOM_AVALABLE     -29
 MERROR_NOT_COMPILED         -30
 MERROR_NOT_ENABLED          -31
 MERROR_SCRIPT_KILLED        -32
 MERROR_FILE_NOT_FOUND       -33
 MERROR_TOOLPATH_NOT_FOUND   -39
 MERROR_TIMED_OUT            -40
 MERROR_SOFTLIMITS           -41
 MERROR_FILE_BADFORMAT       -42
 MERROR_INVALID_TYPE         -43
 MERROR_TLM_ALLOC_FAILED     -44
 MERROR_TLM_TOOL_UNMANAGED   -45
 MERROR_TLM_GROUP_EXPIRED    -46
 MERROR_TLM_GROUP_NOT_FOUND  -47
 MERROR_TLM_GROUP_ADDED      -48
 MERROR_TLM_GROUP_CHANGED    -49
 MERROR_TLM_TOOL_NOT_FOUND   -50
 MERROR_TLM_TOOL_ADDED       -51
 MERROR_TLM_TOOL_CHANGED     -52

DazTheGas
New For 2022 - Instagram: dazthegas
Re: Return Codes
« Reply #2 on: September 17, 2016, 02:48:37 PM »
Hi DTG,
thanks for that. I guess the definitions are in a C header file somewhere.

I have found, as you suggested I might, a file dialog example in the examples
folder which I can modify for my purpose.

Thanks again
Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'
Re: Return Codes
« Reply #3 on: September 18, 2016, 03:44:23 AM »
Hi,
now understand how errorcodes are passed around, thanks DTG.

I'm not out of the woods yet tho...

if(file:ShowModal() == wx.wxID_OK)then
            local path = file:GetPath()   
            local linecount
            local buf
            local rc
            local pathGenerating=1

       rc=mc.mcCntlLoadGcodeFile(inst, path)
            wx.wxMessageBox(tostring(rc))
            rc = mc.mcToolPathGenerate(inst)
           
           
            while(pathGenerating==1)do
                pathGenerating, rc = mc.mcToolPathGetGenerating(inst)
            end
            linecount, rc = mc.mcCntlGetGcodeLineCount(inst)
            buf, rc = mc.mcCntlGetGcodeFileName(inst)




            wx.wxMessageBox(buf.."    lines loaded  "..linecount)
                     
        end

The file dialog gets a good path and filename. If I debug it works ok.
If I run it as m150 at the MDI line it fails. The file dialog operates normally
but the file does not load or generate a toolpath neither the message boxes
come up to indicate progress.
One possibility I considered was that the instructions imediatley following the load
were happening so fast that it was 'breaking' the load.
You can see I've tried to put a while loop in there to allow the load/generate to
complete. It didn't work either, although that may be my poor coding than anything.

The other possibility that occurred to me is that when I start the macro the panel is
showing the MDI input and maybe the Gcode has got nowhere to go.

Might point out that this is not really necessary macro but rather an experiment
in Lua coding.

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'

Offline DazTheGas

*
  •  778 778
  • DazTheGas
    • View Profile
Re: Return Codes
« Reply #4 on: September 18, 2016, 04:57:47 AM »
I am rather confused as to what you are trying to do??

Macros are normally run from gcode so if your gcode calls this macro then it would be trying to load another gcode on top of itself, which I would say mach4 wont allow this for safety.

DazTheGas
New For 2022 - Instagram: dazthegas
Re: Return Codes
« Reply #5 on: September 18, 2016, 06:25:05 AM »
Hi DTG,
you're right, its totally pointless and your insight suggests not possible.

I imagined that an MDI call to a function that would navigate to a file and load it
would be pretty straightforward. The way you framed your question suggests that you consider
an MDI macro call to be in the nature of 'running Gcode' and such a function would fail as it
would be trying to overwrite itself.

The real purpose is to gain familiarity with Lua and wxLua. The example file dialog that I found in
the Lua Examples folder is really my focus. I need to manipulate it to navigate to a file, read line
by line, preform a mathematical correction and output line by line to a new file, suitably named.

I have done a similar thing in Mach3. My feeling is that the VB variant in Mach3 works but has holes
and Mach3 as good as it is has bugs. If I'm going to make the effort to learn a new language then
Lua is  more modern and capable, ergo the effort should be made there.

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'

Offline DazTheGas

*
  •  778 778
  • DazTheGas
    • View Profile
Re: Return Codes
« Reply #6 on: September 18, 2016, 07:14:41 AM »
To do something like this you would need to look at creating a wizard that you can load a file and then use something like "wxstc.wxStyledTextCtrl" which contains search and replace features, notepad++ is built using the same scintilla libraries, infact the mcLua editor is using the C++ wxWidgets version.

DazTheGas
New For 2022 - Instagram: dazthegas