public void ReadPropertyValues(ref OPCTag tag) { // count 必须比 propIds.Length 少一个 int count = 4; List <int> propIds = new List <int>(); propIds.Add(0); propIds.Add(1); propIds.Add(2); propIds.Add(3); propIds.Add(4); Array PropertyIDs = propIds.ToArray(); Array PropertyValues; Array Errors; try{ mServer.GetItemProperties(tag.Name, count, ref PropertyIDs, out PropertyValues, out Errors); if ((count == 0) || (count > 10000)) { return; } for (int i = 1; i <= count; i++) { if (i == 1) { VarEnum dataType = (VarEnum)VarEnum.ToObject(typeof(VarEnum), PropertyValues.GetValue(i)); //tag.DataType = dataType; //var text = dataType.ToString(); // these methods are clunkier but run 25% faster on my machine var text2 = Enum.GetName(typeof(VarEnum), dataType); //var text3 = typeof(VarEnum).GetEnumName(dataType); tag.DataTypeText = text2; } else if (i == 2) { tag.SetValue(this, PropertyValues.GetValue(i)); } else if (i == 3) { tag.Quality = (OPCQuality)PropertyValues.GetValue(i); } else if (i == 4) { tag.ItemTimeStamp = (DateTime)PropertyValues.GetValue(i); } break; } } catch (Exception ex) { } }
public void GetItemProperties(string tagName) { int count = 4; List <int> propIds = new List <int>(); propIds.Add(0); propIds.Add(1); propIds.Add(2); propIds.Add(3); propIds.Add(4); Array PropertyIDs = propIds.ToArray(); Array PropertyValues; Array Errors; try{ mServer.GetItemProperties(tagName, count, ref PropertyIDs, out PropertyValues, out Errors); if ((count == 0) || (count > 10000)) { return; } for (int i = 1; i <= count; i++) { if (i == 1) { VarEnum foo = (VarEnum)VarEnum.ToObject(typeof(VarEnum), PropertyValues.GetValue(i)); var text = foo.ToString(); // "Clubs" // these methods are clunkier but run 25% faster on my machine var text2 = Enum.GetName(typeof(VarEnum), foo); // "Clubs" //var text3 = typeof(VarEnum).GetEnumName(foo); // "Clubs" } Console.WriteLine("in GetItemProperties, tagName is : " + tagName + ": DataType is: " + PropertyValues.GetValue(i).GetType() + ": " + PropertyIDs.GetValue(i) + ", " + PropertyValues.GetValue(i).ToString() + ", " + Errors.GetValue(i)); } } catch (Exception ex) { } }