G-codes/offsets/tools with .Net
Moderators: TomKerekes, dynomotion
Re: G-codes/offsets/tools with .Net
Thanks for that Tom.
I'm now trying to understand how all the tool IDs will work, and I'm remembering some of the 'quirks' I came across when implementing my tool table.
Current/SelectedToolSlot returns the tool table index (not the tool slot value), and I probably want to use CurrentToolSlot, not SelectedToolSlot.
When using the Tool Slot in the tool table, the interpreter transfers the toolid if less than 100, or slotid if greater than 100 to the relevant vars, so I don't actually need to worry about that bit, as it's handled by the interpreter.
Now I understand that, I think I can manage the rest of the tool functions.
I'm now trying to understand how all the tool IDs will work, and I'm remembering some of the 'quirks' I came across when implementing my tool table.
Current/SelectedToolSlot returns the tool table index (not the tool slot value), and I probably want to use CurrentToolSlot, not SelectedToolSlot.
When using the Tool Slot in the tool table, the interpreter transfers the toolid if less than 100, or slotid if greater than 100 to the relevant vars, so I don't actually need to worry about that bit, as it's handled by the interpreter.
Now I understand that, I think I can manage the rest of the tool functions.
Re: G-codes/offsets/tools with .Net
Tom, I'm not sure whether I've just discovered a bug, or if I'm doing something wrong, but I've got a problem with tool diameters.
This is my code for loading values into the tooltable-
Which results in the following in my debug output-
Now I dump the values back out using the following code -
Which results in this debug output-
The tool diameters for tools 1,2 and 3, are not what was stored into the tool table.
Any ideas?
This is my code for loading values into the tooltable-
Code: Select all
foreach(Tool t in CF.Tools)
{
ComboBox_Tools.Items.Add(new ComboBoxItem { Content = t.ToolID.ToString() + "-" + t.Comment });
KM.CoordMotion.Interpreter.SetupParams.SetTool(it, t.SlotID, t.ToolID, t.Length, t.Diameter, t.XOffset, t.YOffset);
TextBox_Debug.AppendText("\r\nTool i:" + it + " slot:" + t.SlotID + " id:" + t.ToolID + " len:" + t.Length + " dia:" + t.Diameter + " xoff:" + t.XOffset + " yoff:" + t.YOffset);
it++;
}
Code: Select all
Tool i:0 slot:1 id:1 len:2 dia:0.1 xoff:0 yoff:0
Tool i:1 slot:2 id:2 len:0 dia:2 xoff:0 yoff:0
Tool i:2 slot:3 id:3 len:2 dia:3 xoff:0 yoff:0
Tool i:3 slot:3 id:4 len:0.4 dia:4 xoff:0 yoff:0
Tool i:4 slot:3 id:5 len:0.5 dia:0 xoff:0 yoff:0
Tool i:5 slot:4 id:104 len:0 dia:0 xoff:0 yoff:0
Tool i:6 slot:4 id:105 len:0 dia:0 xoff:0 yoff:0
Code: Select all
for (int i = 0; i <= 127; i++)
{
int slot = 0, id = 0;
double len = 0, dia = 0, xoff = 0, yoff = 0;
KM.CoordMotion.Interpreter.SetupParams.GetTool(i, ref slot, ref id, ref len, ref dia, ref xoff, ref yoff);
if(slot !=0 || id !=0 || len!=0)
TextBox_Debug.AppendText("\r\nTool i:" + i + " slot:" + slot + " id:" + id + " len:" + len + " dia:" + dia + " xoff:" + xoff + " yoff:" + yoff);
}
Code: Select all
Tool i:0 slot:1 id:1 len:2 dia:1 xoff:0 yoff:0
Tool i:1 slot:2 id:2 len:0 dia:1 xoff:0 yoff:0
Tool i:2 slot:3 id:3 len:2 dia:2 xoff:0 yoff:0
Tool i:3 slot:3 id:4 len:0.4 dia:0 xoff:0 yoff:0
Tool i:4 slot:3 id:5 len:0.5 dia:0 xoff:0 yoff:0
Tool i:5 slot:4 id:104 len:0 dia:0 xoff:0 yoff:0
Tool i:6 slot:4 id:105 len:0 dia:0 xoff:0 yoff:0
Any ideas?
- TomKerekes
- Posts: 2676
- Joined: Mon Dec 04, 2017 1:49 am
Re: G-codes/offsets/tools with .Net
Oops that's a bug.
This code from KMotion_dotNet_Interop.cpp is missing setting the diameter:
This code from KMotion_dotNet_Interop.cpp is missing setting the diameter:
Code: Select all
extern "C" __declspec(dllexport) void __stdcall KM_dotnet_Interop_GCodeInterpreter_SetTool(int *handle, int index, int slot, int id,
double length, double diameter, double xoffset, double yoffset)
{
CGCodeInterpreter *GC_dll=(CGCodeInterpreter *)handle;
GC_dll->p_setup->tool_table[index].slot = slot;
GC_dll->p_setup->tool_table[index].id = id;
GC_dll->p_setup->tool_table[index].length = length;
GC_dll->p_setup->tool_table[index].xoffset = xoffset;
GC_dll->p_setup->tool_table[index].yoffset = yoffset;
}
extern "C" __declspec(dllexport) void __stdcall KM_dotnet_Interop_GCodeInterpreter_GetTool(int *handle, int index, int *slot, int *id,
double *length, double *diameter, double *xoffset, double *yoffset)
{
CGCodeInterpreter *GC_dll=(CGCodeInterpreter *)handle;
*slot = GC_dll->GetRealTimeState()->tool_table[index].slot;
*id = GC_dll->GetRealTimeState()->tool_table[index].id;
*length = GC_dll->GetRealTimeState()->tool_table[index].length;
*diameter = GC_dll->GetRealTimeState()->tool_table[index].diameter;
*xoffset = GC_dll->GetRealTimeState()->tool_table[index].xoffset;
*yoffset = GC_dll->GetRealTimeState()->tool_table[index].yoffset;
}
Regards,
Tom Kerekes
Dynomotion, Inc.
Tom Kerekes
Dynomotion, Inc.
Re: G-codes/offsets/tools with .Net
That would do it
And I've even managed to add the required code, and build a new DLL
And the new code-
And I've even managed to add the required code, and build a new DLL
Code: Select all
Tool i:0 slot:1 id:1 len:2 dia:0.1 xoff:0 yoff:0
Tool i:1 slot:2 id:2 len:0 dia:2 xoff:0 yoff:0
Tool i:2 slot:3 id:3 len:2 dia:3 xoff:0 yoff:0
Tool i:3 slot:3 id:4 len:0.4 dia:4 xoff:0 yoff:0
Tool i:4 slot:3 id:5 len:0.5 dia:0 xoff:0 yoff:0
Tool i:5 slot:4 id:104 len:0 dia:0 xoff:0 yoff:0
Tool i:6 slot:4 id:105 len:0 dia:0 xoff:0 yoff:0
Tool i:0 slot:1 id:1 len:2 dia:0.1 xoff:0 yoff:0
Tool i:1 slot:2 id:2 len:0 dia:2 xoff:0 yoff:0
Tool i:2 slot:3 id:3 len:2 dia:3 xoff:0 yoff:0
Tool i:3 slot:3 id:4 len:0.4 dia:4 xoff:0 yoff:0
Tool i:4 slot:3 id:5 len:0.5 dia:0 xoff:0 yoff:0
Tool i:5 slot:4 id:104 len:0 dia:0 xoff:0 yoff:0
Tool i:6 slot:4 id:105 len:0 dia:0 xoff:0 yoff:0
Code: Select all
extern "C" __declspec(dllexport) void __stdcall KM_dotnet_Interop_GCodeInterpreter_SetTool(int *handle, int index, int slot, int id,
double length, double diameter, double xoffset, double yoffset)
{
CGCodeInterpreter *GC_dll=(CGCodeInterpreter *)handle;
GC_dll->p_setup->tool_table[index].slot = slot;
GC_dll->p_setup->tool_table[index].id = id;
GC_dll->p_setup->tool_table[index].length = length;
GC_dll->p_setup->tool_table[index].diameter = diameter;
GC_dll->p_setup->tool_table[index].xoffset = xoffset;
GC_dll->p_setup->tool_table[index].yoffset = yoffset;
}
Re: G-codes/offsets/tools with .Net
Having got a bit bored with re-writing KMotionCNC C++ to C#, I've been working on a little idea I've wanted to implement for a while.
Automatic C code generation.
To configure channel settings, go to the Config tab, then the Channels tab, then click Config, which will open a new window.
Config tab you can set the overall axis channels (defincoordsystem code), the directory where C programs will be generated to (this uses a bit of a bodge just now due to lack of WPF functionality to select folders. Just navigate to the folder you want to use, then click open. If you happen to click on a file within the folder you'd like to use, it doesn't matter. Still just click open), and any prefix you'd like to add to the files.
KStep option works (but only adds code for enabling it, not any of the autodisable code yet). Kanalog does nothing.
Channels tab should be pretty obvious, although the gain/offset boxes aren't labelled. Limitswitch options don't do anything yet, as I need to go and read up on how to implement them.
C Output tab. Generate Init, will generate the init file from the settings in the other tabs, and display in the text box.
Generate Chan, was simply for testing, and only generates the channel code for whatever channel is selected on the previous tab, and displays it in the box.
Once you've created all the settings above, click save, then close the window.
Then if you go to the usual User Button config on the main widow, the combobox will have an option for AutoC. Select that, enter a thread number as normal, select Init from the second combobox that appear, then click Save Settings. Remember to add a button name, or it won't appear.
KMoCNC needs copied to your KMotion/Release folder.
I've attached my KMC_3040mm.xml as it has lots of configuration options already configured, and it can be saved anywhere. Select it on the Tool/Setup Files tab.
To load KMoCNC, you'll also need to create a copy of the emc.var file (in KMotion/Data ), called emc_test.var (I would add a copy, but the forum software doesn't let me upload .var files, and it's probably as quick copy, pasting, and renaming your existing file, than trying to change a file suffix!)
I'm planning on expanding this functionality as I need it, but if somebody does want to use it and is keen for something specific to be implemented, let me know and I'll consider it.
Next on my hit list is keyboard jogging, and finishing the KFlopToPC functionality.
<edited to remove old .exe>
Automatic C code generation.
To configure channel settings, go to the Config tab, then the Channels tab, then click Config, which will open a new window.
Config tab you can set the overall axis channels (defincoordsystem code), the directory where C programs will be generated to (this uses a bit of a bodge just now due to lack of WPF functionality to select folders. Just navigate to the folder you want to use, then click open. If you happen to click on a file within the folder you'd like to use, it doesn't matter. Still just click open), and any prefix you'd like to add to the files.
KStep option works (but only adds code for enabling it, not any of the autodisable code yet). Kanalog does nothing.
Channels tab should be pretty obvious, although the gain/offset boxes aren't labelled. Limitswitch options don't do anything yet, as I need to go and read up on how to implement them.
C Output tab. Generate Init, will generate the init file from the settings in the other tabs, and display in the text box.
Generate Chan, was simply for testing, and only generates the channel code for whatever channel is selected on the previous tab, and displays it in the box.
Once you've created all the settings above, click save, then close the window.
Then if you go to the usual User Button config on the main widow, the combobox will have an option for AutoC. Select that, enter a thread number as normal, select Init from the second combobox that appear, then click Save Settings. Remember to add a button name, or it won't appear.
KMoCNC needs copied to your KMotion/Release folder.
I've attached my KMC_3040mm.xml as it has lots of configuration options already configured, and it can be saved anywhere. Select it on the Tool/Setup Files tab.
To load KMoCNC, you'll also need to create a copy of the emc.var file (in KMotion/Data ), called emc_test.var (I would add a copy, but the forum software doesn't let me upload .var files, and it's probably as quick copy, pasting, and renaming your existing file, than trying to change a file suffix!)
I'm planning on expanding this functionality as I need it, but if somebody does want to use it and is keen for something specific to be implemented, let me know and I'll consider it.
Next on my hit list is keyboard jogging, and finishing the KFlopToPC functionality.
<edited to remove old .exe>
- Attachments
-
- KMC_3040mm.xml
- (34.23 KiB) Downloaded 273 times
Last edited by Moray on Sat Jan 23, 2021 10:14 pm, edited 1 time in total.
- TomKerekes
- Posts: 2676
- Joined: Mon Dec 04, 2017 1:49 am
Re: G-codes/offsets/tools with .Net
Hi Moray,
I can't get it to run. I had to add your 3DTools.dll to get it to do anything. But says Unable to open file C:\KMotion435f\KMotion\Data\emc_test.var even though I believe it is there. It displays that message several times the main screen pops up then disappears and exits.
I can't get it to run. I had to add your 3DTools.dll to get it to do anything. But says Unable to open file C:\KMotion435f\KMotion\Data\emc_test.var even though I believe it is there. It displays that message several times the main screen pops up then disappears and exits.
Regards,
Tom Kerekes
Dynomotion, Inc.
Tom Kerekes
Dynomotion, Inc.
Re: G-codes/offsets/tools with .Net
Tom, I've just realised emc_test.var is still hardcoded to C:\KMotion435f\KMotion\Data\emc_test.var
And I'd forgotten about the need for 3DTools.
I've actually just tried removing the reference to emc_test.var, and everything seems to load. Is not having a var file specified likely to cause any problems?
New exe attached.
<edited to remove old .exe>
And I'd forgotten about the need for 3DTools.
I've actually just tried removing the reference to emc_test.var, and everything seems to load. Is not having a var file specified likely to cause any problems?
New exe attached.
<edited to remove old .exe>
Last edited by Moray on Sat Jan 23, 2021 10:14 pm, edited 1 time in total.
Re: G-codes/offsets/tools with .Net
And I've just remembered, make sure you load a GCode file, otherwise certain MDI functions may cause a crash.
I re-worked my internal handling of MDIs, which introduced a problem whereby the GCode viewer can crash if there is no text lines. It's on my list of bugs to fix, along with validation of values entered into text boxes.
I re-worked my internal handling of MDIs, which introduced a problem whereby the GCode viewer can crash if there is no text lines. It's on my list of bugs to fix, along with validation of values entered into text boxes.
Re: G-codes/offsets/tools with .Net
Here's a file with the GCode viewer bug hopefully squashed.
- Attachments
-
- KMoCNC.exe
- (149 KiB) Downloaded 295 times
- TomKerekes
- Posts: 2676
- Joined: Mon Dec 04, 2017 1:49 am
Re: G-codes/offsets/tools with .Net
Hi Moray,
Cool it runs (after I figured out I needed to create a \C Programs\KMoCNC folder)
Cool it runs (after I figured out I needed to create a \C Programs\KMoCNC folder)
If no filename is specified emc.var is used.I've actually just tried removing the reference to emc_test.var, and everything seems to load. Is not having a var file specified likely to cause any problems?
Regards,
Tom Kerekes
Dynomotion, Inc.
Tom Kerekes
Dynomotion, Inc.