在上一篇中已经简单尝试了从OPC中读取标签,这次我们进行标签的写入
标签写入主要分为同步和异步,同步的比较简单
//ServerHandle是标签句柄,value则是要写入的值 OPCList[ServerHandle].Write(value);
而对于异步
string value = tWriteText.Text.Trim(); //要写入的值 string Tag = lst_Items.SelectedItem.ToString(); int Handle = OPCList.FindIndex(it => it.ItemID == Tag); //获取标签的句柄 int[] reServerHandle = new int[2] { 0, Handle }; //此处是获取要写入标签的Handle,因为句柄0是默认占用的,所以此处是一个长度为2的数组 Array arrayReServerHandle = reServerHandle.ToArray(); object[] reValue = new object[2] { "", value }; //和句柄数组对应 Array values = reValue.ToArray(); KepGroup.AsyncWrite(1, ref arrayReServerHandle, ref values, out writeErrors, 2022, out cancelId);
标签:KEPServer,C#,标签,写入,value,int,PLC,句柄,Handle From: https://www.cnblogs.com/M-MAKI/p/16743899.html