📄 opc.cs
字号:
using System;
using System.Collections.Generic;
using System.Text;
using OPCAutomation;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace WindowsApplication1
{
sealed class OPC
{
[DllImport("kernel32.dll")]
public static extern int GetTickCount();
#region OPC连接的变量
string ServerName = "OPC.SimaticNET"; // ‘OPC的类型
//string NodeName = "soft";
//string ip = "";//'结点名,即计算机名
//string OPCWay = "S7:[ccc1|VFD1|S7ONLINE]"; //'Step7 用
string OPCWay = "S7:[S7 connection_1]"; // Simatic用
const int RI50 = 170;
const int RI51 = 232;
const int RI52 = 40;
const int RI53 = 52;
const int RI54 = 150;
const int RI55 = 120;
const int RI56 = 80;
const int RI57 = 120;
const int RI58 = 200;
const int RI59 = 120;
const int RI61 = 90;
const int RI63 = 364;
const int RI65 = 8;
const int RI66 = 50;
const int RI90 = 340;
//static object DBD;
int i;
///OPCServer MyOPCServer;
//public OPCGroups MyOPCGroups;
OPCGroup OPCGroup50;
OPCGroup OPCGroup51;
OPCGroup OPCGroup52;
OPCGroup OPCGroup53;
OPCGroup OPCGroup54;
OPCGroup OPCGroup55;
OPCGroup OPCGroup56;
OPCGroup OPCGroup57;
OPCGroup OPCGroup58;
OPCGroup OPCGroup59;
OPCGroup OPCGroup61;
OPCGroup OPCGroup63;
OPCGroup OPCGroup65;
OPCGroup OPCGroup66;
OPCGroup OPCGroup90;
public static OPCItems OPCItemColl50;
public static OPCItems OPCItemColl51;
public static OPCItems OPCItemColl52;
public static OPCItems OPCItemColl53;
public static OPCItems OPCItemColl54;
public static OPCItems OPCItemColl55;
public static OPCItems OPCItemColl56;
public static OPCItems OPCItemColl57;
public static OPCItems OPCItemColl58;
public static OPCItems OPCItemColl59;
public static OPCItems OPCItemColl61;
public static OPCItems OPCItemColl63;
public static OPCItems OPCItemColl65;
public static OPCItems OPCItemColl66;
public static OPCItems OPCItemColl90;
//Array ServerHandlesOut;
//Array ErrorsOut;
// Array ReadItemLb50 = Array.CreateInstance(typeof(String), new int[] { RI50 }, new int[] { 1 });
string[] ReadItemLbl50 = new string[RI50+1];
string[] ReadItemLbl51 = new string[RI51+1];
string[] ReadItemLbl52 = new string[RI52+1];
string[] ReadItemLbl53 = new string[RI53+1];
string[] ReadItemLbl54 = new string[RI54+1];
string[] ReadItemLbl55 = new string[RI55+1];
string[] ReadItemLbl56 = new string[RI56+1];
string[] ReadItemLbl57 = new string[RI57+1];
string[] ReadItemLbl58 = new string[RI58+1];
string[] ReadItemLbl59 = new string[RI59+1];
string[] ReadItemLbl61 = new string[RI61+1];
string[] ReadItemLbl63 = new string[RI63+1];
string[] ReadItemLbl65 = new string[RI65+1];
string[] ReadItemLbl66 = new string[RI66+1];
string[] ReadItemLbl90 = new string[RI90+1];
//Array ClientHandles50=Array.CreateInstance(typeof(string), new int[]{RI50}, new int[]{1});
int[] ClientHandles50 = new int[RI50+1];
int[] ClientHandles51 = new int[RI51+1];
int[] ClientHandles52 = new int[RI52+1];
int[] ClientHandles53 = new int[RI53+1];
int[] ClientHandles54 = new int[RI54+1];
int[] ClientHandles55 = new int[RI55+1];
int[] ClientHandles56 = new int[RI56+1];
int[] ClientHandles57 = new int[RI57+1];
int[] ClientHandles58 = new int[RI58+1];
int[] ClientHandles59 = new int[RI59+1];
int[] ClientHandles61 = new int[RI61+1];
int[] ClientHandles63 = new int[RI63+1];
int[] ClientHandles65 = new int[RI65+1];
int[] ClientHandles66 = new int[RI66+1];
int[] ClientHandles90 = new int[RI90+1];
#endregion
#region 程序方法实现初始化部分
private void InitRItemLbl50()
{
int i = 0;
int DBXH = 0;
int DBXL = 0;
do
{
ClientHandles50[i] = i;
i = i + 1;
ReadItemLbl50[i] = OPCWay + "DB50," + DBXH + "." + DBXL;
DBXL = DBXL + 1;
if (DBXL > 7)
{
DBXL = 0;
DBXH = DBXH + 1;
}
//splash.ProgressBar.Value = i;
} while (i < RI50);
}
private void InitRItemLbl51()
{
int i = 0;
int DBXH = 0;
int DBXL = 0;
do
{
ClientHandles51[i] = i;
i = i + 1;
ReadItemLbl51[i] = OPCWay + "DB51," + DBXH + "." + DBXL;
DBXL = DBXL + 1;
if (DBXL > 7)
{
DBXL = 0;
DBXH = DBXH + 1;
}
// splash.ProgressBar.Value = i;
} while (i < RI51);
}
private void InitRItemLbl52()
{
int i = 0;
int DBXH = 0;
int DBXL = 0;
do
{
ClientHandles52[i] = i;
i = i + 1;
ReadItemLbl52[i] = OPCWay + "DB52," + DBXH + "." + DBXL;
DBXL = DBXL + 1;
if (DBXL > 7)
{
DBXL = 0;
DBXH = DBXH + 1;
}
//splash.ProgressBar.Value = i;
} while (i < RI52);
}
private void InitRItemLbl53()
{
int i = 0;
int DBD = 0;
do
{
ClientHandles53[i] = i;
i = i + 1;
ReadItemLbl53[i] = OPCWay + "DB53,W" + DBD;
DBD = DBD + 2;
//splash.ProgressBar.Value = i;
} while (i < RI53);
}
private void InitRItemLbl54()
{
int i = 0;
int DBD = 0;
do
{
ClientHandles54[i] = i;
i = i + 1;
ReadItemLbl54[i] = OPCWay + "DB54,REAL" + DBD;
DBD = DBD + 4;
//splash.ProgressBar.Value = i;
} while (i < 65);
//ReadItemLbl54[i] = OPCWay + "DB54,DINT" + DBD - 4;
i = 65;
DBD = 258;
do
{
ClientHandles54[i] = i;
i = i + 1;
ReadItemLbl54[i] = OPCWay + "DB54,REAL" + DBD;
DBD = DBD + 4;
//splash.ProgressBar.Value = i;
} while (i < RI54);
}
private void InitRItemLbl55()
{
int i = 0;
int DBD = 0;
do
{
ClientHandles55[i] = i;
i = i + 1;
ReadItemLbl55[i] = OPCWay + "DB55,REAL" + DBD;
DBD = DBD + 4;
//splash.ProgressBar.Value = i;
} while (i < RI55);
}
private void InitRItemLbl56()
{
int i = 0;
int DBD = 0;
do
{
ClientHandles56[i] = i;
i = i + 1;
ReadItemLbl56[i] = OPCWay + "DB56,REAL" + DBD;
DBD = DBD + 4;
//splash.ProgressBar.Value = i;
} while (i < RI56);
}
private void InitRItemLbl57()
{
int i = 0;
int DBD = 0;
do
{
ClientHandles57[i] = i;
i = i + 1;
ReadItemLbl57[i] = OPCWay + "DB57,REAL" + DBD;
DBD = DBD + 4;
// splash.ProgressBar.Value = i;
} while (i < RI57);
}
private void InitRItemLbl58()
{
int i = 0;
int DBD = 0;
do
{
ClientHandles58[i] = i;
i = i + 1;
ReadItemLbl58[i] = OPCWay + "DB58,REAL";
DBD = DBD + 4;
//splash.ProgressBar.Value = i;
} while (i < RI58);
}
private void InitRItemLbl59()
{
int i = 0;
int DBD = 0;
do
{
ClientHandles59[i] = i;
i = i + 1;
ReadItemLbl59[i] = OPCWay + "DB59,REAL" + DBD;
DBD = DBD + 4;
//splash.ProgressBar.Value = i;
} while (i < RI59);
}
private void InitRItemLbl61()
{
int i = 0;
int DBXH = 0;
int DBXL = 0;
do
{
ClientHandles61[i] = i;
i = i + 1;
ReadItemLbl61[i] = OPCWay + "DB61," + DBXH + "." + DBXL;
DBXL = DBXL + 1;
if (DBXL > 7)
{
DBXL = 0;
DBXH = DBXH + 1;
}
// splash.ProgressBar.Value = i;
} while (i < RI61);
}
private void InitRItemLbl63()
{
int i = 0;
int DBXH = 0;
int DBXL = 0;
do
{
ClientHandles63[i] = i;
i = i + 1;
ReadItemLbl63[i] = OPCWay + "DB63," + DBXH + "." + DBXL;
DBXL = DBXL + 1;
if (DBXL > 7)
{
DBXL = 0;
DBXH = DBXH + 1;
}
// splash.ProgressBar.Value = i;
} while (i < RI63);
}
private void InitRItemLbl65()
{
int i = 0;
int DBD = 0;
do
{
ClientHandles65[i] = i;
i = i + 1;
ReadItemLbl65[i] = OPCWay + "DB65,REAL" + DBD;
DBD = DBD + 4;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -