コード例 #1
0
        /// <summary>
        /// Send a Hart-IP Request
        /// </summary>
        /// <param name="Request"><see cref="HartIPRequest"></see></param>
        /// <param name="MsgRsp"><see cref="MsgResponse"></see></param>
        /// <para>see the HartIPRequest.Command for HART specification references.</para>
        /// <returns>bool if it is success</returns>
        public bool SendHartRequest(HartIPRequest Request, MsgResponse MsgRsp)
        {
            bool bSuccess = false;

            if (Request == null)
            {
                throw new ArgumentException("Invalid argument in SendHartRequest.");
            }

            lock (SyncRoot)
            {
                m_Error = String.Empty;
                try
                {
                    if (m_RspMsgReader == null)
                    {
                        // Create a thread that is constantly reading on the input stream
                        m_bStopped          = false;
                        m_RspMsgReader      = new Thread(new ThreadStart(this.ReceiveMsg));
                        m_RspMsgReader.Name = "HartIPConnection";
                        m_RspMsgReader.Start();
                    }

                    // add the request object into the m_Requests list
                    MsgRequest MsgReq = new MsgRequest(Request.TransactionId, MsgRsp);
                    m_Requests.Add(MsgReq);

                    // send the request
                    bSuccess = SendRequest(Request);
                    LogMsg.Instance.Log(Request.ToString());
                }
                catch (SocketException se)
                {
                    m_Error = String.Format("SendHartRequest SocketException: ErrorCode:{0}. {1}",
                                            se.ErrorCode, se.Message);
                    LogMsg.Instance.Log("Error, " + m_Error, true);
                }
                catch (Exception e)
                {
                    m_Error = String.Format("SendHartRequest Exception: {0}", e.Message);
                    LogMsg.Instance.Log("Error, " + m_Error, true);
                }

                if (!bSuccess)
                {
                    LogMsg.Instance.Log("Error, Failed sending Request: " + Request.ToString(), true);
                    DequeueRequest(Request.TransactionId);
                }
            }

            return(bSuccess);
        }
コード例 #2
0
        /// <summary>
        /// Send a Hart-IP Request
        /// </summary>
        /// <param name="Request"><see cref="HartIPRequest"></see></param>
        /// <para>see the HartIPRequest.Command for HART specification references.</para>
        /// <returns>bool true if the request is sent success.</returns>
        private bool SendHartIPRequest(HartIPRequest Request)
        {
            bool bSuccess = false;

            lock (SyncRoot)
            {
                m_Error = String.Empty;
                try
                {
                    bSuccess = SendRequest(Request);
                    LogMsg.Instance.Log(Request.ToString());
                }
                catch (SocketException se)
                {
                    m_Error = String.Format("SendHartIPRequest SocketException: ErrorCode:{0}. {1}",
                                            se.ErrorCode, se.Message);
                    LogMsg.Instance.Log("Error, " + m_Error, true);
                }
                catch (Exception e)
                {
                    m_Error = String.Format("SendHartIPRequest Exception: {0}", e.Message);
                    LogMsg.Instance.Log("Error, " + m_Error, true);
                }
            }

            return(bSuccess);
        }