Exemplo n.º 1
0
        public static List <object> OPC_Read(List <string> ItemNames)
        {
            if (ItemNames == null || ItemNames.Count == 0)
            {
                return(null);
            }
            int           count   = ItemNames.Count;
            List <object> readRtn = new List <object>();//设置返回值数组

            using (var srv = new OPCXML_DataAccess())
            {
                ReadRequestItemList ItemLists = new ReadRequestItemList();
                ItemLists.Items = new ReadRequestItem[count];
                for (int i = 0; i < count; i++)
                {
                    ItemLists.Items[i]          = new ReadRequestItem();
                    ItemLists.Items[i].ItemPath = "";
                    ItemLists.Items[i].ItemName = ItemNames[i + 1];
                }
                RequestOptions opt = new RequestOptions();

                ReplyItemList ItemValues = new ReplyItemList();;
                OPCError[]    Errors;
                opt.ReturnItemTime = true;
                srv.Read(opt, ItemLists, out ItemValues, out Errors);
                foreach (var p in ItemValues.Items)
                {
                    readRtn.Add(p.Value);
                }
            }
            return(readRtn);
        }
Exemplo n.º 2
0
        /*---------------------------------------------Reading Function Decleration ----------------------------------------------------------------*/
        public List <object> OPCRead(List <string> TagNames)
        {
/*---------------------------------------------Request Instance Decleration ----------------------------------------------------------------*/
            List <string> TagName  = new List <string>(TagNames);
            List <object> TagValue = new List <object>();
            int           RTagNos  = TagName.Count();

            ReadRequestItemList ReadItemList = new ReadRequestItemList();

            ReadItemList.Items = new ReadRequestItem[RTagNos];

            RequestOptions.ClientRequestHandle      = "";
            RequestOptions.LocaleID                 = "EN-US";
            RequestOptions.RequestDeadlineSpecified = false;
            RequestOptions.ReturnDiagnosticInfo     = false;
            RequestOptions.ReturnErrorText          = false;
            RequestOptions.ReturnItemName           = false;
            RequestOptions.ReturnItemPath           = false;
            RequestOptions.ReturnItemTime           = false;
            ReadItemList.ItemPath = "";

            for (int Looper = 0; Looper < RTagNos; Looper++)
            {
                ReadItemList.Items[Looper]          = new ReadRequestItem();
                ReadItemList.Items[Looper].ItemName = TagName[Looper];
            }



/*---------------------------------------------Reading Function Invoked ----------------------------------------------------------------*/
            myClient.Read(RequestOptions, ReadItemList, out ReplyList, out ErrorList);

/*---------------------------------------------Output to Console Invoked ----------------------------------------------------------------*/

            for (int Looper = 0; Looper < ReplyList.Items.Count(); Looper++)
            {
                if ((ReplyList.Items[Looper] != null) && (ReplyList.Items[Looper].Value != null) && (ReplyList.Items[Looper].Value.GetType().Name != "XmlNode[]"))
                {
                    TagValue.Add(ReplyList.Items[Looper].Value);

                    //Console.WriteLine(ReplyList.Items[Looper].Value.ToString());

                    //Value.ToString());
                }
                else
                {
                    TagValue.Add("<Error>");
                }
            }

            return(TagValue);
        }