/// <summary>
 /// Send KeepAlive message
 /// </summary>
 public void KeepAlive()
 {
     lock (SyncRoot)
     {
         if (m_HartIPConn.IsConnected)
         {
             HARTMsgResult Result = new HARTMsgResult();
             try
             {
                 m_HartIPConn.SendKeepAlive(Result);
             }
             catch (Exception e)
             {
                 Result.AddMessage(e.Message, false, true);
                 m_Error = "KeepAlive: " + e.Message;
                 Logger.Log("Error, " + m_Error, true);
             }
         }
     }
 }
        /// <summary>
        /// Create a HART Close Session Request, send it to the Gateway,
        /// and close the socket.
        /// </summary>
        /// <param name="Result"><see cref="HARTMsgResult">HARTMsgResult</see></param>
        public void CloseSession(HARTMsgResult Result)
        {
            HartIPRequest Req = null;

            do
            {
                Req = HartIPRequest.CloseSession(TransactionId);
                MsgResponse MsgRsp = new MsgResponse(HARTIPConnect.USE_SOCKET_TIMEOUT_DEFAULT);
                if (SendHartRequest(Req, MsgRsp))
                {
                    try
                    {   // wait for the object return or timeout
                        if (MsgRsp.GetResponse() == false)
                        {
                            Result.AddMessage("Close Session failed: No response was received.", false, true);
                            break;
                        }
                        if (!MsgRsp.ResponseMsg.IsValidResponse)
                        {
                            Result.AddMessage("Close Session failed: Received an invalid response msg type.", false, true);
                            break;
                        }
                        LogMsg.Instance.Log(MsgRsp.ResponseMsg.ToString());
                    }
                    catch
                    {
                        Result.AddMessage("Close Session failed.", false, true);
                        break;
                    }
                }
                else
                {
                    Result.AddMessage("Close Session failed.", false, true);
                    break;
                }
            } while (false); /* ONCE */

            Close();
            Result.AddMessage("Closed the HPort socket.", false, true);
        }
        /// <summary>
        /// Disconnect - end HART-IP session
        /// </summary>
        public void Disconnect()
        {
            HARTMsgResult Result = new HARTMsgResult();

            m_HartIPConn.CloseSession(Result);
        }