예제 #1
0
        public void TestLookupItemIDs01()
        {
            //testing --
            OpcServer opcServer         = new OpcServer();
            Accessor  opcServerAccessor = ReflectionAccessor.Wrap(opcServer);

            opcServerAccessor.SetField("ifServer", new OPCServerComClass());
            opcServerAccessor.SetField("ifItmProps", ((IOPCItemProperties)opcServerAccessor.GetField("ifServer")));

            int []            propertyIDs = new int[3];
            OPCPropertyItem[] propertiesData;
            //Test Procedure Call
            opcServer.LookupItemIDs("Item1", propertyIDs, out propertiesData);
            //Post Condition Check
        }
예제 #2
0
        public void ListAllProperties(ref OpcServer theSrv, string itemid)
        {
            listPropsView.Items.Clear();

            string[]          istrs = new string[5];
            OPCProperty[]     props;
            OPCPropertyData[] propdata;
            int[]             propertyIDs = new int[1];
            OPCPropertyItem[] propitm;

            try
            {
                theSrv.QueryAvailableProperties(itemid, out props);
                if (props == null)
                {
                    return;
                }

                foreach (OPCProperty p in props)
                {
                    istrs[0] = p.PropertyID.ToString();
                    istrs[1] = p.Description;
                    istrs[2] = DUMMY_VARIANT.VarEnumToString(p.DataType);
                    istrs[3] = "";
                    istrs[4] = "";

                    propertyIDs[0] = p.PropertyID;
                    theSrv.GetItemProperties(itemid, propertyIDs, out propdata);
                    if (propdata != null)
                    {
                        if (propdata[0].Error != HRESULTS.S_OK)
                        {
                            istrs[3] = "!Error 0x" + propdata[0].Error.ToString("X");
                        }
                        else
                        {
                            istrs[3] = propdata[0].Data.ToString();
                        }
                    }

                    if (p.PropertyID > 6)
                    {
                        theSrv.LookupItemIDs(itemid, propertyIDs, out propitm);
                        if (propitm != null)
                        {
                            if (propitm[0].Error != HRESULTS.S_OK)
                            {
                                istrs[4] = "!Error 0x" + propitm[0].Error.ToString("X");
                            }
                            else
                            {
                                istrs[4] = propitm[0].newItemID;
                            }
                        }
                    }

                    listPropsView.Items.Add(new ListViewItem(istrs));
                }
            }
            catch (COMException)
            {
                MessageBox.Show(this, "QueryAvailableProperties failed!", "Item Properties", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            // preselect top item in ListView
            listPropsView.Items[0].Selected = true;
        }