KepServer可以将任何工业设备的通信协议转换为opc协议,然后用OPCAutomation进行上位机数据读写。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using OPCAutomation;
namespace KepTest1
{
public partial class FrmMain : Form
{
public FrmMain()
{
InitializeComponent();
this.Load += FrmMain_Load;
}
private void FrmMain_Load(object sender, EventArgs e)
{
this.btnRefresh_Click(btnRefresh, null);
this.dataGridViewValue.AutoGenerateColumns = false;
}
OPCServer opcServer;
OPCGroups opcGroups;
OPCGroup opcGroup;
OPCItems opcItems;
OPCItem opcItem; //项
Dictionary<string, OPCItem> dicOpcItem = new Dictionary<string, OPCItem>();
List<OPCItem> opcItemList = new List<OPCItem>(); //项的集合
OPCBrowser opcBrowser;
string strHostName = null;
object opcServerList;
List<OpcValue> opcValueList = new List<OpcValue>();
int clientHandle; //change句柄
int count;
//异步写入相关
Array writeErrors;
int cancelId;
private void btnConn_Click(object sender, EventArgs e)
{
//连接服务器
if (opcServer != null)
{
opcServer = new OPCServer();
}
try
{
opcServer.Connect(this.cmb_ServerName.Text, this.cmb_ServerNode.Text);
}
catch (Exception ex)
{
MessageBox.Show("连接失败:" + ex.Message);
return;
}
opcBrowser = this.opcServer.CreateBrowser(); //由OPC 节点创建浏览器
opcBrowser.ShowBranches();//展示浏览器属性
opcBrowser.ShowLeafs(true); //叶节点展示
//绑定 其实是浏览器browers
this.listBoxServer.Items.Clear();
foreach (var item in opcBrowser)
{
if (!thi

本文介绍了如何使用KepServer将工业设备的通信协议转换为OPC,实现在上位机上对西门子PLC的MD200等数据的读写操作,包括OPC连接、数据订阅、异步写入及实时刷新。
最低0.47元/天 解锁文章
4155

被折叠的 条评论
为什么被折叠?



