Beispiel #1
0
        private void Settle()
        {
            try
            {
                string fullTagName =
                    string.Format(
                        "{0}.{1}",
                        item.KepServerName,
                        item.TagName);
                Debug.WriteLine(string.Format("TagName:[{0}]", fullTagName));

                TIRAPOPCTag tag =
                    TIRAPOPCDevices.Instance.FindOPCTagItem(fullTagName);

                if (tag != null)
                {
                    Console.WriteLine(
                        string.Format(
                            "[{0}]收到消息事件:TagName[{1}],Value[{2}],TimeStamp[{3}]",
                            item.ReceiveTime.ToString("HH:mm:ss.fff"),
                            item.TagName, item.Value, item.TimeStamp));
                    Console.WriteLine(
                        string.Format(
                            "[{0}][线程 #{1}]处理 OPC 消息:TagName:[{2}],Value:[{3}]",
                            DateTime.Now.ToString("HH:mm:ss.fff"),
                            threadID,
                            item.TagName,
                            item.Value));
                    //WriteLog.Instance.Write(
                    //    guid,
                    //    string.Format(
                    //        "[线程 #{0}]处理 OPC 消息:TagName:[{1}],Value:[{2}]",
                    //        threadID,
                    //        item.TagName,
                    //        item.Value));
                    tag.SetTagValue(item.Value, item.TimeStamp);
                }
                else
                {
                    Debug.WriteLine(
                        string.Format(
                            "KepTag:未注册[{0}]",
                            fullTagName));
                }
            }
            catch (Exception error)
            {
                string errCode = "";
                string errText = "";

                if (error.Data["ErrCode"] != null)
                {
                    errCode = error.Data["ErrCode"].ToString();
                }
                if (error.Data["ErrText"] != null)
                {
                    errText = error.Data["ErrText"].ToString();
                }
                else
                {
                    errText = error.Message;
                }

                Debug.WriteLine(
                    string.Format(
                        "[线程 #{0}]处理消息时出错:[({1}){2}]",
                        threadID,
                        errCode,
                        errText));
            }
        }
Beispiel #2
0
        private void Settle()
        {
            Debug.WriteLine(
                string.Format(
                    "[线程 #{0}]开始处理 OPC 出队消息",
                    threadID));

            TIRAPOPCTagValueItem value = TIRAPOPCTagValueItemQueue.Instance.Get();

            while (!needStopped || value != null)
            {
                if (value != null)
                {
                    Debug.WriteLine(
                        string.Format(
                            "[线程 #{0}]处理 OPC 出队消息:TagName:[{1}],Value:[{2}]",
                            threadID,
                            value.TagName,
                            value.Value));

                    try
                    {
                        string fullTagName =
                            string.Format(
                                "{0}.{1}",
                                value.KepServerName,
                                value.TagName);
                        Debug.WriteLine(string.Format("TagName:[{0}]", fullTagName));

                        TIRAPOPCTag tag =
                            TIRAPOPCDevices.Instance.FindOPCTagItem(fullTagName);

                        if (tag != null)
                        {
                            Console.WriteLine(
                                string.Format(
                                    "[线程 #{0}]处理 OPC 出队消息:TagName:[{1}],Value:[{2}]",
                                    threadID,
                                    value.TagName,
                                    value.Value));
                            tag.SetTagValue(value.Value, value.TimeStamp);
                        }
                        else
                        {
                            Debug.WriteLine(
                                string.Format(
                                    "KepTag:未注册[{0}]",
                                    fullTagName));
                        }
                    }
                    catch (Exception error)
                    {
                        string errCode = "";
                        string errText = "";

                        if (error.Data["ErrCode"] != null)
                        {
                            errCode = error.Data["ErrCode"].ToString();
                        }
                        if (error.Data["ErrText"] != null)
                        {
                            errText = error.Data["ErrText"].ToString();
                        }
                        else
                        {
                            errText = error.Message;
                        }

                        Debug.WriteLine(
                            string.Format(
                                "[线程 #{0}]处理消息时出错:[({1}){2}]",
                                threadID,
                                errCode,
                                errText));
                    }
                }

                Thread.Sleep(10);

                value = TIRAPOPCTagValueItemQueue.Instance.Get();
            }

            Debug.WriteLine("[线程 #[{0}]已停止。", threadID);
        }