Пример #1
0
        }           //	end ProcessCommandLine

        public int BuildAddressSpace()
        {
            try
            {
                DaAddressSpaceRoot root    = Application.Instance.DaAddressSpaceRoot;
                MyCreator          creator = (MyCreator)Application.Instance.Creator;

                MyDaAddressSpaceElement clockNode = (MyDaAddressSpaceElement)creator.CreateMyDaAddressSpaceElement();
                clockNode.Name        = "clock";
                clockNode.Type        = MyDaAddressSpaceElement.TYPE_NODECLOCK;
                clockNode.IoMode      = EnumIoMode.NONE;
                clockNode.HasChildren = true;
                root.AddChild(clockNode);

                MyDaAddressSpaceElement reportNode = (MyDaAddressSpaceElement)creator.CreateMyDaAddressSpaceElement();
                reportNode.Name        = "report";
                reportNode.Type        = MyDaAddressSpaceElement.TYPE_NODEREPORT;
                reportNode.IoMode      = EnumIoMode.NONE;
                reportNode.HasChildren = true;
                clockNode.AddChild(reportNode);

                m_reportTagSec              = (MyDaAddressSpaceElement)creator.CreateMyDaAddressSpaceElement();
                m_reportTagSec.Name         = "sec";
                m_reportTagSec.Type         = MyDaAddressSpaceElement.TYPE_REPORT_SEC;
                m_reportTagSec.AccessRights = EnumAccessRights.READABLE;
                m_reportTagSec.Datatype     = typeof(Int32);
                m_reportTagSec.IoMode       = EnumIoMode.REPORT_CYCLIC;
                reportNode.AddChild(m_reportTagSec);

                m_reportTagMin              = (MyDaAddressSpaceElement)creator.CreateMyDaAddressSpaceElement();
                m_reportTagMin.Name         = "min";
                m_reportTagMin.Type         = MyDaAddressSpaceElement.TYPE_REPORT_MIN;
                m_reportTagMin.AccessRights = EnumAccessRights.READABLE;
                m_reportTagMin.Datatype     = typeof(Int32);
                m_reportTagMin.IoMode       = EnumIoMode.REPORT_CYCLIC;
                reportNode.AddChild(m_reportTagMin);

                MyDaAddressSpaceElement pollNode = (MyDaAddressSpaceElement)creator.CreateMyDaAddressSpaceElement();
                pollNode.Name        = "poll";
                pollNode.Type        = MyDaAddressSpaceElement.TYPE_NODEPOLL;
                pollNode.IoMode      = EnumIoMode.NONE;
                pollNode.HasChildren = true;
                clockNode.AddChild(pollNode);

                MyDaAddressSpaceElement tag = null;

                tag              = (MyDaAddressSpaceElement)creator.CreateMyDaAddressSpaceElement();
                tag.Name         = "sec";
                tag.Type         = MyDaAddressSpaceElement.TYPE_POLL_SEC;
                tag.AccessRights = EnumAccessRights.READABLE;
                tag.Datatype     = typeof(Int32);
                tag.IoMode       = EnumIoMode.POLL;
                pollNode.AddChild(tag);

                tag              = (MyDaAddressSpaceElement)creator.CreateMyDaAddressSpaceElement();
                tag.Name         = "min";
                tag.Type         = MyDaAddressSpaceElement.TYPE_POLL_MIN;
                tag.AccessRights = EnumAccessRights.READABLE;
                tag.Datatype     = typeof(Int32);
                tag.IoMode       = EnumIoMode.POLL;
                pollNode.AddChild(tag);
            }
            catch (Exception exc)
            {
                Trace(
                    EnumTraceLevel.ERR,
                    EnumTraceGroup.USER1,
                    "OpcServer.BuildAddressSpace",
                    exc.ToString());
                return((int)EnumResultCode.E_FAIL);
            }               //	end try...catch

            return((int)EnumResultCode.S_OK);
        }           //	end BuildAddressSpace
Пример #2
0
        }           //	end constructor

        public override int HandleReadRequests()
        {
            int count = Requests.Count;

            for (int i = 0; i < count; i++)
            {
                DaRequest request = (DaRequest)Requests[i];
                if ((request != null) && (request.ProgressRequestState(EnumRequestState.CREATED, EnumRequestState.INPROGRESS) == true))
                {
                    MyDaAddressSpaceElement element = request.AddressSpaceElement as MyDaAddressSpaceElement;

                    if (element == null)
                    {
                        request.Result = EnumResultCode.E_FAIL;
                    }
                    else
                    {
                        if (request.PropertyId == 0)
                        {
                            if (element.Type == MyDaAddressSpaceElement.TYPE_POLL_SEC)
                            {
                                // get address space element value
                                DateTime now        = DateTime.Now;
                                ValueQT  cacheValue = new ValueQT(now.Second, EnumQuality.GOOD, now);
                                request.Value  = cacheValue;
                                request.Result = EnumResultCode.S_OK;
                            }
                            else if (element.Type == MyDaAddressSpaceElement.TYPE_POLL_MIN)
                            {
                                // get address space element value
                                DateTime now        = DateTime.Now;
                                ValueQT  cacheValue = new ValueQT(now.Minute, EnumQuality.GOOD, now);
                                request.Value  = cacheValue;
                                request.Result = EnumResultCode.S_OK;
                            }
                            else if (element.Type == MyDaAddressSpaceElement.TYPE_REPORT_MIN)
                            {
                                //	this is a direct device read request
                                DateTime now        = DateTime.Now;
                                ValueQT  cacheValue = new ValueQT(now.Minute, EnumQuality.GOOD, now);
                                request.Value  = cacheValue;
                                request.Result = EnumResultCode.S_OK;
                            }
                            else if (element.Type == MyDaAddressSpaceElement.TYPE_REPORT_SEC)
                            {
                                //	this is a direct device read request
                                DateTime now        = DateTime.Now;
                                ValueQT  cacheValue = new ValueQT(now.Second, EnumQuality.GOOD, now);
                                request.Value  = cacheValue;
                                request.Result = EnumResultCode.S_OK;
                            }                               //	end if ... else
                        }
                        else
                        {
                            // get property value
                            // get the value from the address space element
                            element.GetPropertyValue(request);
                        } //	end if ... else
                    }     //	end if ... else
                }         //	end if
            }             //	end for
            return(CompleteRequests());
        }                 //	end HandleReadRequests