欢迎来到天天文库
浏览记录
ID:43648356
大小:53.91 KB
页数:9页
时间:2019-10-11
《c# opc客户端开发》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;usingOPCAutomation;usingSystem.Net;namespaceOpc_Client{publicpartialclassForm1:Form{publicForm1(){InitializeComponent();}#re
2、gion私?有®D变À?量¢?OPCServerSyServer;OPCGroupsSyGroups;OPCGroupSyGroup;OPCItemsSyItems;OPCItemSyItem;stringstrHostIP=string.Empty;stringstrHostName=string.Empty;boolopc_connected=false;//连¢?接¨®状Á¡ä态¬?intitmHandleClient=0;//客¨ª户¡ì端?句?柄À¨²intitmHandleServer=0;//服¤t务?端?句?柄À¨²#endregion#region方¤?法¤¡
3、§privatevoidGetLocalServer(){IPHostEntryIPHost=Dns.GetHostEntry(Dns.GetHostName());if(IPHost.AddressList.Length>0){strHostIP=IPHost.AddressList[4].ToString();this.tboxServerIP.Text=strHostIP.ToString();}else{return;}IPHostEntryipHostEntry=Dns.GetHostByAddress(strHostIP);strHostName=ipHostEnt
4、ry.HostName.ToString();try{SyServer=newOPCServer();objectserverList=SyServer.GetOPCServers(strHostName);foreach(stringturnin(Array)serverList){this.cmbServerName.Items.Add(turn);cmbServerName.SelectedIndex=0;btnConnServer.Enabled=true;}}catch(Exceptionerr){MessageBox.Show("枚?举¨´本À?地Ì?OPC服¤t务
5、?器¡Â出?错䨪:êo"+err.Message,"提¬¨¢示º?信?息¡é",MessageBoxButtons.OK,MessageBoxIcon.Warning);}}privateboolCreatGroup(){try{SyGroups=SyServer.OPCGroups;SyGroup=SyGroups.Add("OPCDOTNETGROUP");SetGroupProperty();SyGroup.DataChange+=newDIOPCGroupEvent_DataChangeEventHandler(SyGroup_DataChange);SyGroup
6、.AsyncWriteComplete+=newDIOPCGroupEvent_AsyncWriteCompleteEventHandler(SyGroup_AsyncWriteComplete);SyItems=SyGroup.OPCItems;}catch(Exceptionerr){MessageBox.Show("创ä¡ä建¡§组Á¨¦出?现?错䨪误¨®"+err.Message,"提¬¨¢示º?信?息¡é",MessageBoxButtons.OK,MessageBoxIcon.Warning);returnfalse;}returntrue;}privatevo
7、idLoadDataToTree(OPCBrowseroPCBrowser,TreeNodeCollectiontreeNodeCollection){oPCBrowser.Organization.ToString();oPCBrowser.ShowBranches();foreach(objectturninoPCBrowser){TreeNodenode=treeNodeCollection.Add(turn.ToString());treeView1.SelectedNode=nod
此文档下载收益归作者所有