The Host may enable the option to enforce acknowledgement of every(exceptions below) serial message transacted with the Module, specifically by issuing the /wiki/spaces/RHA/pages/2621455 command to the Module. With the Serial Acknowledgement feature enabled the Host will queue up outgoing messages, messages will be sent one-by-one and only after the previous request is responded to by a frame with a matching Frame Sequence Number or explicitly asked by the Module.
The serial acknowledgment option is disabled by default. If this option is disabled when the Host sends a command, a Status Response will only be issued upon an error; i.e., a Status Response of “Success” will not be issued by the Module upon successful completion of the command. This model has been designed to minimize serial traffic but it is important to note that the Host can overload the Module with requests if not limited.
In terms of complexity, request limiting rather than Serial Ack options is a simpler model to implement for Host developers.
If the option is enabled, both the Host and Module must acknowledge the receipt of every serial message by returning an appropriate frame with a matching Frame Sequence Number.
There are two possible Serial Acknowledgement types:
When the Serial Acknowledgement option is enabled, a general Status Response with a status of Success will be returned from the Module, OR an assigned response whose Frame Sequence Number matches that of the originating request.
The Host should acknowledge every frame coming from the Module that is not an acknowledgement frame. The acknowledgement frame that the Host should send out is a Status Response frame with a payload of 0x00 (Success), and a Frame Sequence Number that matches the Sequence Number of the frame being acknowledged.
Figure 1 illustrates a serial transaction with serial acknowledgement enabled by the Host.
Figure 1
The drawing in Figure 2 illustrates the same serial transaction but with serial acknowledgment disabled; note that these transactions omits any Status Response conveying Success.
Figure 2
The Module queues all outgoing serial messages to the Host. If the Host has enabled the Serial Acknowledgment option, the Module will retransmit any message up to (3) times until that message is acknowledged. The acknowledgement must be of the Status Response type, with a Frame Sequence Number that matches the frame being acknowledged.
The Module will not respond to the following frames with any acknowledgement, even if the Serial Acknowledgement feature is enabled:
//NOTE: not a working sample, code is for demonstration purposes only class SampleMessageHandler { //Setup Thread wait / Mutex EventWaitHandle ewh = new EventWaitHandler(false, EventResetMode.AutoReset); public delegate void IncomingMessageDelegate(Frame incomingFrame); Frame sentFrame; public void StartSending() { while(isMessageInQueue) { sentFrame = SendNextFrame(); //Wait For Ack ewh.WaitOne(); } } public void HandleIncomingFrame(Frame incomingFrame) { if(incomingFrame.isAckOf(sentFrame)) { ewh.set();//signal the wait } else { doSomethingElse(incomingFrame); } } public class SerialListener { public static StartSerialListener() { IncomingMessageDelegate imd1 = new IncomingMessageDelegate(HandleIncomingFrame); openComPort(); startReceiving(); } //Listener methods // . // . // . // . public void onIncomingMessage(Frame f) { // // // imd1(f); } } } class Test() { public static void Main() { SerialAckSmaple sas = new SerialAckSample(); sas.StartSerialListener(); sas.StartSending(); } } |