Dynomotion

Group: DynoMotion Message: 15362 From: kn6za Date: 2/12/2018
Subject: homing tool changer

Hi Tom,


   Looking for a way to set the KMotioncnc tool via a c program.


  I can use the persist variable to get the current tool slot # from KMotion, but how do I update Kmotion to reflect the current tool after power cycle homing, or a tool change not initiated by KMotion?


  Writing the value to the persist variable does not update KMotioncnc to the current tool status. 


   Andrew

Group: DynoMotion Message: 15370 From: Tom Kerekes Date: 2/12/2018
Subject: Re: homing tool changer
Hi Andrew,

I believe you could issue an MDI command of "Txxx" where xxx would be the Tool ID or Slot.

Note however that MDI commands are not allowed if GCode is executing.  But I wouldn't expect that to be an issue on power up or during externally initiated tool changes.  KMotionCNC must be running.

Regards
TK

On 2/12/2018 5:21 AM, kn6za@... [DynoMotion] wrote:
 

Hi Tom,


   Looking for a way to set the KMotioncnc tool via a c program.


  I can use the persist variable to get the current tool slot # from KMotion, but how do I update Kmotion to reflect the current tool after power cycle homing, or a tool change not initiated by KMotion?


  Writing the value to the persist variable does not update KMotioncnc to the current tool status. 


   Andrew


Group: DynoMotion Message: 15371 From: kn6za Date: 2/12/2018
Subject: Re: homing tool changer
Tom,


   Thanks, I will do that. No I dont think I would ever want to initiate a tool change outside of kmotion while running a gcode.

  Besides the homing I also have some front pannel buttons for ATC forward and ATC reverse. I will use MDI as you suggest.


   Andrew
Group: DynoMotion Message: 15372 From: mmurray70@hotmail.com Date: 2/12/2018
Subject: Re: homing tool changer
Hi Tom,

My machine also displays the wrong tool until i do a tool change. I save the last tool to a file and read it again on in my init file. My current tool number is saved as persist.UserData[157].  How exactly do I send an MDI command with a variable (tool number) from my init file? Thanks.


 
Group: DynoMotion Message: 15373 From: kn6za Date: 2/12/2018
Subject: Re: homing tool changer
Good question Murray,

 I was going to do a look up table for each tool to get around that, but there may be a better way.


   Andrew 
Group: DynoMotion Message: 15374 From: Tom Kerekes Date: 2/12/2018
Subject: Re: homing tool changer
You can format and print an integer to a decimal string of characters with sprintf which works similar to printf except instead of the characters being printed they are stored into an array of characters.  See below

#include "KMotionDef.h"

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

#define LAST_TOOL_VAR 8     //  -1=Spindle empty, 0=unknown, 1-4 Tool Slot loaded into Spindle

main()
{
    char s[80];
    sprintf(s,"T%d",persist.UserData[LAST_TOOL_VAR]);
    MDI(s);  //send the T word
}


HTH
Regards
TK


On 2/12/2018 4:41 PM, kn6za@... [DynoMotion] wrote:
 

Good question Murray,


 I was going to do a look up table for each tool to get around that, but there may be a better way.


   Andrew 

Group: DynoMotion Message: 15375 From: kn6za Date: 2/12/2018
Subject: Re: homing tool changer
Thanks Tom,

   Thats slick!

   Andrew
Group: DynoMotion Message: 15376 From: mmurray70@hotmail.com Date: 2/12/2018
Subject: Re: homing tool changer
It worked Tom thanks! I got a compiling error first, but I tried deleting the top part and simply used this code once my variable has been set from the file on the hard disk. 

char s[80];
sprintf(s,"T%d",persist.UserData[157]);
MDI(s);  //send the T word

That was it, just those three lines and it sets the proper number now when i initialize. Thanks again.  

Group: DynoMotion Message: 15377 From: Tom Kerekes Date: 2/12/2018
Subject: Re: homing tool changer
Great.  Thanks for posting back.
TK

On 2/12/2018 5:49 PM, mmurray70@... [DynoMotion] wrote:
 

It worked Tom thanks! I got a compiling error first, but I tried deleting the top part and simply used this code once my variable has been set from the file on the hard disk. 


char s[80];
sprintf(s,"T%d",persist.UserData[157]);
MDI(s);  //send the T word

That was it, just those three lines and it sets the proper number now when i initialize. Thanks again.