opcdefine.cs
来自「OPCserver OPCserver.rar」· CS 代码 · 共 203 行
CS
203 行
#define Win32
//using Microsoft.VisualBasic;
//using AxComctlLib;
using System;
using System.Data;
//using Microsoft.VisualBasic.Compatibility;
using System.Collections;
using System.Windows.Forms;
using System.Diagnostics;
using System.Drawing;
using System.Runtime.InteropServices;
namespace CNETServer
{
sealed class opcdefine
{
////////////////////////////////////////////////////////////////////////////////////////////////
//// filename : opcdefine.bas
//// opc server 定义文件 For DA 2.05 版
//// author: tuolin email: tuolin2003@sina.com
//// Lasttime: 2003/05/8 ver 1.01
////////////////////////////////////////////////////////////////////////////////////////////////
public const short OPC_QUALITY_BAD = 0x0;
public const short OPC_QUALITY_UNCERTAIN = 0x40;
public const short OPC_QUALITY_GOOD = 0xC0;
public const short OPC_QUALITY_CONFIG_ERROR = 0x4;
public const short OPC_QUALITY_NOT_CONNECTED = 0x8;
public const short OPC_QUALITY_DEVICE_FAILURE = 0xC;
public const short OPC_QUALITY_SENSOR_FAILURE = 0x10;
public const short OPC_QUALITY_LAST_KNOWN = 0x14;
public const short OPC_QUALITY_COMM_FAILURE = 0x18;
public const short OPC_QUALITY_OUT_OF_SERVICE = 0x1C;
public const short OPC_QUALITY_LAST_USABLE = 0x44;
public const short OPC_QUALITY_SENSOR_CAL = 0x50;
public const short OPC_QUALITY_EGU_EXCEEDED = 0x54;
public const short OPC_QUALITY_SUB_NORMAL = 0x58;
public const short OPC_QUALITY_LOCAL_OVERRIDE = 0xD8;
public enum OPCSERVERSTATE
{
OPC_STATUS_RUNNING = 1,
OPC_STATUS_FAILED = OPCSERVERSTATE.OPC_STATUS_RUNNING + 1,
OPC_STATUS_NOCONFIG = OPCSERVERSTATE.OPC_STATUS_FAILED + 1,
OPC_STATUS_SUSPENDED = OPCSERVERSTATE.OPC_STATUS_NOCONFIG + 1,
OPC_STATUS_TEST = OPCSERVERSTATE.OPC_STATUS_SUSPENDED + 1
}
public struct FILETIME
{
public int dwLowDateTime;
public int dwHighDateTime;
}
public struct SYSTEMTIME
{
public short wYear;
public short wMonth;
public short wDayOfWeek;
public short wDay;
public short wHour;
public short wMinute;
public short wSecond;
public short wMilliseconds;
}
////Init
////初始化OPC Server
////static const GUID pCLSID =
////{ 0x90ca4f34, 0xb61a, 0x4e29, { 0x8d, 0xc6, 0xb6, 0xde, 0xf4, 0x1b, 0x25, 0xbd } }
[DllImport("TLSvrRdk.dll", ExactSpelling=true, CharSet=CharSet.Ansi, SetLastError=true)]
public static extern bool TL_InitOpcServer(ref byte pCLSID, int uServerRate);
////const LPSTR lpCLSID = "{90CA4F34-B61A-4e29-8DC6-B6DEF41B25BD}"
[DllImport("TLSvrRdk.dll", ExactSpelling=true, CharSet=CharSet.Ansi, SetLastError=true)]
public static extern bool TL_InitOpcServerS(string lpCLSID, int uServerRate);
////请求断开所有的客户端程序
[DllImport("TLSvrRdk.dll", ExactSpelling=true, CharSet=CharSet.Ansi, SetLastError=true)]
public static extern void TL_RequestAllDisconnect();
////结束
[DllImport("TLSvrRdk.dll", ExactSpelling=true, CharSet=CharSet.Ansi, SetLastError=true)]
public static extern void TL_UnInitOpcServer();
////Tag
////添加点,如不成功返值为0
[DllImport("TLSvrRdk.dll", ExactSpelling=true, CharSet=CharSet.Ansi, SetLastError=true)]
public static extern int TL_CreateTag(string lpName, object Value, short wInitialQuality, bool isWrite);
//// 可设定点的各种属性详见DA 2.04 中的 41页 4.4.6 节
[DllImport("TLSvrRdk.dll", ExactSpelling=true, CharSet=CharSet.Ansi, SetLastError=true)]
public static extern int TL_SetTagProperties(int hTagHandle, int dwPropertyID, string lpDescription, object Value);
////删除点
[DllImport("TLSvrRdk.dll", ExactSpelling=true, CharSet=CharSet.Ansi, SetLastError=true)]
public static extern int TL_RemoveTag(int hTagHandle);
////该函数读取点的值
[DllImport("TLSvrRdk.dll", ExactSpelling=true, CharSet=CharSet.Ansi, SetLastError=true)]
public static extern int TL_ReadTag(int hTagHandle, ref object lpValue);
////该函数读取带时标的点的值
//UPGRADE_WARNING: 结构 FILETIME 可能要求封送处理属性作为此声明语句中的参数传递。 单击以获得更多信息:“ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup1050"”
[DllImport("TLSvrRdk.dll", ExactSpelling=true, CharSet=CharSet.Ansi, SetLastError=true)]
public static extern int TL_ReadTagWithTimeStamp(int hTagHandle, ref object lpValue, ref short lpQuality, ref FILETIME lpTimestamp);
//// 刷新点
[DllImport("TLSvrRdk.dll", ExactSpelling=true, CharSet=CharSet.Ansi, SetLastError=true)]
public static extern int TL_UpdateTag(int hTagHandle, object Value, short wQuality);
////按名称刷新点
[DllImport("TLSvrRdk.dll", ExactSpelling=true, CharSet=CharSet.Ansi, SetLastError=true)]
public static extern int TL_UpdateTagByName(string lpName, object Value, short wQuality);
//// 带时标刷新点
//UPGRADE_WARNING: 结构 FILETIME 可能要求封送处理属性作为此声明语句中的参数传递。 单击以获得更多信息:“ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup1050"”
[DllImport("TLSvrRdk.dll", ExactSpelling=true, CharSet=CharSet.Ansi, SetLastError=true)]
public static extern int TL_UpdateTagWithTimeStamp(int hTagHandle, object Value, short wQuality, ref FILETIME Timestamp);
////取当前激活的客户端个数
[DllImport("TLSvrRdk.dll", ExactSpelling=true, CharSet=CharSet.Ansi, SetLastError=true)]
public static extern short TL_GetClientCounts();
////设定hash 表大小,如果大于0则表示内部查找点使用 hash 算法.
[DllImport("TLSvrRdk.dll", ExactSpelling=true, CharSet=CharSet.Ansi, SetLastError=true)]
public static extern int TL_SetHashSize(int ulHashSize);
////Register
////当成NT Server 一样运行
[DllImport("TLSvrRdk.dll", ExactSpelling=true, CharSet=CharSet.Ansi, SetLastError=true)]
public static extern int TL_AsNTService(string lpSvrName);
[DllImport("TLSvrRdk.dll", ExactSpelling=true, CharSet=CharSet.Ansi, SetLastError=true)]
public static extern bool TL_SetupRegCode(string lpSetupRegCode);
////注册OPC Server
////static const GUID pCLSID =
////{ 0x90ca4f34, 0xb61a, 0x4e29, { 0x8d, 0xc6, 0xb6, 0xde, 0xf4, 0x1b, 0x25, 0xbd } }
[DllImport("TLSvrRdk.dll", ExactSpelling=true, CharSet=CharSet.Ansi, SetLastError=true)]
public static extern int TL_Registry(ref byte pCLSID, string lpSvrName, string lpDescr, string lpExepath);
////const LPSTR lpCLSID = "{90CA4F34-B61A-4e29-8DC6-B6DEF41B25BD}"
[DllImport("TLSvrRdk.dll", ExactSpelling=true, CharSet=CharSet.Ansi, SetLastError=true)]
public static extern int TL_RegistryS(string lpCLSID, string lpSvrName, string lpDescr, string lpExepath);
////反注册OPC Server
////static const GUID pCLSID =
////{ 0x90ca4f34, 0xb61a, 0x4e29, { 0x8d, 0xc6, 0xb6, 0xde, 0xf4, 0x1b, 0x25, 0xbd } }
[DllImport("TLSvrRdk.dll", ExactSpelling=true, CharSet=CharSet.Ansi, SetLastError=true)]
public static extern int TL_Unregister(ref byte pCLSID, string lpSvrName);
////const LPSTR lpCLSID = "{90CA4F34-B61A-4e29-8DC6-B6DEF41B25BD}"
[DllImport("TLSvrRdk.dll", ExactSpelling=true, CharSet=CharSet.Ansi, SetLastError=true)]
public static extern int TL_UnregisterS(string lpCLSID, string lpSvrName);
////Server State
////区分点名称大小写
[DllImport("TLSvrRdk.dll", ExactSpelling=true, CharSet=CharSet.Ansi, SetLastError=true)]
public static extern int TL_SetMatchCase(int bModelFlag);
//// 该函数用来设置服务器的运行状态。默认值为OPC_STATUS_RUNNING
//UPGRADE_WARNING: 结构 OPCSERVERSTATE 可能要求封送处理属性作为此声明语句中的参数传递。 单击以获得更多信息:“ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup1050"”
[DllImport("TLSvrRdk.dll", ExactSpelling=true, CharSet=CharSet.Ansi, SetLastError=true)]
public static extern void TL_SetServerState(OPCSERVERSTATE sServerState);
////该函数用来设置服务器主版本号。默认为零
[DllImport("TLSvrRdk.dll", ExactSpelling=true, CharSet=CharSet.Ansi, SetLastError=true)]
public static extern void TL_SetMajorVersion(short wMajorVersion);
////该函数用来设置服务器副版本号。默认为零
[DllImport("TLSvrRdk.dll", ExactSpelling=true, CharSet=CharSet.Ansi, SetLastError=true)]
public static extern void TL_SetMinorVersion(short wMinorVersion);
////该函数用来设置服务器版本创建号。默认为零。
[DllImport("TLSvrRdk.dll", ExactSpelling=true, CharSet=CharSet.Ansi, SetLastError=true)]
public static extern void TL_SetBuildNumber(short wBuildNumber);
////该函数用来设置服务器厂商信息。默认为TL SoftWare
[DllImport("TLSvrRdk.dll", ExactSpelling=true, CharSet=CharSet.Ansi, SetLastError=true)]
public static extern void TL_SetVendorInfo(string lpVendorInfo);
////该函数用来设置服务器的带宽。默认值为0x0
[DllImport("TLSvrRdk.dll", ExactSpelling=true, CharSet=CharSet.Ansi, SetLastError=true)]
public static extern void TL_SetBandWidth(int dwBandWidth);
////设定服务器的分隔符
[DllImport("TLSvrRdk.dll", ExactSpelling=true, CharSet=CharSet.Ansi, SetLastError=true)]
public static extern byte TL_SetQualifier(byte cQualifier);
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?