Page 1 of 2
C program streams
Posted: Tue Mar 12, 2024 3:15 pm
by Tarasevih
Hi Tom.
I have different C programs assigned to two buttons, but they are on the same thread because I don’t have enough threads for my machine.
Is it possible to ignore pressing another while running a program on one button?
That is, when I pressed one button, I cannot press the second until the program is executed?
Regards,
Taras.
Re: C program streams
Posted: Tue Mar 12, 2024 11:29 pm
by TomKerekes
Hi Taras,
One solution might be to configure the buttons to execute in for example Thread 3, which invokes the real program to run in Thread 4 only if Thread 4 is not active.
For Example the button executes this in Thread 3:
Code: Select all
#include "KMotionDef.h"
#define TMP 10 // which spare persist to use to transfer data
#include "KflopToKMotionCNCFunctions.c"
extern volatile int ThreadActive; // one bit for each thread
void main()
{
if (ThreadActive & (1 << 4)) return; // if Thread 4 is executing exit
if (ScreenScript("Action:4;4;0;0;0;0;BlinkKFLOP46.c"))
printf("Screen Script Failed\n");
else
printf("Screen Script Success\n");
}
Re: C program streams
Posted: Thu Mar 14, 2024 5:48 am
by Tarasevih
Hi Tom.
Thank you very much.
There are a couple more questions.
Code: Select all
if (ThreadActive & (1 << 5)) return;
So can I check if thread 5 is free?
Code: Select all
if (ScreenScript("Action:5;5;0;0;0;0;BlinkKFLOP46.c"))
So will it be possible to run the program in thread 5?
I understood you correctly ?
Regards,
Taras.
Re: C program streams
Posted: Thu Mar 14, 2024 6:00 am
by TomKerekes
Yes. But the first parameter is the Action Type. You probably want 4 for Execute without waiting. The 2nd parameter is the Thread.
Re: C program streams
Posted: Thu Mar 14, 2024 8:49 am
by Tarasevih
Hi Tom.
Thank you very much.
Code: Select all
if (ThreadActive & (1 << 5)) return;
Here we check 5 bits of the ThreadActive byte for equality 1 ?
If equal to 1 then the thread is busy.
And here we call the script with the name BlinkKFLOP46 and parameters
1)Execution parameter(1(I/O Bit) 2(Two I/O Bit) 3(DAC) 4(Execute Prog) 5(Exec Wait) ...)
2)The thread in which the script will be executed
3)?
4)?
5)?
6)?
What do the other parameters mean?
Or does it not matter?
Regards,
Taras.
Re: C program streams
Posted: Thu Mar 14, 2024 6:19 pm
by TomKerekes
Hi Taras,
The parameters have different purposes depending on the Action. They are commonly not all used.
For the Execute Action the 2nd numeric parameter is the KFLOP persist Variable for any data.
The 3nd numeric parameter is a parameter to be placed in the KFLOP persist variable. This can be useful to have a single C Program used by multiple buttons to do different things based on the value.
You can use the Screen Editor's Script Dialog to help form the screen script for an Action. Selecting different Action Types will show the related parameters.
- Action.png (7.04 KiB) Viewed 3383 times
Clicking Set will create the Script:
Action:4;1;30;123;0;0;BlinkKFLOP.c
Re: C program streams
Posted: Tue Mar 19, 2024 9:43 am
by Tarasevih
Hi Tom.
What is the variable ScreenScript ?
How to declare it?
Regards,
Taras.
Re: C program streams
Posted: Tue Mar 19, 2024 5:31 pm
by TomKerekes
Hi Taras,
Sorry I don't understand the question.
Re: C program streams
Posted: Wed Mar 20, 2024 5:52 am
by Tarasevih
Hi Tom.
I used your example as is
Code: Select all
#include "KMotionDef.h"
#define TMP 10 // which spare persist to use to transfer data
#include "KflopToKMotionCNCFunctions.c"
extern volatile int ThreadActive; // one bit for each thread
void main()
{
if (ThreadActive & (1 << 4)) return; // if Thread 4 is executing exit
if (ScreenScript("Action:4;4;0;0;0;0;BlinkKFLOP46.c"))
printf("Screen Script Failed\n");
else
printf("Screen Script Success\n");
}
But the compiler asks to assign a ScreenScript variable.
Regards,
Taras.
Re: C program streams
Posted: Wed Mar 20, 2024 5:13 pm
by TomKerekes
Hi Taras,
The function ScreenScript should be defined in KflopToKMotionCNCFunctions.h. Is it?
What Version of KMotion are you using?