下面这段代码是网上抄来的,相信有人也找到过这段,实际上真正运行的时候就会发现其实是有问题的,我把它修改了下,能正常读写了。 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Runtime.InteropServices; namespace kingview { public partial class Form1 : Form { /// /// 与组态王建立连接 /// 每次应用程序启动时,必须用该函数与组态王建立连接 /// /// node为节点(IP),如果是本机,其值为空 /// 返回错误码,见附录。 [DllImport("kingvewcliend.dll")] public static extern int StartCliend(string node); /// /// 得到组态王SDK中列出的项目(包括变量及其域)总数 /// [DllImport("kingvewcliend.dll")] public static extern int ReadItemNo(); /// /// 得到某个项目的名称 /// 将返回组态王的项目的名称 /// 为用户写入的其要取的变量的索引号,其为ReadItemNo返回的范围内的某个数 /// 返回错误码,见附录 /// [DllImport("kingvewcliend.dll")] //[SecurityPermission(SecurityAction.Assert, Unrestricted = true)] public static extern int GetItemNames(StringBuilder sName, int wItemId); /// /// 将某个项目添加到采集列中 /// 是要加入采集的项目名 /// TagId项目采集的标识号 /// 项目的数据类型 /// 返回错误码,见附录 /// [DllImport("kingvewcliend.dll")] public static extern int AddTag(string sRegName, ref int TagId, ref int TagDataType); /// /// 向某个项目中有应用程序向组态王方向写数据 /// /// 为要采集项目的标识号 /// bVal、lVal、fVal、sVal为设定的数值,用户将根据变量的类型设定数值 /// bVal、lVal、fVal、sVal为设定的数值,用户将根据变量的类型设定数值 /// b
2021-11-23 17:17:59 23KB 组态王 opc Kingvewclien KingView
1