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