class SampleSerialAck
{
//Setup Thread wait / Mutex
EventWaitHandle ewh = new EventWaitHandler(false, EventResetMode.AutoReset);
Frame sentFrame;
void SendAndWait()
{
sentFrame = SendNextFrame();
//Wait For Ack
ewh.WaitOne();
bool ack = false;
while(!ack)
{
Frame f = moduleFrameListener.getFrame();
if(f.isAckOf(sentFrame))
{
ack = true;
}
}
}
HandleIncomingFrame(Frame incomingFrame)
{
if(incomingFrame.isAckOf(sentFrame))
{
ewh.set();//signal the wait
}
else
{
doSomethingElse(incomingFrame);
}
}
}
class Test()
{
public static void Main()
{
FrameListener fl = new FrameListener();
SerialAckSmaple as = new SerialAckSample();
as.HandleIncomingFrame(fl.getFrame());
}
} |