資源簡介
自己做的控制臺例子程序,OPC服務器用KEPServerEx 附帶了OPCDAAuto.dll文件,方便大家使用 功能包括:服務器連斷、組增減、item增減、DataChange回調,同步/異步讀等等功能
基于VS2008 C#
本人 裝了西門子的STEP7和NET2006,沒有裝的機器可能會報錯說某文件不存在

代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.Linq;
using?System.Text;
using?System.Net;
using?System.Collections;
using?OPCAutomation;
using?System.Threading;
namespace?OPCDAAutoTest
{
????class?Tester
????{
????????static?void?Main(string[]?args)
????????{
????????????Tester?tester=new?Tester();
????????????tester.work();
????????}
????????#region?私有變量
????????///?
????????///?OPCServer?object
????????///?
????????OPCServer?MyServer;
????????///?
????????///?OPCGroups?object
????????///?
????????OPCGroups?MyGroups;
????????///?
????????///?OPCGroup?object
????????///?
????????OPCGroup?MyGroup;
????????OPCGroup?MyGroup2;
????????///?
????????///?OPCItems?object
????????///?
????????OPCItems?MyItems;
????????OPCItems?MyItems2;
????????///?
????????///?OPCItem?object
????????///?
????????OPCItem[]?MyItem;
????????OPCItem[]?MyItem2;
????????///?
????????///?主機IP
????????///?
????????string?strHostIP?=?““;
????????///?
????????///?主機名稱
????????///?
????????string?strHostName?=?““;
????????///?
????????///?連接狀態
????????///?
????????bool?opc_connected?=?false;
????????///?
????????///?客戶端句柄
????????///?
????????int?itmHandleClient?=?0;
????????///?
????????///?服務端句柄
????????///?
????????int?itmHandleServer?=?0;
????????#endregion
????????//測試用工作方法
????????public?void?work()
????????{
????????????//初始化item數組
????????????MyItem?=?new?OPCItem[4];
????????????MyItem2?=?new?OPCItem[4];
????????????GetLocalServer();
????????????//ConnectRemoteServer(“TX1“?“KEPware.KEPServerEx.V4“);//用計算機名的局域網
????????????//ConnectRemoteServer(“192.168.1.35“?“KEPware.KEPServerEx.V4“);//用IP的局域網
????????????if?(ConnectRemoteServer(““?“KEPware.KEPServerEx.V4“))//本機
????????????{
????????????????if?(CreateGroup())
????????????????{
????????????????????Thread.Sleep(500);//暫停線程以讓DataChange反映,否則下面的同步讀可能讀不到
????????????????????//以下同步寫
????????????????????MyItem[3].Write(“I?love?you!“);//同步寫
????????????????????MyItem[2].Write(true);//同步寫
????????????????????MyItem[1].Write(-100);//同步寫
????????????????????MyItem[0].Write(120);//同步寫??????????????
???
????????????????????//以下同步讀
????????????????????object?ItemValues;??object?Qualities;?object?TimeStamps;//同步讀的臨時變量:值、質量、時間戳
????????????????????MyItem[0].Read(1out?ItemValuesout?Qualitiesout?TimeStamps);//同步讀,第一個參數只能為1或2
????????????????????int?q0?=?Convert.ToInt32(ItemValues);//轉換后獲取item值
????????????????????MyItem[1].Read(1?out?ItemValues?out?Qualities?out?TimeStamps);//同步讀,第一個參數只能為1或2
????????????????????int?q1?=?Convert.ToInt32(ItemValues);//轉換后獲取item值
????????????????????MyItem[2].Read(1?out?ItemValues?out?Qualities?out?TimeStamps);//同步讀,第一個參數只能為1或2
????????????????????bool?q2?=?Convert.ToBoolean(ItemValues);//轉換后獲取item值
???????
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件??????40960??2009-01-16?10:19??OPCDAAutoTest\OPCDAAutoTest\bin\Debug\Interop.OPCAutomation.dll
?????文件??????10240??2009-01-23?08:37??OPCDAAutoTest\OPCDAAutoTest\bin\Debug\OPCDAAutoTest.exe
?????文件??????19968??2009-01-23?08:37??OPCDAAutoTest\OPCDAAutoTest\bin\Debug\OPCDAAutoTest.pdb
?????文件??????14328??2009-01-23?08:37??OPCDAAutoTest\OPCDAAutoTest\bin\Debug\OPCDAAutoTest.vshost.exe
?????文件????????490??2007-07-21?01:33??OPCDAAutoTest\OPCDAAutoTest\bin\Debug\OPCDAAutoTest.vshost.exe.manifest
?????文件??????40960??2009-01-16?10:19??OPCDAAutoTest\OPCDAAutoTest\obj\Debug\Interop.OPCAutomation.dll
?????文件????????858??2009-01-23?08:37??OPCDAAutoTest\OPCDAAutoTest\obj\Debug\OPCDAAutoTest.csproj.FileListAbsolute.txt
?????文件????????550??2009-01-16?10:19??OPCDAAutoTest\OPCDAAutoTest\obj\Debug\OPCDAAutoTest.csproj.ResolveComReference.cache
?????文件??????10240??2009-01-23?08:37??OPCDAAutoTest\OPCDAAutoTest\obj\Debug\OPCDAAutoTest.exe
?????文件??????19968??2009-01-23?08:37??OPCDAAutoTest\OPCDAAutoTest\obj\Debug\OPCDAAutoTest.pdb
?????文件?????233472??2005-03-11?09:39??OPCDAAutoTest\OPCDAAutoTest\OPCDAAuto.dll
?????文件???????2827??2009-01-16?10:25??OPCDAAutoTest\OPCDAAutoTest\OPCDAAutoTest.csproj
?????文件??????14896??2009-01-23?08:37??OPCDAAutoTest\OPCDAAutoTest\Program.cs
?????文件???????1382??2009-01-16?10:18??OPCDAAutoTest\OPCDAAutoTest\Properties\AssemblyInfo.cs
?????文件????????929??2009-01-16?10:18??OPCDAAutoTest\OPCDAAutoTest.sln
????..A..H.?????13824??2009-01-22?17:08??OPCDAAutoTest\OPCDAAutoTest.suo
?????目錄??????????0??2009-01-16?10:24??OPCDAAutoTest\OPCDAAutoTest\obj\Debug\Refactor
?????目錄??????????0??2009-01-16?10:18??OPCDAAutoTest\OPCDAAutoTest\obj\Debug\TempPE
?????目錄??????????0??2009-01-16?10:25??OPCDAAutoTest\OPCDAAutoTest\bin\Debug
?????目錄??????????0??2009-01-23?08:37??OPCDAAutoTest\OPCDAAutoTest\obj\Debug
?????目錄??????????0??2009-01-16?10:18??OPCDAAutoTest\OPCDAAutoTest\bin
?????目錄??????????0??2009-01-16?10:18??OPCDAAutoTest\OPCDAAutoTest\obj
?????目錄??????????0??2009-01-16?10:18??OPCDAAutoTest\OPCDAAutoTest\Properties
?????目錄??????????0??2009-01-23?08:37??OPCDAAutoTest\OPCDAAutoTest
?????目錄??????????0??2009-01-16?10:18??OPCDAAutoTest
-----------?---------??----------?-----??----
???????????????425892????????????????????25
- 上一篇:接收發送HTTP報文
- 下一篇:自己用C#寫的計算器的源代碼修改版
評論
共有 條評論