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.