Edit GCode variables from .Net

Moderators: TomKerekes, dynomotion

Post Reply
dominfo
Posts: 14
Joined: Tue Sep 12, 2023 8:39 am

Edit GCode variables from .Net

Post by dominfo » Thu Sep 14, 2023 3:06 pm

Hello Tom

I continue investigating on creating arcs with a different scale factor on one axis (inspired by polygon.ngc).
I could write a GCode program and simulate on KmotionCNC => it seems correct.

I will write a .Net application (C# or VB) to use with Kogna or Kflop using your .Net library.
The .Net application must be able to set GCode variables from #1 to #50 before "Interpreting" the program file which uses those variables.

I could find some source code for that with C++ ( ...KMotion\PC VC Examples\SimpleGCode\SimpleGcode.cpp)

Code: Select all

int UserMCodeCallback(int mcode)
{
	double Var1000 = Interpreter->p_setup->parameters[1000];
	CString s;
	s.Format("MCode %d Trigger GCode Var 1000 = %f",mcode,Var1000); 
	MessageBox(NULL,s,"SimpleGCode",MB_OK);
	return 0;
}
It seems that this

Code: Select all

Interpreter->p_setup->parameters
array is not exposed to the .net library.

Is this missing as I expect?
If yes, is it possible to add the possibility ro read/write those variables from .Net ?

Thanks for your support
Frederic

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

Re: Edit GCode variables from .Net

Post by TomKerekes » Sun Sep 17, 2023 12:29 am

Hi Frederic,
It seems that this

Interpreter->p_setup->parameters
array is not exposed to the .net library.

Is this missing as I expect?
If yes, is it possible to add the possibility ro read/write those variables from .Net ?
Yes it is missing. We have added it and will be available in the next release.

It is a little tricky to do what you describe because when the Interpreter starts it initializes and clears all GCode Variables (except those saved to Disk which are read from the Var file). So any Variables you set would be lost. There is an option to not initialize by setting InitializeOnExecute to false. But then you should call InitializeInterpreter, then set your variables, then begin execution

I've attached an example Python program that does this before it executes a GCode file that adds 2 Variables as a demo.

HTH
Attachments
AddVars100_101.ngc
(29 Bytes) Downloaded 132 times
GCodeWithCallbacks.py.txt
(2.83 KiB) Downloaded 134 times
Regards,

Tom Kerekes
Dynomotion, Inc.

dominfo
Posts: 14
Joined: Tue Sep 12, 2023 8:39 am

Re: Edit GCode variables from .Net

Post by dominfo » Mon Sep 18, 2023 12:01 pm

Hi Tom
Thanks for your quick support. It looks promising.
Looking forward to test the new release.

Regards
Frederic

Post Reply