Ejemplo n.º 1
0
        public bool ViewItem(string opcid)
        {
            try
            {
                RemoveItem();                   // first remove previous item if any

                itmHandleClient = 1234;
                OPCItemDef[] aD = new OPCItemDef[1];
                aD[0] = new OPCItemDef(opcid, true, itmHandleClient, VarEnum.VT_EMPTY);
                OPCItemResult[] arrRes;
                theGrp.AddItems(aD, out arrRes);
                if (arrRes == null)
                {
                    return(false);
                }
                if (arrRes[0].Error != HRESULTS.S_OK)
                {
                    return(false);
                }

                btnItemMore.Enabled = true;
                itmHandleServer     = arrRes[0].HandleServer;
                itmAccessRights     = arrRes[0].AccessRights;
                itmTypeCode         = VT2TypeCode(arrRes[0].CanonicalDataType);

                txtItemID.Text       = opcid;
                txtItemDataType.Text = DUMMY_VARIANT.VarEnumToString(arrRes[0].CanonicalDataType);

                if ((itmAccessRights & OPCACCESSRIGHTS.OPC_READABLE) != 0)
                {
                    int cancelID;
                    theGrp.Refresh2(OPCDATASOURCE.OPC_DS_DEVICE, 7788, out cancelID);
                }
                else
                {
                    txtItemValue.Text = "no read access";
                }

                if (itmTypeCode != TypeCode.Object)                                     // Object=failed!
                {
                    // check if write is premitted
                    if ((itmAccessRights & OPCACCESSRIGHTS.OPC_WRITEABLE) != 0)
                    {
                        btnItemWrite.Enabled = true;
                    }
                }
            }
            catch (COMException)
            {
                MessageBox.Show(this, "AddItem OPC error!", "ViewItem", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return(false);
            }
            return(true);
        }
Ejemplo n.º 2
0
        public void TestVarEnumToString01()
        {
            System.Runtime.InteropServices.VarEnum varEnum = (System.Runtime.InteropServices.VarEnum)DUMMY_VARIANT.VT_ILLEGAL;
            //Test Procedure Call
            string str = DUMMY_VARIANT.VarEnumToString(varEnum);

            //Post Condition Check
            Assert.AreEqual("VT_ILLEGAL", str);

            //test
            varEnum = (System.Runtime.InteropServices.VarEnum)DUMMY_VARIANT.VT_ARRAY;
            //Test Procedure Call
            str = DUMMY_VARIANT.VarEnumToString(varEnum);
            //Post Condition Check
            Assert.AreEqual("VT_ARRAY | VT_EMPTY", str);

            //test
            varEnum = (System.Runtime.InteropServices.VarEnum)DUMMY_VARIANT.VT_BYREF;
            //Test Procedure Call
            str = DUMMY_VARIANT.VarEnumToString(varEnum);
            //Post Condition Check
            Assert.AreEqual("VT_BYREF | VT_EMPTY", str);

            //test
            varEnum = (System.Runtime.InteropServices.VarEnum)DUMMY_VARIANT.VT_VECTOR;
            //Test Procedure Call
            str = DUMMY_VARIANT.VarEnumToString(varEnum);
            //Post Condition Check
            Assert.AreEqual("VT_VECTOR | VT_EMPTY", str);

            //test
            varEnum = (System.Runtime.InteropServices.VarEnum)DUMMY_VARIANT.VT_TYPEMASK;
            //Test Procedure Call
            str = DUMMY_VARIANT.VarEnumToString(varEnum);


            //test
            varEnum = System.Runtime.InteropServices.VarEnum.VT_I4;
            //Test Procedure Call
            str = DUMMY_VARIANT.VarEnumToString(varEnum);
            //Post Condition Check
            Assert.AreEqual("VT_I4", str);
        }
Ejemplo n.º 3
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;
        }
Ejemplo n.º 4
0
 public override string ToString()
 {
     return(string.Concat(new object[] { "ID:", this.PropertyID, " '", this.Description, "' T:", DUMMY_VARIANT.VarEnumToString(this.DataType) }));
 }
Ejemplo n.º 5
0
 public override string ToString()
 {
     return("ID:" + PropertyID + " '" + Description + "' T:" + DUMMY_VARIANT.VarEnumToString(DataType));
 }