Hi Andy,
The homing code (as yet unmodified) is HomeX_with_index_autoalign (called in Threads 1-6 as a result of buttons in KmotionCNC)
I don't understand. Are you still executing code without the changes I requested? Please attach the files you are using.
I was able to run a dummy program with the behavior in Threads 1-5 simultaneously without issue (just printing a counter value when counter % 5000 == 0) but it would break in Thread 6 if KmotionCNC was running and work otherwise.
Unless there is a WaitNextTimeSlice() in the loop then the Console would be flooded with messages. With the WaitNextTimeSlice I can run such a loop in all 7 Threads and KMotionCNC without any problem. Please post the entire program you are running.
Code:
#include "KMotionDef.h"
main()
{
int i=0;
for (;;)
{
WaitNextTimeSlice();
if (((i++) % 5000) == 0)
printf("Count 7 = %d\n", i);
}
}
What Version are you running?
Maybe something to do with your custom Screen? Select a non-custom screen to see if it is related.
If any command that communicates to KmotionCNC (I am using the DROlabel and set the Z axis based on a toolsetter input) needs to complete would it make sense to use a bit as a busy indicator across threads and have each communication check that it isn't set, set it and then clear it after the command finishes?
There is a flaw in that method. If in the period between the reading the bit and setting the bit the Thread gets pre-empted and another Thread sets the bit things still get messed up.
There is a test and set function defined in KMotionDef.h that solves this problem. You might use a persist variable for this that all Threads have easy access to.
Code:
// test a location and if zero, set
// to value. returns the original
// value. routine is atomic
int TestAndSet(int *mutex, int value);
//{
// register result = *mutex;
// if (result==0) *mutex=value;
// return result;
//}
Another approach is to have a single thread do all the communication and have other Threads request that Thread to do it. For example setting a bit.
printf's to Console should only be used for diagnostics but it is designed to be Thread safe.