Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagec#
titleSerial Ack Sample
linenumberstrue
collapsetrue
class SampleSerialAck
{
	//Setup Thread wait / Mutex
	EventWaitHandle ewh = new EventWaitHandler(false, EventResetMode.AutoReset);
	Frame sentFrame;

	void SendAndWait()
	{
	    sentFrame = SendNextFrame();

	    //Wait For Ack
	    ewh.WaitOne();
	}

	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());
	}

}