Need Help! G43 G49 status Led and Toggle


Results 1 to 4 of 4

Thread: G43 G49 status Led and Toggle

  1. #1
    Registered
    Join Date
    Mar 2013
    Location
    us
    Posts
    29
    Downloads
    0
    Uploads
    0

    Default 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.

    Similar Threads:


  2. #2
    Gold Member TomKerekes's Avatar
    Join Date
    May 2006
    Location
    USA
    Posts
    2958
    Downloads
    0
    Uploads
    0

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



    Attached Program and Screen Script

    Attached Files Attached Files


  3. #3
    Registered
    Join Date
    Mar 2013
    Location
    us
    Posts
    29
    Downloads
    0
    Uploads
    0

    Default

    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
    Gold Member TomKerekes's Avatar
    Join Date
    May 2006
    Location
    USA
    Posts
    2958
    Downloads
    0
    Uploads
    0

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


    Attached Files Attached Files


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
  •  


About CNCzone.com

    We are the largest and most active discussion forum for manufacturing industry. The site is 100% free to join and use, so join today!

Follow us on


Our Brands

G43 G49 status Led and Toggle

G43 G49 status Led and Toggle