584,837 active members*
4,895 visitors online*
Register for free
Login
Results 1 to 8 of 8
  1. #1
    Join Date
    Mar 2013
    Posts
    33

    G43 G49 status Led and Toggle

    Hello everyone I am trying to implement a button to turn tool length compensation on and off or at the least a Led to see the status.

    Only thing I can think of is to monitor the variables for tool length offset and current fixture offset

    Is there an easier solution
    I don't have the ability to recompile from visual studio.

  2. #2
    Join Date
    May 2006
    Posts
    4043

    Re: G43 G49 status Led and Toggle

    Hi dirtdigger257,

    I can't think of an easy way to do this without adding some new functionality.

    The Tool Length Index is -1 when Length Compensation is turned off.

    Here is a C Program that maintains a Virtual Bit (actually a KFLOP LED Bit 46) based on periodically requesting the Index

    Code:
    #include "KMotionDef.h"
    
    #define TMP 10                    // which spare persist to use to transfer data
    #include "KflopToKMotionCNCFunctions.c"
    
    void ServiceToolOffsetMode(void);
    
    main()
    {
        for (;;)                    // forever loop
        {
            ServiceToolOffsetMode();
        }
    }
    
    #define STATUSBIT 46
    
    // periodically set Virtual Bit based on Tool Table Index
    void ServiceToolOffsetMode(void)
    {
        static double LastTime = 0;
        int Units, TWORD, HWORD, DWORD;
    
        if (Time_sec() < LastTime + 0.3)
            return;
    
        LastTime = Time_sec();
        GetMiscSettings(&Units, &TWORD, &HWORD, &DWORD);
        SetStateBit(STATUSBIT, HWORD != -1);
    }

    https://youtu.be/j82hDWQ9l3o

    Attached Program and Screen Script
    TK
    http://dynomotion.com

  3. #3
    Join Date
    Mar 2013
    Posts
    33
    Thanks works great

    Is it ok to have two for loops running in separate threads
    one in my init the for the MPG
    the other for servicing KmotioCNC jog rate and tool offset?

    If not it take to long to run threw the init for loop and cause problems jogging.

  4. #4
    Join Date
    May 2006
    Posts
    4043

    Re: G43 G49 status Led and Toggle

    Hi dirtdigger257,

    You could use 2 Threads but each extra Thread increases the time between Time Slices so it is better to use less Threads where possible.

    Please try the code below (and attached) that is written in a non-blocking manner so your MPG should always be serviced using a single loop.


    Code:
    #include "KMotionDef.h"
    
    #define TMP 10                    // which spare persist to use to transfer data
    #include "KflopToKMotionCNCFunctions.c"
    
    void ServiceToolOffsetMode(void);
    
    main()
    {
        for (;;)                    // forever loop
        {
            ServiceToolOffsetMode();
        }
    }
    
    #define STATUSBIT 46
    
    // periodically set Virtual Bit based on Tool Table Index
    // keeps track of state of sequence to always return immediately
    void ServiceToolOffsetMode(void)
    {
        static BOOL WaitingForResponse = FALSE;
        static double LastTime = 0;
        int HWORD;
    
        if (WaitingForResponse)        // Waiting for a response from the PC?
        {
            if (persist.UserData[PC_COMM_PERSIST] <= 0)    // Has PC Responded??
            {
                HWORD = persist.UserData[TMP + 2];    // Get Tool H Word
    
                SetStateBit(STATUSBIT, HWORD != -1);    // -1 indicates no active offset 
                LastTime = Time_sec();
                WaitingForResponse = FALSE;
            }
        }
        else
        {
            if (Time_sec() > LastTime + 0.3)    // only request periodically
            {
                DoPCIntNoWait(PC_COMM_GET_MISC_SETTINGS, TMP);    // Request settings from PC
                WaitingForResponse = TRUE;    // Remember we are waiting for a response
            }
        }
    }
    TK
    http://dynomotion.com

  5. #5
    Join Date
    Aug 2017
    Posts
    112

    Re: G43 G49 status Led and Toggle

    Quote Originally Posted by TomKerekes View Post
    Hi dirtdigger257,

    You could use 2 Threads but each extra Thread increases the time between Time Slices so it is better to use less Threads where possible.

    Please try the code below (and attached) that is written in a non-blocking manner so your MPG should always be serviced using a single loop.


    Code:
    #include "KMotionDef.h"
    
    #define TMP 10                    // which spare persist to use to transfer data
    #include "KflopToKMotionCNCFunctions.c"
    
    void ServiceToolOffsetMode(void);
    
    main()
    {
        for (;;)                    // forever loop
        {
            ServiceToolOffsetMode();
        }
    }
    
    #define STATUSBIT 46
    
    // periodically set Virtual Bit based on Tool Table Index
    // keeps track of state of sequence to always return immediately
    void ServiceToolOffsetMode(void)
    {
        static BOOL WaitingForResponse = FALSE;
        static double LastTime = 0;
        int HWORD;
    
        if (WaitingForResponse)        // Waiting for a response from the PC?
        {
            if (persist.UserData[PC_COMM_PERSIST] <= 0)    // Has PC Responded??
            {
                HWORD = persist.UserData[TMP + 2];    // Get Tool H Word
    
                SetStateBit(STATUSBIT, HWORD != -1);    // -1 indicates no active offset 
                LastTime = Time_sec();
                WaitingForResponse = FALSE;
            }
        }
        else
        {
            if (Time_sec() > LastTime + 0.3)    // only request periodically
            {
                DoPCIntNoWait(PC_COMM_GET_MISC_SETTINGS, TMP);    // Request settings from PC
                WaitingForResponse = TRUE;    // Remember we are waiting for a response
            }
        }
    }
    Hi tom,

    Thanks for your reply, i am having some problem while running the above c program,

    The issue is When i am starting KmotionCNC.exe first time then it runs fine.

    But when i am giving G49 and closing KmotionCNC.exe

    After running the KmotionCNC.exe again i am getting LED On state but , i turned it off while closing KmotionCNC.exe

    I want this whole state off or on untill unless i give G43 H1001 or G43.4 H1001 or G49.

    Closing KmotionCNC should not reset it.
    Regards

    Amit Kumar

  6. #6
    Join Date
    May 2006
    Posts
    4043

    Re: G43 G49 status Led and Toggle

    Hi Amit,

    The LED is displaying the true state of the Interpreter.

    If the Tool Setup Options: Tool Length/Offset Immediately and M6 on Tool Table Changes

    Attachment 427158

    are selected, then when KMotionCNC starts up the Tool Compensation is enabled and set to match the selected tool displayed on the screen:

    Attachment 427160




    If those options are not selected then the Settings File parameter slot_for_length_offset

    Attachment 427162

    can be used to initialize which Tool is in use or -1 for not applied.




    If no setting is included the Interpreter length offset is initialized to -1 for none.




    I want this whole state off or on untill unless i give G43 H1001 or G43.4 H1001 or G49.
    Disable the Options and set the Settings file parameter slot_for_length_offset to -1 to initialize the Interpreter with no Length Compensation in effect.
    TK
    http://dynomotion.com

  7. #7
    Join Date
    Aug 2017
    Posts
    112

    Re: G43 G49 status Led and Toggle

    Quote Originally Posted by TomKerekes View Post
    Hi Amit,

    The LED is displaying the true state of the Interpreter.

    If the Tool Setup Options: Tool Length/Offset Immediately and M6 on Tool Table Changes



    are selected, then when KMotionCNC starts up the Tool Compensation is enabled and set to match the selected tool displayed on the screen:






    If those options are not selected then the Settings File parameter slot_for_length_offset



    can be used to initialize which Tool is in use or -1 for not applied.




    If no setting is included the Interpreter length offset is initialized to -1 for none.




    Disable the Options and set the Settings file parameter slot_for_length_offset to -1 to initialize the Interpreter with no Length Compensation in effect.
    Hi tom,

    Thanks for your reply,

    I tried the above method for the tool offset led toggle, i am facing one problem that,

    When i am turning power on the kflop board its remembering its last state wheather it was turned on or off last time.

    But i don't want to remember that, i just want after every power recycle G43 G49, LED should be initially off.and i have to manually turn it ON on every power off and on Sequence.

    Waiting for your kind reply.
    Regards

    Amit Kumar

  8. #8
    Join Date
    May 2006
    Posts
    4043

    Re: G43 G49 status Led and Toggle

    Hi Amit,

    Please be more specific what you are doing.
    TK
    http://dynomotion.com

Similar Threads

  1. DIY Toggle Clamp Holddowns
    By Regnar in forum DIY CNC Router Table Machines
    Replies: 10
    Last Post: 12-20-2017, 04:20 PM
  2. Machinist Toggle Recommendation?
    By dalianharley in forum Tormach Personal CNC Mill
    Replies: 10
    Last Post: 05-17-2014, 02:19 AM
  3. toggle axis 4 dro to a-b-c
    By router101 in forum Mach Software (ArtSoft software)
    Replies: 2
    Last Post: 05-11-2010, 02:47 AM
  4. need help with HAL - toggle settings with one button
    By DrStein99 in forum LinuxCNC (formerly EMC2)
    Replies: 2
    Last Post: 10-22-2009, 02:46 PM
  5. Jog Mode Toggle
    By dynamotive in forum Mach Software (ArtSoft software)
    Replies: 0
    Last Post: 09-30-2009, 03:04 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •