Assignment of bit input state variable during G-code execution

Moderators: TomKerekes, dynomotion

Post Reply
AlexTsevuh
Posts: 5
Joined: Mon May 26, 2025 9:40 am

Assignment of bit input state variable during G-code execution

Post by AlexTsevuh » Mon May 26, 2025 9:52 am

Hello!
Is it possible to assign the state of a bit input to a variable during G-code execution. If it is possible, how to do it?

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

Re: Assignment of bit input state variable during G-code execution

Post by TomKerekes » Mon May 26, 2025 5:10 pm

Hi Alex,

Here is an example that sets GCode Variable #1 to 1 if Bit 46 is set and to 0 if not. You might set the Program to M100. Be sure to configure M100 to Execute/wait/sync.

Code: Select all

#include "KMotionDef.h"

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

int main()
{
	double d;
	
	if (ReadBit(46))  //set variable based on Bit
		d=1.0;
	else 
		d=0.0;
		
	SetUserDataDouble(TMP,d);  // put variable in persists array
	
	// Upload one Variable from perists to GCode #1 
	SetVars(1,1,TMP); 
}

GCode to move X to 1 or 0 based on Input Bit 46

Code: Select all

M100 (Set Var #1 based on Bit 46)
G0 X#1
M30
HTH
Regards,

Tom Kerekes
Dynomotion, Inc.

AlexTsevuh
Posts: 5
Joined: Mon May 26, 2025 9:40 am

Re: Assignment of bit input state variable during G-code execution

Post by AlexTsevuh » Tue May 27, 2025 9:27 am

Hello, Tom!
Thank you very much. It's all clear. I tried it but made mistakes. Now everything is clear...
Regards, Alex Tsevukh!

Post Reply