Page 1 of 1

Assignment of bit input state variable during G-code execution

Posted: Mon May 26, 2025 9:52 am
by AlexTsevuh
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?

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

Posted: Mon May 26, 2025 5:10 pm
by TomKerekes
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

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

Posted: Tue May 27, 2025 9:27 am
by AlexTsevuh
Hello, Tom!
Thank you very much. It's all clear. I tried it but made mistakes. Now everything is clear...
Regards, Alex Tsevukh!