public override void Initialize(string file) { opcServer = new OPCServer(Name); Config.Configuration config = new Config.Configuration(file); opcServer.Connect(config.ProgID, config.ServerName);// opcServer.Connect(config.ConnectionString); OPCGroup group = opcServer.AddGroup(config.GroupName, config.UpdateRate); foreach (Config.ItemInfo item in config.Items) { group.AddItem(item.ItemName, item.OpcItemName, item.ClientHandler, item.IsActive); } opcServer.Groups.DefaultGroup.OnDataChanged += new OPCGroup.DataChangedEventHandler(DefaultGroup_OnDataChanged); }
void initopc() { OpcSvr.Connect("KEPware.KEPServerEx.V6", "127.0.0.1"); //设置要连接OPC的版本和IP OpcIn = OpcSvr.OPCGroups.Add("OPCIN"); //设置监控的OPCGroup OpcIn.OPCItems.AddItem("1#BOF.PLC1ALLOY.Alloy_Weig1", 1); OpcIn.OPCItems.AddItem("1#BOF.PLC1ALLOY.Alloy_Weig2", 2); OpcIn.OPCItems.AddItem("1#BOF.PLC1ALLOY.Alloy_Weig3", 3); OpcIn.OPCItems.AddItem("1#BOF.PLC1ALLOY.Alloy_Weig4", 4); OpcIn.OPCItems.AddItem("1#BOF.PLC1ALLOY.Alloy_Weig5", 5); OpcIn.OPCItems.AddItem("1#BOF.PLC1ALLOY.Alloy_Weig6", 6); OpcIn.OPCItems.AddItem("1#BOF.PLC1ALLOY.Alloy_Weig7", 7); OpcIn.OPCItems.AddItem("1#BOF.PLC1ALLOY.Alloy_Weig8", 8); OpcIn.IsActive = true; //这个是标配 OpcIn.IsSubscribed = true; //这个是标配 OpcIn.DataChange += new DIOPCGroupEvent_DataChangeEventHandler(OpcInTri_DataChange); //给这个OPC采集的方法设置一个触发的方法,当OPC有改变的时候就会触发这个方法 }
public Form1() { try { InitializeComponent(); OPCServerName = "{Here comes your OPC server’s name}"; ObjOPCServer = new OPCServer(); ObjOPCServer.Connect(OPCServerName, "";); ObjOPCGroups = ObjOPCServer.OPCGroups; ObjOPCGroup = ObjOPCGroups.Add("OPCGroup1"); ObjOPCGroup.DataChange += new DIOPCGroupEvent_DataChangeEventHandler(ObjOPCGroup_DataChange); ObjOPCGroup.OPCItems.AddItem("{tag name or address (like {plc name on server}!%mw0)}", 1); ObjOPCGroup.UpdateRate = 10; ObjOPCGroup.IsActive = true; ObjOPCGroup.IsSubscribed = true; } catch (Exception e){ MessageBox.Show(e.ToString()); } }
public Form1() { try { InitializeComponent(); OPCServerName = "{Here comes your OPC server’s name}"; ObjOPCServer = new OPCServer(); ObjOPCServer.Connect(OPCServerName, ""; ); ObjOPCGroups = ObjOPCServer.OPCGroups; ObjOPCGroup = ObjOPCGroups.Add("OPCGroup1"); ObjOPCGroup.DataChange += new DIOPCGroupEvent_DataChangeEventHandler(ObjOPCGroup_DataChange); ObjOPCGroup.OPCItems.AddItem("{tag name or address (like {plc name on server}!%mw0)}", 1); ObjOPCGroup.UpdateRate = 10; ObjOPCGroup.IsActive = true; ObjOPCGroup.IsSubscribed = true; } catch (Exception e) { MessageBox.Show(e.ToString()); } }