Page 1 of 1

Tracking production information data and time

Posted: Fri Apr 03, 2026 9:57 am
by devotip
I need to record some data during the gcode execution to collect information about when the gcode program was run and some accessory information.
What is a reasonable way to achieve the following: retrieve the gcode filename or a string inside the gcode text where is defined a production batch code make it available to a C code context in some different places along the gcode and have the C code write into a file the production code and current time
My best guess is to have something like the following but I miss how to forward the raw string to the M119 handler to then write to a file date timeand string

Code: Select all

( C:\projects\tewi\PerfoGen\PORTELLA GIAN.cnc )
M119 'partnumber-batchcode-start'
some gcode
M119 'partnumber-batchcode-cooling'
M0
M119 'partnumber-batchcode-rework'
some gcode
M119 'partnumber-batchcode-end'
M30

Re: Tracking production information data and time

Posted: Fri Apr 03, 2026 6:25 pm
by TomKerekes
Hi devotip,

There aren't currently methods for doing this.

Here is a patch for Version 5.4.1 to add a command to read the current line of GCode and another to read the current date/Time from the PC.

KMotionCNC.exe copy to KMotion\Release folder
PC-DSP.h copy to DSP_KFLOP or DSP_Kogna depending on which you use or both
KflopToKMotionCNCFunctions.c copy to C Programs folder or wherever your C Program is.
KFLOPtoKMotionCNCGetGcodeLine.c example to read current line of GCode
KFLOPtoKMotionCNCGetDateTime.c example to read Date Time from PC

Code: Select all

#include "KMotionDef.h"

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

//Reads current line of GCode

int main()
{
	char s[250];
	
	GetGCodeLine(1000, s);  // get the line of GCode
	printf("%s\n",s); // rint it
}
prints : M119 (Hello world) for that line of GCode.


Code: Select all

#include "KMotionDef.h"

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

//Reads current date/time

int main()
{
	char s[250];
	
	GetDateTime(1000, s);  // get the date time string
	printf("%s\n",s); // print it
}
prints: Fri, Apr 03, 2026, 11:09:28

Please let us know if you find any issues.