Sorry for the delay, but I haven't been able to reproduce this. Is this still an issue?
But I suspect the problem is caused by having 2 Threads sending commands to KMotionCNC. The KflopToKMotionCNCFunctions.c are not currently written to be Thread safe. That is they only work reliably if only one Thread at a time is sending commands. The code assumes that KMotionCNC is idle and not processing any commands. It then assumes it can immediately tell KMotionCNC to do something. It then waits until KMotionCNC finishes and again is idle before returning and allowing other commands. So things get confused when more than one Thread is issuing commands.
It isn't clear to me what would cause the Init Thread to be issuing commands during a Tool Change. Maybe Analog noise causing Override commands?
But anyway, I think a safer approach would be to have the M6 program set a Virtual Bit to request that the Init Program perform the KMotionCNC commands. That would result in only one Thread sending commands.
Here is an M6 C Program to perform a request and wait until the request has been completed:
Code: Select all
#include "KMotionDef.h"
#define TOOL_CHANGE_REQUEST 1056
main()
{
SetBit(TOOL_CHANGE_REQUEST); // request halt and display message
while (ReadBit(TOOL_CHANGE_REQUEST)) ; // wait until finished
}
Here is some code to add to the Init Program forever loop to perform the request and acknowledge it has been performed:
Code: Select all
#define TOOL_CHANGE_REQUEST 1056
/// Handle Tool Change
if (ReadBit(TOOL_CHANGE_REQUEST))
{
DoPC(PC_COMM_HALT_NEXT_LINE);
MsgBox("!!!Change Tool!!!",MB_OK|MB_ICONEXCLAMATION);
ClearBit(TOOL_CHANGE_REQUEST);
}
HTH