Esempio n. 1
0
        /// <summary>
        /// Get the next message to send in the FIFO list
        /// </summary>
        /// <returns>Message to send</returns>
        private CMessageCom ReadMessage()
        {
            CMessageCom message = null;

            //Si está en modo BURST envía el siguiente que todavía no haya enviado
            if (m_frameWindow > 1)
            {
                for (var i = 0; i <= m_Messages.Count - 1; i++)
                {
                    if (m_Messages[i].TriesRemaining() == CMessageCom.MAX_MESSAGE_TRIES)
                    {
                        message = m_Messages[i];
                        message.DecrementTriesRemaining();
                        m_Messages[i] = message;

                        break;
                    }
                }

                //Si está en modo SINGLE envía el primero
            }
            else
            {
                if (m_Messages.Count > 0)
                {
                    if (m_Messages[0].TriesRemaining() == CMessageCom.MAX_MESSAGE_TRIES)
                    {
                        message = m_Messages[0];
                        message.DecrementTriesRemaining();
                        m_Messages[0] = message;
                    }
                }
            }

            return(message);
        }
Esempio n. 2
0
        /// <summary>
        /// Manage a timeout communication. Tries to resend the message. If attempts have been exhausted, raise an event
        /// </summary>
        /// <param name="state">Timer state</param>
        private void Elapsed_ConnectTimeOut(object state)
        {
            m_TimerConnectTimeOut.Change(Timeout.Infinite, Timeout.Infinite); //Stop the Timer

            if (m_Messages.Count > 0)
            {
                CMessageCom message = m_Messages[0];

                if (message.TriesRemaining() > 0)
                {
                    message.DecrementTriesRemaining();
                    m_Messages[0] = message;
                    if (message.DelayedResponse)
                    {
                        m_TimerConnectTimeOut.Change(TIME_TIMEOUT_MESSAGE_DELAYED_RESPONSE, TIME_TIMEOUT_MESSAGE_DELAYED_RESPONSE); //Start the Timer
                    }
                    else
                    {
                        m_TimerConnectTimeOut.Change(TIME_TIMEOUT_MESSAGE, TIME_TIMEOUT_MESSAGE); //Start the Timer
                    }


                    if (SendMessageEvent != null)
                    {
                        SendMessageEvent(message);
                    }
                }
                else
                {
                    m_Messages.RemoveAt(0);

                    if (ConnectionTimeOutEvent != null)
                    {
                        ConnectionTimeOutEvent(m_address, message.Command());
                    }
                }
            }
        }