예제 #1
0
        private int GetInt32Value(string index_name)
        {
            object qualities;
            object timestamp;
            int    return_value = 0;

            //return 0;
            ObjOPCGroups.GetOPCGroup("ReadGroup").SyncRead((short)OPCAutomation.OPCDataSource.OPCDevice,
                                                           tagIndexReader - 1,
                                                           ref readerItemServerHandles,
                                                           out ItemServerReadValues,
                                                           out readerItemServerErrors,
                                                           out qualities,
                                                           out timestamp);
            string message = "";

            for (int i = 1; i <= Globals.GetTotalNumberOfOutputTags(); i++)
            {
                int index = Globals.OUTPUT_TAGS.FirstOrDefault(x => x.Name == index_name).Index;
                if (index == i)
                {
                    return_value = (int)ItemServerReadValues.GetValue(i);
                }
            }
            return(return_value);
        }
예제 #2
0
 public void  SyncRead(string[] sItemsID, string sGroupName, out Array Value, out object Qualities, out object TimeStamps, out Array Result)
 {
     try
     {
         int    iNumItem       = sItemsID.Length;
         int[]  iServerHandler = GetServerHandles(sItemsID);
         Array  aServerHandler = (Array)iServerHandler;
         Array  aValue;
         Array  aError;
         object oQualities;
         object oTimeStamps;
         KepGroup = KepGroups.GetOPCGroup(sGroupName);
         KepGroup.SyncRead(1, iNumItem, aServerHandler, out aValue, out aError, out oQualities, out oTimeStamps);
         //Console.WriteLine($"lKepItem:{ sItemsID[0]},{(int)aValue.GetValue(0)},{Qualities},{ TimeStamps}");
         //Console.WriteLine($"lKepItem:{(int)aValue.GetValue(0)}");
         Value      = aValue;
         Qualities  = oQualities;
         TimeStamps = oTimeStamps;
         Result     = aError;
     }
     catch
     {
         // Console.WriteLine("************** " + "SyncRead Error" + " **************");
         Value      = null;
         Qualities  = null;
         TimeStamps = null;
         Result     = null;
     }
 }
예제 #3
0
        public bool GetItems(string groupName, out string[] itemNames, out string reStr)
        {
            reStr = "";

            itemNames = null;
            try
            {
                OPCGroups myGroups = myServer.OPCGroups;
                if (myGroups == null)
                {
                    reStr = "得到项列表失败,组名:" + groupName + "不存在";
                    return(false);
                }
                OPCGroup myGroup = myGroups.GetOPCGroup(groupName);
                if (myGroup == null)
                {
                    reStr = "得到项列表失败";
                    return(false);
                }
                OPCItems items = myGroup.OPCItems;
                itemNames = new string[items.Count];
                for (int i = 0; i < itemNames.Count(); i++)
                {
                    itemNames[i] = items.Item(i + 1).ItemID;
                }
                reStr = "得到项列成功!";
                return(true);
            }
            catch (System.Exception ex)
            {
                reStr = "得到项列表失败,返回异常:" + ex.Message;
                return(false);
            }
        }