private void LokasyonuGetir(string lokasyon) { mngr.GlobalDataChangeKapat = true; mngr.ConnectGroupDataChangeKapat = true; string eskilokasyonadi = mngr.ConnectedGroup.Name; mngr.ConnectedGroup = mngr.ConnectedOPCServer.OPCGroups.GetOPCGroup(lokasyon); panelCihazlar.Visible = true; List <OpcItems> silinecektaglar = mngr.GetOPCItem.FindAll(p => p != null && p.OpcGroupName == eskilokasyonadi); if (silinecektaglar.Count > 0) { mngr.DeleteOPCItem(silinecektaglar, eskilokasyonadi); } mymodel.Adres[] adresler = Persistence.ReadList <Adres>(@" Select Adres.* From Cihaz Inner Join CihazAdres on CihazAdres.Cihaz_Id=Cihaz.Id and CihazAdres.Aktif=1 Inner Join Adres on CihazAdres.Adres_Id=Adres.Id and Adres.Aktif=1 Inner Join Lokasyon on Lokasyon.Id=Cihaz.Lokasyon_Id and Lokasyon.Aktif=1 Where CihazAdres.AdresTipi in ('OkunacakAdres','AlarmAdresi') and Adres.Aktif=@prm0 and Lokasyon.Adi=@prm1", new object[] { true, lokasyon }); List <string> adreslistesi = new List <string>(); listBox1.Items.Clear(); foreach (Adres adres in adresler) { adreslistesi.Add(adres.TagAdresi); listBox1.Items.Add(adres.TagAdresi); } mngr.SetOpcItems(mngr.ConnectedGroup.Name, adreslistesi); mngr.OPCAddItems(mngr.ConnectedGroup.Name); //foreach (Adres adres in adresler) //{ // List<OpcItems> items = mngr.GetOPCItem.FindAll(p => p != null && p.OPCItemName == adres.TagAdresi); // foreach (OpcItems item in items) // { // item.OPCItemValueChange += new OPCItemValueChangeEventHandler(Opcitemchange); // } //} SetDataControlsReadOnlyRecursive(this); mngr.GlobalDataChangeKapat = false; mngr.ConnectGroupDataChangeKapat = false; }
public frmCihazIzlem() { InitializeComponent(); OPCServer opcserver = Persistence.Read <OPCServer>(new Condition("Aktif", Operator.Equal, 1)); if (opcserver != null && opcserver.Id > 0) { // mymodel.Adres[] adresler = Persistence.ReadList<Adres>(@" // Select // Adres.* // From Adres // Inner Join CihazAdres on CihazAdres.Adres_Id=Adres.Id and CihazAdres.Aktif=1 // Where // CihazAdres.AdresTipi in ('OkunacakAdres','AlarmAdresi') // and Adres.Aktif=@prm0 ",new object[]{true}); lokasyons = Persistence.ReadList <Lokasyon>("Select * From Lokasyon Where Aktif=@prm0", new object[] { 1 });; treeListLokasyon.DataSource = lokasyons; Hashtable adreslist = new Hashtable(); Utility.SetGridStyle(treeListLokasyon); //foreach (Adres ent in adresler) //{ // adreslist.Add(ent.TagAdresi); // listBox1.Items.Add(ent.tagadresi); //} foreach (Lokasyon lksyn in lokasyons) { if (lksyn.Adres.Id > 0) { lksyn.Adres = Persistence.Read <Adres>(lksyn.Adres.Id); adreslist.Add(lksyn.Kodu, lksyn); listBox1.Items.Add(lksyn.Adres.TagAdresi); } } mngr = null; //mngr = new OpcManager(adreslist); mngr = new OpcManager(); mngr.OPCServerConnect(opcserver.OpcServerName, opcserver.OPCNodeName); OPCServerGroup[] groups = OPCServer.ReadGroups(opcserver.Id); if (groups != null && groups.Length > 0) { opcserver.Groups.AddRange(groups); foreach (OPCServerGroup group in opcserver.Groups) { mngr.AddOpcGroupServer(group.OPCGroupName, group.GroupUpdateRate, group.GroupActiveState, (float)group.GroupDeadBand); List <string> list = new List <string>(); Lokasyon lks = (Lokasyon)adreslist[group.OPCGroupName]; if (lks != null) { list.Add(lks.Adres.TagAdresi); mngr.SetOpcItems("lks" + lks.Kodu, list); mngr.OPCAddItems(lks.Kodu); List <OpcItems> items = mngr.GetOPCItem.FindAll(p => p != null && p.OPCItemName == lks.Adres.TagAdresi && (p.OpcGroupName == group.OPCGroupName || p.OpcGroupName == "lks" + group.OPCGroupName)); foreach (OpcItems item in items) { item.OPCItemValueChange += new OPCItemValueChangeEventHandler(Opcitemchange); } } } foreach (OPCAutomation.OPCGroupClass group in mngr.ConnectedOPCServer.OPCGroups) { group.DataChange += mngr.ConnectedGroup_DataChange; } mngr.ConnectedOPCServer.OPCGroups.GlobalDataChange += new OPCAutomation.DIOPCGroupsEvent_GlobalDataChangeEventHandler(mngr.OPCGroups_GlobalDataChange); //foreach (Lokasyon lsyn in lokasyons) //{ // List<OpcItems> items = mngr.GetOPCItem.FindAll(p => p != null && p.OPCItemName == lsyn.Adres.TagAdresi); // foreach (OpcItems item in items) // { // item.OPCItemValueChange += new OPCItemValueChangeEventHandler(Opcitemchange); // } //} //mngr.AddOpcGroupServer(opcserver.OPCGroupName, (opcserver.GroupUpdateRate), (opcserver.GroupActiveState), (float)opcserver.GroupDeadBand); //mngr.OPCAddItems(); //SetDataControlsReadOnlyRecursive(this); } } else { MessageBox.Show("Bağlanılacak OPC Server Bulunamadı.\nOPC Server Tanım Ekranında gerekli tanımlamayı yapınız"); return; } }
public frmCihazIzlem() { InitializeComponent(); OPCServer opcserver = Persistence.Read<OPCServer>(new Condition("Aktif", Operator.Equal, 1)); if (opcserver != null && opcserver.Id > 0) { // mymodel.Adres[] adresler = Persistence.ReadList<Adres>(@" // Select // Adres.* // From Adres // Inner Join CihazAdres on CihazAdres.Adres_Id=Adres.Id and CihazAdres.Aktif=1 // Where // CihazAdres.AdresTipi in ('OkunacakAdres','AlarmAdresi') // and Adres.Aktif=@prm0 ",new object[]{true}); lokasyons = Persistence.ReadList<Lokasyon>("Select * From Lokasyon Where Aktif=@prm0", new object[] { 1 }); ; treeListLokasyon.DataSource = lokasyons; Hashtable adreslist = new Hashtable(); Utility.SetGridStyle(treeListLokasyon); //foreach (Adres ent in adresler) //{ // adreslist.Add(ent.TagAdresi); // listBox1.Items.Add(ent.tagadresi); //} foreach (Lokasyon lksyn in lokasyons) { if (lksyn.Adres.Id > 0) { lksyn.Adres = Persistence.Read<Adres>(lksyn.Adres.Id); adreslist.Add(lksyn.Kodu, lksyn); listBox1.Items.Add(lksyn.Adres.TagAdresi); } } mngr = null; //mngr = new OpcManager(adreslist); mngr = new OpcManager(); mngr.OPCServerConnect(opcserver.OpcServerName,opcserver.OPCNodeName); OPCServerGroup[] groups=OPCServer.ReadGroups(opcserver.Id); if(groups!=null && groups.Length>0) { opcserver.Groups.AddRange(groups); foreach (OPCServerGroup group in opcserver.Groups) { mngr.AddOpcGroupServer(group.OPCGroupName, group.GroupUpdateRate, group.GroupActiveState, (float)group.GroupDeadBand); List<string> list = new List<string>(); Lokasyon lks = (Lokasyon)adreslist[group.OPCGroupName]; if (lks != null) { list.Add(lks.Adres.TagAdresi); mngr.SetOpcItems("lks" + lks.Kodu, list); mngr.OPCAddItems(lks.Kodu); List<OpcItems> items = mngr.GetOPCItem.FindAll(p => p != null && p.OPCItemName == lks.Adres.TagAdresi && (p.OpcGroupName == group.OPCGroupName || p.OpcGroupName == "lks" + group.OPCGroupName)); foreach (OpcItems item in items) { item.OPCItemValueChange += new OPCItemValueChangeEventHandler(Opcitemchange); } } } foreach (OPCAutomation.OPCGroupClass group in mngr.ConnectedOPCServer.OPCGroups) { group.DataChange += mngr.ConnectedGroup_DataChange; } mngr.ConnectedOPCServer.OPCGroups.GlobalDataChange += new OPCAutomation.DIOPCGroupsEvent_GlobalDataChangeEventHandler(mngr.OPCGroups_GlobalDataChange); //foreach (Lokasyon lsyn in lokasyons) //{ // List<OpcItems> items = mngr.GetOPCItem.FindAll(p => p != null && p.OPCItemName == lsyn.Adres.TagAdresi); // foreach (OpcItems item in items) // { // item.OPCItemValueChange += new OPCItemValueChangeEventHandler(Opcitemchange); // } //} //mngr.AddOpcGroupServer(opcserver.OPCGroupName, (opcserver.GroupUpdateRate), (opcserver.GroupActiveState), (float)opcserver.GroupDeadBand); //mngr.OPCAddItems(); //SetDataControlsReadOnlyRecursive(this); } } else { MessageBox.Show("Bağlanılacak OPC Server Bulunamadı.\nOPC Server Tanım Ekranında gerekli tanımlamayı yapınız"); return; } }