OPCServer:使用KEPServer
https://www.cnblogs.com/ioufev/p/9366877.html
1.下載安裝
實際OPCServer使用(450M,中文,破解時間限制):KEPServer V6,百度網盤 ,密碼: ykj2
2. 添加仿真器或者硬件PLC S7-300,S7-1200
仿真器就選:Simulator
西門子硬件就選:siemens TCP/IP ethernet,
如果連接硬件:參考這里:https://www.cnblogs.com/txwtech/p/15218280.html
記得輸入PLC 的IP
標記里面的地址:K0003是隨便寫的。連接了硬件PLC,就輸入PLC的實際需要操作的地址即可。
程序鏈接:c# 連接KepServer仿真器demo(not free)
c#連接KEPServer后,寫入數據,就可以觀察其變化
public static void initOPC(List<Wms_OpcTagListModel> taglist) { InitOK = false; if (OpcLink != null) { OpcLink.Dispose(); } OpcLink = new DaClient(new Uri("opcda://127.0.0.1/KEPware.KEPServerEx.V6")); // Opc.Server[] servers = m_discovery.GetAvailableServers(Specification.COM_DA_20,“OPC服務器IP地址”,null); //opcda://127.0.0.1/Matrikon.OPC.Simulation.1 OpcLink.Options.DefaultMonitorInterval = 1000; OpcLink.Options.MaxPublishRequestCount = int.MaxValue; OpcLink.Options.MaxNotificationQueueSize = int.MaxValue; //OpcLink.Options.SessionTimeout = uint.MaxValue; OpcLink.Options.MaxMessageQueueSize = int.MaxValue; OpcLink.Options.MaxSubscriptionCount = int.MaxValue; //OpcLink.Options.SubscriptionLifetimeCount = uint.MaxValue; //OpcLink.Options.SubscriptionKeepAliveCount= int.MaxValue; OpcLink.Connect(); while (OpcLink.Status != OpcStatus.Connected) { Thread.Sleep(5); Console.WriteLine("連接失敗"); } if (OpcLink.Status == OpcStatus.Connected) { Thread.Sleep(5); Console.WriteLine("連接成功"); } // OpcGroup group = OpcLink.AddGroup("opc"); // OpcLink.AddItems("opc", new string[] {"PLC.Device1.Start", "PLC.Device1.Allow" }); // group.DataChange += new OpcObeser().Group_DataChange; InitOK = true; string get_data = OpcLink.Read<string>("通道1.設備1.Tag1"); Console.WriteLine("PLC tag1 data: "+get_data); OpcLink.Write<string>("通道1.設備1.Tag1", "22"); Console.WriteLine("PLC write tag1 data"); Thread.Sleep(2000); string get_data2 = OpcLink.Read<string>("通道1.設備1.Tag1"); Console.WriteLine("changed PLC tag1 data: " + get_data2);
點擊quick client,