public frmOpcServer() { InitializeComponent(); mngr = new OpcManager(); server=Persistence.Read<OPCServer>(new Condition[]{new Condition("Aktif",Operator.Equal,true)}); if (server != null) { OPCServerGroup[] groups = OPCServer.ReadGroups(server.Id); server.Groups.AddRange(groups); dataGridView1.DataSource = server.Groups; textBoxServerIsmi.Text = server.OpcServerName; textBoxOPCNodeIsmi.Text = server.OPCNodeName; } else server = new OPCServer(); dataGridView1.SetGridStyle( @"<Style> <Column Name='Id' HeaderText='Id' Width='100' DisplayIndex='0' Visible='false' /> <Column Name='OPCGroupName' HeaderText='OPCGroupName' Width='100' DisplayIndex='1' Visible='true' /> <Column Name='GroupUpdateRate' HeaderText='GroupUpdateRate' Width='100' DisplayIndex='2' Visible='true' /> <Column Name='GroupDeadBand' HeaderText='GroupDeadBand' Width='100' DisplayIndex='3' Visible='true' /> <Column Name='GroupActiveState' HeaderText='GroupActiveState' Width='100' DisplayIndex='4' Visible='true' Type ='CheckBox' /> </Style>"); }
void frmCihazTanim_ButtonClick3(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e) { object adres = gridViewAlarmAdresler.GetRowCellValue(gridViewAlarmAdresler.FocusedRowHandle, "TagAdresi"); if (adres != null && adres != string.Empty) { //OpcManager mngr; //OPCServer opcserver = Persistence.Read<OPCServer>(new Condition("Aktif", Operator.Equal, 1)); //if (opcserver != null && opcserver.Id > 0) //{ List <string> adreslist = new List <string>(); adreslist.Add(adres.ToString()); mngr = new OpcManager(opcserver.Groups[0].OPCGroupName, adreslist); mngr.OPCServerConnect(opcserver.OpcServerName, opcserver.OPCNodeName); //mngr.AddOpcGroupServer(opcserver.OPCGroupName, (opcserver.GroupUpdateRate), (opcserver.GroupActiveState), (float)opcserver.GroupDeadBand); mngr.AddOpcGroupServer(opcserver.Groups[0].OPCGroupName, opcserver.Groups[0].GroupUpdateRate, opcserver.Groups[0].GroupActiveState, (float)opcserver.Groups[0].GroupDeadBand); mngr.OPCAddItems(this.editButtonLokasyon.Text); gridViewAlarmAdresler.SetRowCellValue(gridViewAlarmAdresler.FocusedRowHandle, "OkunanDeger", mngr.GetOPCItemSyncRead(this.editButtonLokasyon.Text, adres.ToString())); mngr.DisConnectServer(); mngr = null; //} } else { MessageBox.Show("Hata:Tag Degeri boş ya da adres seçmediniz !!!", "Uyarı..", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
public frmOpcServer() { InitializeComponent(); mngr = new OpcManager(); server = Persistence.Read <OPCServer>(new Condition[] { new Condition("Aktif", Operator.Equal, true) }); if (server != null) { OPCServerGroup[] groups = OPCServer.ReadGroups(server.Id); server.Groups.AddRange(groups); dataGridView1.DataSource = server.Groups; textBoxServerIsmi.Text = server.OpcServerName; textBoxOPCNodeIsmi.Text = server.OPCNodeName; } else { server = new OPCServer(); } dataGridView1.SetGridStyle( @"<Style> <Column Name='Id' HeaderText='Id' Width='100' DisplayIndex='0' Visible='false' /> <Column Name='OPCGroupName' HeaderText='OPCGroupName' Width='100' DisplayIndex='1' Visible='true' /> <Column Name='GroupUpdateRate' HeaderText='GroupUpdateRate' Width='100' DisplayIndex='2' Visible='true' /> <Column Name='GroupDeadBand' HeaderText='GroupDeadBand' Width='100' DisplayIndex='3' Visible='true' /> <Column Name='GroupActiveState' HeaderText='GroupActiveState' Width='100' DisplayIndex='4' Visible='true' Type ='CheckBox' /> </Style>"); }
private void frmCihazIzlem_FormClosing(object sender, FormClosingEventArgs e) { //mngr.ConnectedOPCServer.OPCGroups.GlobalDataChange -= mngr.OPCGroups_GlobalDataChange; mngr.ConnectGroupDataChangeKapat = true; mngr.GlobalDataChangeKapat = true; mngr.ConnectedOPCServer.OPCGroups.RemoveAll(); foreach (OPCAutomation.OPCGroupClass grp in mngr.ConnectedOPCServer.OPCGroups) { mngr.OPCRemoveItems(grp.Name); mngr.RemoveGroupServer(grp.Name); } mngr.ConnectGroupDataChangeKapat = false; mngr.GlobalDataChangeKapat = false; mngr.ConnectedOPCServer.Disconnect(); mngr = null; System.GC.Collect(); Utility.OpenForms.Remove(this.Name); }
void frmCihazTanim_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e) { object value = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "YazilacakDeger"); object adres = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "TagAdresi"); if (value != null && value != System.DBNull.Value && adres != null && adres != string.Empty) { //OpcManager mngr; //OPCServer opcserver = Persistence.Read<OPCServer>(new Condition("Aktif", Operator.Equal, 1)); //if (opcserver != null && opcserver.Id > 0) //{ // OPCServerGroup groups=OPCServer.ReadGroups(opcserver.Id,editButtonLokasyon.Text); // if (groups != null) // { // opcserver.Groups.Add(groups); // } // else // { // MessageBox.Show("Hata:Bu Lokasyona ait OPCServerGroup ismi boş !!!", "Uyarı..", MessageBoxButtons.OK, MessageBoxIcon.Warning); // return; // } mymodel.Adres[] adresler = Persistence.ReadList <Adres>(); List <string> adreslist = new List <string>(); adreslist.Add(adres.ToString()); mngr = new OpcManager(opcserver.Groups[0].OPCGroupName, adreslist); mngr.OPCServerConnect(opcserver.OpcServerName, opcserver.OPCNodeName); mngr.AddOpcGroupServer(opcserver.Groups[0].OPCGroupName, opcserver.Groups[0].GroupUpdateRate, opcserver.Groups[0].GroupActiveState, (float)opcserver.Groups[0].GroupDeadBand); mngr.OPCAddItems(this.editButtonLokasyon.Text); mngr.OPCItemWrite(this.editButtonLokasyon.Text, adres.ToString(), value.ToString()); gridView1.SetRowCellValue(gridView1.FocusedRowHandle, "OkunanDeger", mngr.GetOPCItemSyncRead(this.editButtonLokasyon.Text, adres.ToString())); mngr.DisConnectServer(); mngr = null; } //} // else // MessageBox.Show("Hata:Tag Degeri boş ya da adres seçmediniz !!!", "Uyarı..", MessageBoxButtons.OK, MessageBoxIcon.Warning); }
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; } }
void frmCihazTanim_ButtonClick3(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e) { object adres = gridViewAlarmAdresler.GetRowCellValue(gridViewAlarmAdresler.FocusedRowHandle, "TagAdresi"); if (adres != null && adres != string.Empty) { //OpcManager mngr; //OPCServer opcserver = Persistence.Read<OPCServer>(new Condition("Aktif", Operator.Equal, 1)); //if (opcserver != null && opcserver.Id > 0) //{ List<string> adreslist = new List<string>(); adreslist.Add(adres.ToString()); mngr = new OpcManager(opcserver.Groups[0].OPCGroupName,adreslist); mngr.OPCServerConnect(opcserver.OpcServerName, opcserver.OPCNodeName); //mngr.AddOpcGroupServer(opcserver.OPCGroupName, (opcserver.GroupUpdateRate), (opcserver.GroupActiveState), (float)opcserver.GroupDeadBand); mngr.AddOpcGroupServer(opcserver.Groups[0].OPCGroupName, opcserver.Groups[0].GroupUpdateRate, opcserver.Groups[0].GroupActiveState, (float)opcserver.Groups[0].GroupDeadBand); mngr.OPCAddItems(this.editButtonLokasyon.Text); gridViewAlarmAdresler.SetRowCellValue(gridViewAlarmAdresler.FocusedRowHandle, "OkunanDeger", mngr.GetOPCItemSyncRead(this.editButtonLokasyon.Text,adres.ToString())); mngr.DisConnectServer(); mngr = null; //} } else MessageBox.Show("Hata:Tag Degeri boş ya da adres seçmediniz !!!", "Uyarı..", MessageBoxButtons.OK, MessageBoxIcon.Warning); }
void frmCihazTanim_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e) { object value = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "YazilacakDeger"); object adres = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "TagAdresi"); if (value != null && value != System.DBNull.Value && adres != null && adres!=string.Empty) { //OpcManager mngr; //OPCServer opcserver = Persistence.Read<OPCServer>(new Condition("Aktif", Operator.Equal, 1)); //if (opcserver != null && opcserver.Id > 0) //{ // OPCServerGroup groups=OPCServer.ReadGroups(opcserver.Id,editButtonLokasyon.Text); // if (groups != null) // { // opcserver.Groups.Add(groups); // } // else // { // MessageBox.Show("Hata:Bu Lokasyona ait OPCServerGroup ismi boş !!!", "Uyarı..", MessageBoxButtons.OK, MessageBoxIcon.Warning); // return; // } mymodel.Adres[] adresler = Persistence.ReadList<Adres>(); List<string> adreslist = new List<string>(); adreslist.Add(adres.ToString()); mngr = new OpcManager(opcserver.Groups[0].OPCGroupName,adreslist); mngr.OPCServerConnect(opcserver.OpcServerName, opcserver.OPCNodeName); mngr.AddOpcGroupServer(opcserver.Groups[0].OPCGroupName, opcserver.Groups[0].GroupUpdateRate, opcserver.Groups[0].GroupActiveState, (float)opcserver.Groups[0].GroupDeadBand); mngr.OPCAddItems(this.editButtonLokasyon.Text); mngr.OPCItemWrite(this.editButtonLokasyon.Text,adres.ToString(), value.ToString()); gridView1.SetRowCellValue(gridView1.FocusedRowHandle, "OkunanDeger", mngr.GetOPCItemSyncRead(this.editButtonLokasyon.Text,adres.ToString())); mngr.DisConnectServer(); mngr = null; } //} // else // MessageBox.Show("Hata:Tag Degeri boş ya da adres seçmediniz !!!", "Uyarı..", MessageBoxButtons.OK, MessageBoxIcon.Warning); }