Net Core教程

c# OPC Client 采集kepserver--转载

本文主要是介绍c# OPC Client 采集kepserver--转载,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

1.下载OPCDAAuto.dll http://www.ddooo.com/softdown/83516.htm
2.按照里面的txt进行注册
3.参照一下两个链接进行编写程序,链接参照下面,读写参照上面 https://www.cnblogs.com/qq458978/p/9789571.html https://www.haolizi.net/example/view_16928.html
4.当调试可以运行,点击exe运行不了时,可能是你的驱动下载的有问题
5.下面是我的读写部分
6.MyItem = new OPCItem[1];
objServer = new OPCServer();
//连接opc server
objServer.Connect("KEPware.KEPServerEx.V6","127.0.0.1");
//(2)建立一个opc组集合
objGroups = objServer.OPCGroups;
//(3)建立一个opc组
objGroup = objGroups.Add("cerr"); //Group组名字可有可无
//(4)添加opc标签
objGroup.IsActive = true; //设置该组为活动状态,连接PLC时,设置为非活动状态也一样
// objGroup.IsSubscribed = true; //设置异步通知
objGroup.UpdateRate = 850;
objServer.OPCGroups.DefaultGroupDeadband = 0;
// objGroup.DataChange += new DIOPCGroupEvent_DataChangeEventHandler(KepGroup_DataChange);
// objGroup.AsyncReadComplete += new DIOPCGroupEvent_AsyncReadCompleteEventHandler(AsyncReadComplete);
// objGroup.AsyncWriteComplete += new DIOPCGroupEvent_AsyncWriteCompleteEventHandler(AsyncWriteComplete);
objItems = objGroup.OPCItems; //建立opc标签集合

 

MyItems = objGroup.OPCItems;
MyItem[0] = MyItems.AddItem("s71200.1200.test2", 1);//string
// Thread.Sleep(800);
MyItem[0].Write(true);//同步写
Thread.Sleep(500);

 

object ItemValues; object Qualities; object TimeStamps;//同步读的临时变量:值、质量、时间戳
MyItem[0].Read(1, out ItemValues, out Qualities, out TimeStamps);//同步读,第一个参数只能为1或2
bool q3 = Convert.ToBoolean(ItemValues);//转换后获取item值,为防止读到的值为空,不用ItemValues.ToString()
textBox1.Text = q3.ToString();


objServer.OPCGroups.RemoveAll();
objServer.Disconnect();
————————————————

原文链接:https://blog.csdn.net/qq_42859646/article/details/95042842

这篇关于c# OPC Client 采集kepserver--转载的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!