private void OPCGroup_DataChanged(int TransactionID, int NumItems, ref Array ClientHandles, ref Array ItemValues, ref Array Qualities, ref Array TimeStamps) { Objects.OpcItemEventArgs e = new Objects.OpcItemEventArgs(); for (int i = 1; i <= ClientHandles.Length; i++) { if (ItemValues.GetValue(i) == null) { continue; } e.ItemHandle = (int)ClientHandles.GetValue(i); if (typeof(double) == ItemValues.GetValue(i).GetType()) { e.ItemValue = ItemValues.GetValue(i) != null ? (double)ItemValues.GetValue(i) : 0.0; } else if (typeof(bool) == ItemValues.GetValue(i).GetType()) { e.ItemValue = ItemValues.GetValue(i) != null ? (bool)ItemValues.GetValue(i) : false; e.IsFault = (bool)e.ItemValue && ((e.ItemHandle <= 18 && e.ItemHandle >= 15) || (e.ItemHandle <= 98 && e.ItemHandle >= 93)); } else if (typeof(byte) == ItemValues.GetValue(i).GetType()) { e.ItemValue = ItemValues.GetValue(i) != null ? (byte)ItemValues.GetValue(i) : new Byte(); } else if (typeof(string) == ItemValues.GetValue(i).GetType()) { e.ItemValue = ItemValues.GetValue(i) != null ? (string)ItemValues.GetValue(i) : ""; } Module1.TagList[e.ItemHandle].Value = e.ItemValue; Module1.TagList[e.ItemHandle].Timestamp = DateTime.Now; DataChanged?.Invoke(this, e); } }
private void _opcManager_DataChanged(object sender, Objects.OpcItemEventArgs e) { Tag t = Module1.TagList.Select(x => x).Where(x => x.Handle == e.ItemHandle).FirstOrDefault(); TagChanged?.Invoke(t); switch (t.FormId) { case 1: AssignValueToControl(this, "Z" + e.ItemHandle, null, e.ItemValue); AssignValueToControl(_frmConfig, "Z" + e.ItemHandle, null, e.ItemValue); break; case 2: break; case 3: break; case 4: break; case 5: break; case 6: AssignValueToControl(_frmConfig, "Z" + e.ItemHandle, null, e.ItemValue); //AssignValueToControl(_frmConfig, "Z" + e.ItemHandle, "Enabled", !(bool)e.ItemValue); //if (e.ItemValue.GetType() == typeof(bool)) //{ // AssignValueToControl(_frmConfig, "Z" + e.ItemHandle, "ImageIndex", (bool)e.ItemValue ? 1 : 0); // AssignValueToControl(_frmConfig, "Z" + e.ItemHandle, "Enabled", !(bool)e.ItemValue); //} //else //{ // AssignValueToControl(_frmConfig, "Z" + e.ItemHandle, null, e.ItemValue); //} break; case 7: AssignValueToControl(_frmEthernet, "B" + e.ItemHandle, "BackColor", (bool)e.ItemValue ? Color.Green : Color.Red); break; case 8: break; case 9: break; case 10: break; case 12: //11 switch (e.ItemHandle) { case 34: AssignValueToControl(_frmHome, "B33", "ImageIndex", 2); break; case 1: AssignValueToControl(_frmHome, "B33", "ImageIndex", 0); break; case 119: AssignValueToControl(_frmHome, "B117", "ImageIndex", 2); break; case 126: AssignValueToControl(_frmHome, "B117", "ImageIndex", 0); break; default: break; } break; default: break; } if (e.IsFault) { button16.BackColor = Color.Red; string tag = (string)Module1.TagList[e.ItemHandle].Name; DateTime date = DateTime.Now; DbManager.Insert("faults", "0,'" + tag + "','" + date.ToString("yyyy-MM-dd hh:mm") + "',1,(SELECT h FROM (SELECT corr as h FROM tags WHERE handle=" + e.ItemHandle + ") AS G)"); } }