Exec/Wait from inside a c program

Moderators: TomKerekes, dynomotion

User avatar
cnc_freak
Posts: 55
Joined: Fri Apr 20, 2018 5:36 am

Exec/Wait from inside a c program

Post by cnc_freak » Sat Jun 04, 2022 12:16 pm

Im currently using a Z axis handling function by a c program which is executed via programmed M3 with Exec/Wait, from KmotionCNC, and works as expected.I want to call (Exec/Wait) this program also from the main C program loop.How can i do that?
Attached is the executed program.
Attachments
Torch_zero_find.c
(8.4 KiB) Downloaded 30 times

User avatar
TomKerekes
Posts: 2529
Joined: Mon Dec 04, 2017 1:49 am

Re: Exec/Wait from inside a c program

Post by TomKerekes » Sat Jun 04, 2022 5:15 pm

Does your main forever loop also issue commands to KMotionCNC? (two Threads can not issue KMotionCNC commands at the same time)

Can your main forever loop block (wait) until the Torch_zero_find.c completes?

One method is to create a User Button (possibly hidden) to execute the Program then have the forever loop "push" the button with:
DoPCInt(PC_COMM_USER_BUTTON,3);
Regards,

Tom Kerekes
Dynomotion, Inc.

User avatar
cnc_freak
Posts: 55
Joined: Fri Apr 20, 2018 5:36 am

Re: Exec/Wait from inside a c program

Post by cnc_freak » Sun Jun 05, 2022 8:22 pm

I try it but did not work as expected. I assign a toglle button on the screen, with a var 1026 to exec/wait my c program. When i press this button then the program is executed. Also i assign to the M3 function on the tool setup screen on the KmotionCNC a variable 48. This 48 variable is checked in my endless main loop and when goes true, then a function is called, which makes the 1026 variable true, "SetBit(1026)". When a M3 is executed in a Gcode program, the only think happens is the variable 1026 goes true, but the c program assosiated, with this variable/button does not execute.
Please advice.
Regards.
Attachments
Button111.JPG
tool_setup_screen1.JPG

User avatar
TomKerekes
Posts: 2529
Joined: Mon Dec 04, 2017 1:49 am

Re: Exec/Wait from inside a c program

Post by TomKerekes » Sun Jun 05, 2022 9:14 pm

If you're using screen script then it would be simpler for KFLOP to command the Action to run the program directly. For example:

Code: Select all

#include "KMotionDef.h"

#define TMP 10 // which spare persist to use to transfer data
#include "KflopToKMotionCNCFunctions.c"

//For example "WinMsg:Keyboard;;KeyPress;120" to press F9
//For example "WinMsg:DlgName; IDC_SpindleOnCW; BM_CLICK;" to click the Spindle on cw button
//For example "Action : 5; 3; 0; 0; 0; 0; SpindleUsingJogs\CSS\OnCWJog.c" to execute/wait the seec prog in Thread 3 Var 0

void main()
{
	if (ScreenScript("Action : 5; 3; -1; 0; 0; 0; print.c"))
		printf("Screen Script Failed\n");
	else
		printf("Screen Script Success\n");
}
Regards,

Tom Kerekes
Dynomotion, Inc.

User avatar
cnc_freak
Posts: 55
Joined: Fri Apr 20, 2018 5:36 am

Re: Exec/Wait from inside a c program

Post by cnc_freak » Mon Jun 06, 2022 7:49 am

I try this "ScreenScript("WinMsg:Keyboard;;KeyPress;122");" in the endless loop, in the function that handles M3. I also assign to the user button 9 the action Exec/Wait to c function Torch_zero_find.c, with key = 122 = "F11", via Tool setup on KmotionCNC.
When a M3 is executed on a Gcode programm, the Torch_zero_find.c is executed, but the the Gcode programm does not wait until the Torch_zero_find.c finishes.
Attachments
Button110.JPG

User avatar
TomKerekes
Posts: 2529
Joined: Mon Dec 04, 2017 1:49 am

Re: Exec/Wait from inside a c program

Post by TomKerekes » Mon Jun 06, 2022 3:47 pm

You might add a wait in the M3 C Program to wait until the Torch_zero_find.c is finished. One way would be to set a Virtual Bit before the KeyPress. Then have Torch_zero_find.c clear the bit when finished. And of course have the M3 C Program wait until the bit is cleared.
Regards,

Tom Kerekes
Dynomotion, Inc.

User avatar
cnc_freak
Posts: 55
Joined: Fri Apr 20, 2018 5:36 am

Re: Exec/Wait from inside a c program

Post by cnc_freak » Mon Jun 06, 2022 4:22 pm

But this is supposed to do the "Exec/wait" action , to wait until the Torch_zero_find.c finishes.
In the main loop the M3 bit (48) is checked:
//=======================
//= M 3 =
//=======================
if(ReadBit(M3)){
DoM3();
}
And this is the start of the DoM3 function:

// -----------------------------
// - M 3 Function -
// -----------------------------
void DoM3(void){

//-------------------------------------------
//- P L A S M A O P E R A T I O N -
//-------------------------------------------
if(ReadBit(PLASMA) && !ReadBit(T_SELECT1) && !ReadBit(T_SELECT2) ){
ScreenScript("WinMsg:Keyboard;;KeyPress;122");
}

User avatar
TomKerekes
Posts: 2529
Joined: Mon Dec 04, 2017 1:49 am

Re: Exec/Wait from inside a c program

Post by TomKerekes » Mon Jun 06, 2022 10:59 pm

The Exec/wait will only wait until the button is pushed. If you want it to also wait until the probe is finished you will need to add what I said to do.
Regards,

Tom Kerekes
Dynomotion, Inc.

User avatar
cnc_freak
Posts: 55
Joined: Fri Apr 20, 2018 5:36 am

Re: Exec/Wait from inside a c program

Post by cnc_freak » Tue Jun 07, 2022 12:52 pm

I try to use a while(ReadBit(xxxx)) in order to wait the main loop, until the xxxx bit was set by Torch_Zero_find.c.
The Torch_zero_find.c starts but stops in the while (!CheckDone(ZAXIS)); function and the Gcode program continues to execute the machine moves and only when the gcode ends, only then the the Torch_zero_find.c resumes and continues from where it stop.
Is there another way to stop and wait the Torch_zero_find.c to finishes?
Regards.

User avatar
TomKerekes
Posts: 2529
Joined: Mon Dec 04, 2017 1:49 am

Re: Exec/Wait from inside a c program

Post by TomKerekes » Tue Jun 07, 2022 4:09 pm

I try to use a while(ReadBit(xxxx)) in order to wait the main loop, until the xxxx bit was set by Torch_Zero_find.c.
I don't understand what you mean by "main loop". I thought the problem was with the M3 Program not waiting. The wait should be there. Please post your programs for us to see.
Regards,

Tom Kerekes
Dynomotion, Inc.

Post Reply