C program streams

Moderators: TomKerekes, dynomotion

Tarasevih
Posts: 101
Joined: Fri Jul 09, 2021 11:26 am

C program streams

Post by Tarasevih » Tue Mar 12, 2024 3:15 pm

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.

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

Re: C program streams

Post by TomKerekes » Tue Mar 12, 2024 11:29 pm

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");
}
Regards,

Tom Kerekes
Dynomotion, Inc.

Tarasevih
Posts: 101
Joined: Fri Jul 09, 2021 11:26 am

Re: C program streams

Post by Tarasevih » Thu Mar 14, 2024 5:48 am

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.

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

Re: C program streams

Post by TomKerekes » Thu Mar 14, 2024 6:00 am

Yes. But the first parameter is the Action Type. You probably want 4 for Execute without waiting. The 2nd parameter is the Thread.
Regards,

Tom Kerekes
Dynomotion, Inc.

Tarasevih
Posts: 101
Joined: Fri Jul 09, 2021 11:26 am

Re: C program streams

Post by Tarasevih » Thu Mar 14, 2024 8:49 am

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.

Code: Select all

Action:5;5;0;0;0;0;BlinkKFLOP46.c
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.

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

Re: C program streams

Post by TomKerekes » Thu Mar 14, 2024 6:19 pm

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
Action.png (7.04 KiB) Viewed 191 times

Clicking Set will create the Script:
Action:4;1;30;123;0;0;BlinkKFLOP.c
Regards,

Tom Kerekes
Dynomotion, Inc.

Tarasevih
Posts: 101
Joined: Fri Jul 09, 2021 11:26 am

Re: C program streams

Post by Tarasevih » Tue Mar 19, 2024 9:43 am

Hi Tom.
What is the variable ScreenScript ?
How to declare it?

Regards,
Taras.

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

Re: C program streams

Post by TomKerekes » Tue Mar 19, 2024 5:31 pm

Hi Taras,

Sorry I don't understand the question.
Regards,

Tom Kerekes
Dynomotion, Inc.

Tarasevih
Posts: 101
Joined: Fri Jul 09, 2021 11:26 am

Re: C program streams

Post by Tarasevih » Wed Mar 20, 2024 5:52 am

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.
Eror.png
Regards,
Taras.

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

Re: C program streams

Post by TomKerekes » Wed Mar 20, 2024 5:13 pm

Hi Taras,

The function ScreenScript should be defined in KflopToKMotionCNCFunctions.h. Is it?

What Version of KMotion are you using?
Regards,

Tom Kerekes
Dynomotion, Inc.

Post Reply