API lookahead?

Make your own CNC Control Apps

Moderator: cnckeith

Post Reply
Gerral
Posts: 33
Joined: Fri Nov 22, 2024 4:25 pm
Acorn CNC Controller: Yes
Plasma CNC Controller: No
AcornSix CNC Controller: No
Allin1DC CNC Controller: No
Hickory CNC Controller: No
Oak CNC controller: No
CNC Control System Serial Number: B4107B77A373-0905248481
DC3IOB: No
CNC12: Yes
CNC11: No
CPU10 or CPU7: No

API lookahead?

Post by Gerral »

I have a program that is monitoring where things are in a job so it fires off external routines to let the workers know what's going on and what's coming up.

I initially was monitoring a variable so that when it got to 100 at the end of the job it would know it's done. Also the GCode is sending text messages to the program using #300.

What I've found is that the data that's being received in the API is well in advance up to a minute or more to where things are in the code being executed and I do have lookahead turned off.

Code: Select all

IF #50001 ;Prevent G code lookahead from parsing past here
IF #4201 || #4202 THEN GOTO 1000 ;Skip macro if graphing or searching
I resorted to just checking every two seconds to see if the job was still running as a work around.

Code: Select all

            
            double heartbeat = 0;
            bool jobRunning = true;
            string jobMessages;
            string lastjobMessage = string.Empty;
            while (jobRunning)
            {
                jobRunning = CNCPipeManager.IsRunningJob();
                heartbeat = CNCPipeManager.GetUserVariable(31550);
                jobMessages = CNCPipeManager.GetUserStringVariable(300);
                if (!string.Equals(jobMessages, lastjobMessage))
                {
                    lastjobMessage = jobMessages;
                    DisplayProgress(jobMessages);
                }
                CycleRunProgress.EditValue = heartbeat;
                await Task.Delay(2000);
            }
            
Is there a parameter or something I've not found that would cause the API to be in sync with the code as it executes?

As ever... thanks for all your ideas and help.


ASPeters
Posts: 39
Joined: Thu Feb 10, 2022 5:55 pm
Acorn CNC Controller: No
Allin1DC CNC Controller: No
Oak CNC controller: No
CNC Control System Serial Number: none
DC3IOB: No
CNC12: Yes
CNC11: No
CPU10 or CPU7: No

Re: API lookahead?

Post by ASPeters »

The calls GetCurrentLineInfo(out int line_number, out int program_number, out int stack_level) and GetCurrentStackLevelZeroLineInfo(out int line_number, out int program_number) will give you the current executed line information.

GetCurrentLineInfo
line_number - The current line number of the current job or subjob (macros, G65 calls, etc.)
program_number - mostly an internal to cnc12 variable, used to track job files
stack_level - level of call, so the main job (loaded job) would return a 0 (I think, I haven't messed with that in a while) and then a macro call inside of that job would return a 1 and G65 inside of that macro would return a 2, and so on and so forth up to 20 at which point CNC12 won't allow any more nested files.

GetCurrentStackLevelZeroLineInfo has the same variables but will always return the top level job information. So if there is a macro call going on on line 17 say, it will only return the information for line 17, not the line that the macro is at.


Gerral
Posts: 33
Joined: Fri Nov 22, 2024 4:25 pm
Acorn CNC Controller: Yes
Plasma CNC Controller: No
AcornSix CNC Controller: No
Allin1DC CNC Controller: No
Hickory CNC Controller: No
Oak CNC controller: No
CNC Control System Serial Number: B4107B77A373-0905248481
DC3IOB: No
CNC12: Yes
CNC11: No
CPU10 or CPU7: No

Re: API lookahead?

Post by Gerral »

I never noticed those.. Thanks!


Post Reply