資源簡介
OPC數據共享,可用于通訊,C#源代碼實現,加快通訊模塊的開發
代碼片段和文件信息
using?System;
using?System.Windows.Forms;
using?Opc;
using?Opc.Da;
using?OpcCom;
namespace?opcTest
{
????public?partial?class?Form1?:?Form
????{
????????private?Opc.Da.Server?m_server?=?null;//定義數據存取服務器
????????private?Opc.Da.Subscription?subscription?=?null;//定義組對象(訂閱者)
????????private?Opc.Da.SubscriptionState?state?=?null;//定義組(訂閱者)狀態,相當于OPC規范中組的參數
????????private?Opc.IDiscovery?m_discovery?=?new?ServerEnumerator();//定義枚舉基于COM服務器的接口,用來搜索所有的此類服務器。
????????public?Form1()
????????{
????????????InitializeComponent();
????????????textBox1.Text?=?“192.168.1.5“;
????????????button2.Enabled?=?false;
????????????button3.Enabled?=?false;
????????}
????????private?void?button1_Click(object?sender?EventArgs?e)
????????{
????????????//查詢服務器
????????????try
????????????{
????????????????Opc.Server[]?servers?=?m_discovery.GetAvailableServers(Specification.COM_DA_20?textBox1.Text?null);
????????????????if?(servers?!=?null)
????????????????{
????????????????????foreach?(Opc.Da.Server?server?in?servers)
????????????????????{
????????????????????????comboBox1.Items.Add(server.Name);
????????????????????}
????????????????}
????????????????comboBox1.SelectedIndex?=?0;
????????????????listBox1.Items.Add(“查詢服務器成功.請選擇OPC進行連接“);
????????????????button1.Enabled?=?false;
????????????????button2.Enabled?=?true;
????????????}
????????????catch?(Exception?ex)
????????????{
????????????????listBox1.Items.Add(ex.Message);
????????????}
????????}
????????private?void?button2_Click(object?sender?EventArgs?e)
????????{
????????????//連接
????????????if?(button2.Text==“釋放“)
????????????{
????????????????//結束:釋放各資源
????????????????button2.Text?=?“連接“;
????????????????listBox1.Items.Add(“釋放成功.不能進行讀取數據請重新連接“);
????????????????button3.Enabled?=?false;
????????????????try
????????????????{
????????????????????subscription.Dispose();//強制.NET資源回收站回收該subscription的所有資源。?????????
????????????????????m_server.Disconnect();//斷開服務器連接
????????????????}
????????????????catch?(Exception?ex)
????????????????{
????????????????????listBox1.Items.Add(ex.Message);
????????????????}
????????????}
????????????else
????????????{
????????????????try
????????????????{
????????????????????Opc.Server[]?servers?=?m_discovery.GetAvailableServers(Specification.COM_DA_20?textBox1.Text?null);
????????????????????if?(servers?!=?null)
????????????????????{
????????????????????????foreach?(Opc.Da.Server?server?in?servers)
????????????????????????{
????????????????????????????if?(String.Compare(server.Name?comboBox1.Text?true)?==?0)//為true忽略大小寫
????????????????????????????{
????????????????????????????????m_server?=?server;//建立連接。
????????????????????????????????break;
????????????????????????????}
????????????????????????}
????????????????????}
????????????????}
????????????????catch?(Exception?ex)
????????????????{
????????????????????listBox1.Items.Add(ex.Message);
????????????????????return;
??????????????
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????6294??2013-05-10?12:13??bank_pepole\Backup\OPC_Client\Form1.cs
?????文件??????10059??2013-05-10?12:13??bank_pepole\Backup\OPC_Client\Form1.Designer.cs
?????文件???????5814??2013-05-10?12:13??bank_pepole\Backup\OPC_Client\Form1.resx
?????文件???????5975??2013-05-10?13:33??bank_pepole\Backup\OPC_Client\OPC_Client.csproj
?????文件????????564??2013-05-10?13:33??bank_pepole\Backup\OPC_Client\OPC_Client.csproj.user
?????文件????????468??2012-12-12?14:43??bank_pepole\Backup\OPC_Client\Program.cs
?????文件???????1383??2013-05-10?12:09??bank_pepole\Backup\OPC_Client\Properties\AssemblyInfo.cs
?????文件???????2864??2012-12-12?14:43??bank_pepole\Backup\OPC_Client\Properties\Resources.Designer.cs
?????文件???????5612??2012-12-12?14:43??bank_pepole\Backup\OPC_Client\Properties\Resources.resx
?????文件???????1092??2012-12-12?14:43??bank_pepole\Backup\OPC_Client\Properties\Settings.Designer.cs
?????文件????????249??2012-12-12?14:43??bank_pepole\Backup\OPC_Client\Properties\Settings.settings
?????文件????????920??2013-05-10?12:14??bank_pepole\Backup\OPC_Client.sln
????..A..H.?????13824??2013-05-14?15:27??bank_pepole\Backup\OPC_Client.v11.suo
?????文件???50449456??2014-11-10?15:29??bank_pepole\document\dotNetFx40_Full_x86_x64.exe
?????文件?????899584??2015-11-19?22:40??bank_pepole\document\OPC?Core?Components?2.00?SDK?2.30.msi
?????文件????1278001??2015-11-05?15:19??bank_pepole\document\Win7系統下的OPC運行配置.pdf
?????文件???????4608??2016-01-05?16:32??bank_pepole\OpcEnumLib.dll
?????文件?????200704??2005-11-25?17:07??bank_pepole\OpcNetApi.Com.dll
?????文件?????225280??2005-11-25?17:07??bank_pepole\OpcNetApi.dll
?????文件???????9216??2008-07-09?16:50??bank_pepole\OpcRcw.Cmd.dll
?????文件???????6656??2008-07-09?16:50??bank_pepole\OpcRcw.Comn.dll
?????文件??????20992??2008-07-09?16:50??bank_pepole\OpcRcw.Da.dll
?????文件??????15872??2008-07-09?16:50??bank_pepole\OpcRcw.Dx.dll
?????文件??????12800??2008-07-09?16:50??bank_pepole\OpcRcw.Hda.dll
?????文件????????474??2016-06-23?14:56??bank_pepole\OPC_Client\app.config
?????文件????????474??2016-06-23?14:56??bank_pepole\OPC_Client\bin\Debug\app.config
?????文件??????????0??2015-11-29?08:56??bank_pepole\OPC_Client\bin\Debug\log\log.txt
?????文件??????26773??2015-12-04?09:47??bank_pepole\OPC_Client\bin\Debug\log\log_2015-12-04.txt
?????文件??????12006??2015-12-08?16:25??bank_pepole\OPC_Client\bin\Debug\log\log_2015-12-08.txt
?????文件???????4624??2015-12-09?12:36??bank_pepole\OPC_Client\bin\Debug\log\log_2015-12-09.txt
............此處省略106個文件信息
- 上一篇:C# VLC視頻直播 rtsp
- 下一篇:深入淺出WPF 重新整理目錄,帶源碼
評論
共有 條評論