Hi George,
Sorry for the delay but we were having fun at the ATX show
I actually wasn't able to duplicate the problem on my system (I have a very fast PC might be why), but I think I see a bug in your C code:
while(ReadBit(48))
ClearBit(54);
I think your intent was to clear bit 54 after bit 48 is cleared by mach3. But you are missing a semicolon. So instead the ClearBit(54) is included in the while loop and immediately cleared.
But regardless I think a better approach is to use a "two wire handshake" for guaranteed synchronization rather than using delays and pulses that you expect to be always long enough to be observed. The idea works like this: Imagine person A wants to signal person B to do something and wants to know when they have completed. Each person has one flag and they are both down initially. To signal the steps are:
#1 - A puts up his flag and waits to see B has raised his flag
#2 - when B sees A put his flag up, he performs a task and puts his flag up
#3 - when A sees B has put his flag up he drops his flag and waits until B puts his flag down
#4 - when B sees A put his flag down, he drops his flag
The nice thing about this approach is that no delays or pulse times need to be defined and things progress as fast as the communication allows.
Here is some code I tried on the KFLOP side:
Code:
for(;;)
{
if (ReadBit(48)) // signal from mach3 ?
{
Delay_sec(5); // simulate performing a task
SetBit(54); // flag we are done
while(ReadBit(48)); // wait for mach3 to acknowledge by removing signal
ClearBit(54);
}
}
Here is the mach3 side code:
Code:
ActivateSignal(Output5) 'Send signal to input bit 48 on
'Kflop to start THC
While Not IsActive(Input1) 'Wait for THC to complete.Sent from Kflop,Bit 54
Wend
DeactivateSignal(Output5)
While IsActive(Input1) 'Wait for THC to complete.Sent from Kflop,Bit 54 to be removed
Wend
HTH
Regards