資源簡介
相信我,這應該是最全最全的 C#通過opc ua 協議連接plc的項目和文檔資料了!如果又不明白的可瀏覽我的博客,有相關的介紹和使用,歡迎交流討論。
代碼片段和文件信息
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?OPCtest4
{
????public?partial?class?Form1?:?Form
????{
????????OPCServer?KepServer;
????????OPCGroups?KepGroups;
????????OPCGroup?KepGroup;
????????OPCItems?KepItems;
????????OPCItem?KepItem;
????????bool?opc_connected?=?false;//連接狀態
????????int?itmHandleClient?=?0;//客戶端的句柄,句柄即控件名稱,如“張三”,用來識別是哪個具體的對象此處可理解為每個節點的編號
????????int?itmHandleServer?=?0;//服務器的句柄
????????public?Form1()
????????{
????????????InitializeComponent();
????????}
????????private?void?Form1_Load(object?sender?EventArgs?e)
????????{
????????????GetLocalServer();
????????}
????????///?
????????///?獲取本地的OPC服務器名稱
????????///?
????????public?void?GetLocalServer()
????????{
????????????IPHostEntry?host?=?Dns.GetHostEntry(“127.0.0.1“);
????????????var?strHostName?=?host.HostName;
????????????try
????????????{
????????????????KepServer?=?new?OPCServer();
????????????????object?serverList?=?KepServer.GetOPCServers(strHostName);
????????????????foreach?(string?turn?in?(Array)serverList)
????????????????{
????????????????????cmbServerName.Items.Add(turn);
????????????????}
????????????????cmbServerName.SelectedIndex?=?0;
????????????????btnConnServer.Enabled?=?true;
????????????}
????????????catch?(Exception?err)
????????????{
????????????????MessageBox.Show(“枚舉本地OPC服務器出錯:“?+?err.Message?“提示信息“?MessageBoxButtons.OK?MessageBoxIcon.Warning);
????????????}
????????}
????????///?
????????///?“連接“按鈕點擊事件
????????///?
????????///?
????????///?
????????private?void?BtnConnServer_Click(object?sender?EventArgs?e)
????????{
????????????try
????????????{
????????????????if?(!ConnectRemoteServer(txtRemoteServerIP.Text?cmbServerName.Text))
????????????????{
????????????????????return;
????????????????}
????????????????btnSetGroupPro.Enabled?=?true;
????????????????opc_connected?=?true;
????????????????GetServerInfo();
????????????????RecurBrowse(KepServer.CreateBrowser());
????????????????if?(!CreateGroup())
????????????????{
????????????????????return;
????????????????}
????????????}
????????????catch?(Exception?err)
????????????{
????????????????MessageBox.Show(“初始化出錯:“?+?err.Message?“提示信息“?MessageBoxButtons.OK?MessageBoxIcon.Warning);
????????????}
????????}
????????///?
????????///?連接服務器
????????///?
????????///?服務器IP
????????///?服務器名稱
????????///?
????????public?bool?ConnectRemoteServer(string?remoteServerIP?string?remoteServerName)
????????{
????????????try
????????????{
????????????????KepServer.Connect(remoteServ
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2020-02-28?15:14??OPC\
?????文件??????537499??2020-02-25?18:02??OPC\C#實現OPC訪問.pdf
?????目錄???????????0??2020-02-28?15:12??OPC\OPC_UA\
?????目錄???????????0??2020-02-28?15:12??OPC\OPC_UA\OPC_UA_CODE_v10\
?????目錄???????????0??2020-02-28?15:12??OPC\OPC_UA\OPC_UA_CODE_v10\bin\
?????文件???????90112??2009-07-03?14:39??OPC\OPC_UA\OPC_UA_CODE_v10\bin\Opc.Ua.Client.dll
?????文件?????2589184??2009-07-03?14:39??OPC\OPC_UA\OPC_UA_CODE_v10\bin\Opc.Ua.Core.dll
?????文件???????55296??2010-04-30?11:12??OPC\OPC_UA\OPC_UA_CODE_v10\bin\Siemens.OpcUA.Client.exe
?????文件???????22528??2010-04-30?11:12??OPC\OPC_UA\OPC_UA_CODE_v10\bin\Siemens.OpcUA.SimpleClient.exe
?????文件???????18944??2010-04-30?11:12??OPC\OPC_UA\OPC_UA_CODE_v10\bin\Siemens.OpcUA.dll
?????目錄???????????0??2020-02-28?15:12??OPC\OPC_UA\OPC_UA_CODE_v10\src\
?????目錄???????????0??2020-02-28?15:12??OPC\OPC_UA\OPC_UA_CODE_v10\src\ClientAPI\
?????文件???????40444??2010-04-30?11:03??OPC\OPC_UA\OPC_UA_CODE_v10\src\ClientAPI\ClientAPI.cs
?????文件????????3087??2010-02-16?09:40??OPC\OPC_UA\OPC_UA_CODE_v10\src\ClientAPI\ClientAPI.csproj
?????文件????????1727??2010-04-30?11:03??OPC\OPC_UA\OPC_UA_CODE_v10\src\ClientAPI\ClientDiscovery.cs
?????文件????????4351??2010-04-30?11:03??OPC\OPC_UA\OPC_UA_CODE_v10\src\ClientAPI\ClientSubsc
?????目錄???????????0??2020-02-28?15:12??OPC\OPC_UA\OPC_UA_CODE_v10\src\ClientAPI\Properties\
?????文件?????????841??2010-04-30?10:56??OPC\OPC_UA\OPC_UA_CODE_v10\src\ClientAPI\Properties\AssemblyInfo.cs
?????文件????????8472??2009-12-14?10:49??OPC\OPC_UA\OPC_UA_CODE_v10\src\ClientAPI\Properties\Helpers.cs
?????文件?????????120??2009-08-18?08:48??OPC\OPC_UA\OPC_UA_CODE_v10\src\ClientAPI\app.config
?????目錄???????????0??2020-02-28?15:12??OPC\OPC_UA\OPC_UA_CODE_v10\src\ClientAPI\bin\
?????目錄???????????0??2020-02-28?15:12??OPC\OPC_UA\OPC_UA_CODE_v10\src\ClientAPI\bin\Debug\
?????文件???????90112??2009-07-03?14:39??OPC\OPC_UA\OPC_UA_CODE_v10\src\ClientAPI\bin\Debug\Opc.Ua.Client.dll
?????文件?????2589184??2009-07-03?14:39??OPC\OPC_UA\OPC_UA_CODE_v10\src\ClientAPI\bin\Debug\Opc.Ua.Core.dll
?????文件???????20480??2020-02-27?16:43??OPC\OPC_UA\OPC_UA_CODE_v10\src\ClientAPI\bin\Debug\Siemens.OpcUA.dll
?????文件???????36352??2020-02-27?16:43??OPC\OPC_UA\OPC_UA_CODE_v10\src\ClientAPI\bin\Debug\Siemens.OpcUA.pdb
?????目錄???????????0??2020-02-28?15:12??OPC\OPC_UA\OPC_UA_CODE_v10\src\ClientAPI\obj\
?????目錄???????????0??2020-02-28?15:12??OPC\OPC_UA\OPC_UA_CODE_v10\src\ClientAPI\obj\Debug\
?????文件?????????809??2020-02-27?16:43??OPC\OPC_UA\OPC_UA_CODE_v10\src\ClientAPI\obj\Debug\ClientAPI.csproj.FileListAbsolute.txt
?????文件???????44420??2020-02-27?16:43??OPC\OPC_UA\OPC_UA_CODE_v10\src\ClientAPI\obj\Debug\ResolveAssemblyReference.cache
?????文件???????20480??2020-02-27?16:43??OPC\OPC_UA\OPC_UA_CODE_v10\src\ClientAPI\obj\Debug\Siemens.OpcUA.dll
............此處省略839個文件信息
評論
共有 條評論