Hello Guest it is April 28, 2024, 11:03:52 PM

Author Topic: loadGcodeFile with api how cheack its compleate  (Read 1074 times)

0 Members and 1 Guest are viewing this topic.

loadGcodeFile with api how cheack its compleate
« on: January 12, 2022, 05:50:33 PM »
i use Api from c# to load gcode ,generate and run
i try so many options but not find any way to know when each command finish its cycle and i can go next step
itry with get the error value( that was mach support ide) but its not help ,i got "0" mean all ok but its nothing
i try by read the par value for example 4113 that give M function ,but when i make loop to cheack this value ,the cycle in  mach stop
so ...only have its option to put deley ,but this give us many deley while start up program for nothing
any help?
***is steve still on this forum? some one know?


Offline jbuehn

*
  •  101 101
    • View Profile
Re: loadGcodeFile with api how cheack its compleate
« Reply #1 on: January 12, 2022, 07:26:46 PM »
Are you trying to determine when the gcode program is finished loading? You might be able to use mcToolPathGetGenerating(mInst), which returns a bool. Once it returns false your program would be ready to run.
Re: loadGcodeFile with api how cheack its compleate
« Reply #2 on: January 12, 2022, 07:30:15 PM »
ill try thanks
Re: loadGcodeFile with api how cheack its compleate
« Reply #3 on: January 12, 2022, 07:56:43 PM »
sorry not help
same ,when its run loop on c# mach not continiue
here my sample code:
  int i= mcCntlLoadGcodeFile(0, newpath);
                        bool finish = false;
                        for (int kk= 1; kk < 30; kk++)
                        {
                            System.Threading.Thread.Sleep(1000);
                            mcToolPathGetGenerating(0, ref finish);
                            if (finish == true)
                            {
                                break;
                            }
                        }

if some one can help please
Re: loadGcodeFile with api how cheack its compleate
« Reply #4 on: January 13, 2022, 02:01:07 PM »
Not a direct answer to your problem but another approach.
Have your gcode write a value to a file, 1=loaded and at end write another value to the file, 0=done.  Have your c sharp program check the file which leaves Mach alone to do its business uninterupted.

TIA

RT
Re: loadGcodeFile with api how cheack its compleate
« Reply #5 on: January 14, 2022, 02:40:15 AM »
if you have any way to add that option that when file will compleate load or generate ,to write some thing into file ,that can be good solution
by the way i use something simmiliar not to load file but to send to c# machine status ,like change tool or finish run the gcodde ,but all this are simple M function that write value to file

Offline jbuehn

*
  •  101 101
    • View Profile
Re: loadGcodeFile with api how cheack its compleate
« Reply #6 on: January 14, 2022, 11:42:41 AM »
Maybe look at using the message script in the Mach4 GUI? There are a couple event messages related to loading gcode, one of which is mc.MSG_GCODE_LOADED. I've never tried to use that one so unsure if it fits your needs.

You could also have the PLC script checking mcToolPathGetGenerating() to see when it returns true after loading gcode, then write something to your file.
Re: loadGcodeFile with api how cheack its compleate
« Reply #7 on: January 17, 2022, 10:44:16 AM »
sorry not help
same ,when its run loop on c# mach not continiue
here my sample code:
  int i= mcCntlLoadGcodeFile(0, newpath);
                        bool finish = false;
                        for (int kk= 1; kk < 30; kk++)
                        {
                            System.Threading.Thread.Sleep(1000);
                            mcToolPathGetGenerating(0, ref finish);
                            if (finish == true)
                            {
                                break;
                            }
                        }

if some one can help please

Use the return codes to figure out what's going on. That's what they are there for. Also, make sure your path's are formatted properly, you need to escape the '\' character in a string.

Code: [Select]
string newpath = "C:\\Mach4Hobby\\GcodeFiles\\ArcTest.tap";
int rc= mcCntlLoadGcodeFile(0, newpath);


if (rc != MERROR_NOERROR) {
  // there was an error loading the file
}

If you are checking if the toolpath was generated then maybe you need to regenerate the toolpath after you load the gcode file.

Code: [Select]
MINSTANCE mInst = 0;
// Regenerate the toolpaths for controller instance 0
int rc = mcToolPathGenerate(mInst);

// then wait for the tool path to return if it's generated or not

Can't you step through the program, ie, debug it?
Re: loadGcodeFile with api how cheack its compleate
« Reply #8 on: January 17, 2022, 12:01:30 PM »
compewter_numerical
if you see the first time i wrote here you can see that first step was to get the return value
but ill tell again now its return "0" that mean no error ,but this its return before its finish the function
Re: loadGcodeFile with api how cheack its compleate
« Reply #9 on: January 17, 2022, 12:26:40 PM »
compewter_numerical
if you see the first time i wrote here you can see that first step was to get the return value
but ill tell again now its return "0" that mean no error ,but this its return before its finish the function

So, you can open the file?...opening the file shouldn't take long on a modern system...maybe a few milliseconds. Your for loop is waiting for 30 iterations at 1000ms, so 30 seconds. That's why it's taking so long... so that's your answer.

Looks, like you're programming for a plugin if it's in C#. I assume you know how to program and debug then. So, read the API and get creative. Everytime I've opened a file I just use mcCntlLoadGcodeFile, wait some milliseconds using wxMilliSleep(100), then check for errors and report/break if something went wrong. Works everytime for me.

Can't you have a while loop that checks if there was no error and then maybe read the current gcode file length using mcCntlGetGcodeLineCount and break out of the loop on those conditions? Maybe also close the current gcode file before trying to open a gcode file...not sure if that's necessary but it won't hurt anything...mcCntlCloseGCodeFile.