G-codes/offsets/tools with .Net

Moderators: TomKerekes, dynomotion

Moray
Posts: 221
Joined: Thu Apr 26, 2018 10:16 pm

Re: G-codes/offsets/tools with .Net

Post by Moray » Thu Jan 07, 2021 9:44 pm

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. :)

Moray
Posts: 221
Joined: Thu Apr 26, 2018 10:16 pm

Re: G-codes/offsets/tools with .Net

Post by Moray » Tue Jan 12, 2021 7:56 pm

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-

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++;
            }
Which results in the following in my debug output-

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
Now I dump the values back out using the following code -

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);

            }
Which results in this debug output-

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
The tool diameters for tools 1,2 and 3, are not what was stored into the tool table.
Any ideas?

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

Re: G-codes/offsets/tools with .Net

Post by TomKerekes » Tue Jan 12, 2021 8:12 pm

Oops that's a bug.

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.

Moray
Posts: 221
Joined: Thu Apr 26, 2018 10:16 pm

Re: G-codes/offsets/tools with .Net

Post by Moray » Tue Jan 12, 2021 9:42 pm

That would do it 8-)

And I've even managed to add the required code, and build a new DLL :D

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
And the new code-

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;
} 

Post Reply