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?
Assignment of bit input state variable during G-code execution
Moderators: TomKerekes, dynomotion
-
AlexTsevuh
- Posts: 5
- Joined: Mon May 26, 2025 9:40 am
- TomKerekes
- Posts: 2891
- Joined: Mon Dec 04, 2017 1:49 am
Re: Assignment of bit input state variable during G-code execution
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.
GCode to move X to 1 or 0 based on Input Bit 46
HTH
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);
}
Code: Select all
M100 (Set Var #1 based on Bit 46)
G0 X#1
M30Regards,
Tom Kerekes
Dynomotion, Inc.
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
Hello, Tom!
Thank you very much. It's all clear. I tried it but made mistakes. Now everything is clear...
Regards, Alex Tsevukh!
Thank you very much. It's all clear. I tried it but made mistakes. Now everything is clear...
Regards, Alex Tsevukh!