📄 hfopcmodule.bas
字号:
Attribute VB_Name = "HFOPCModule"
Public Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type
Public Type SYSTEMTIME
wYear As Integer
wMonth As Integer
wDayOfWeek As Integer
wDay As Integer
wHour As Integer
wMinute As Integer
wSecond As Integer
wMilliseconds As Integer
End Type
Declare Function HF_Init Lib "OPCClient.dll" Alias "Init" () As Long
Declare Sub HF_Uninit Lib "OPCClient.dll" Alias "Uninit" ()
Declare Function HF_GetServerCount Lib "OPCClient.dll" Alias "GetServerCount" (ByRef MachineName As Byte, _
ByVal Ver2 As Long) As Long
Declare Function HF_GetServerName Lib "OPCClient.dll" Alias "GetServerName" (ByVal index As Integer, _
ByRef buf As Byte, _
ByVal BufSize As Integer) As Long
Declare Function HF_Connect Lib "OPCClient.dll" Alias "Connect" (ByRef MachineName As Byte, _
ByRef ServerName As Byte, _
ByVal Ver2 As Long) As Long
Declare Sub HF_Disconnect Lib "OPCClient.dll" Alias "Disconnect" (ByVal hConnect As Long)
Declare Function HF_AddGroup Lib "OPCClient.dll" Alias "AddGroup" (ByVal hConnect As Long, _
ByRef Name As Byte, _
ByVal bActive As Boolean, _
ByVal Rate As Long, _
ByRef TimeBias As Long, _
ByRef DeadBand As Single, _
ByVal LCID As Long) As Long
Declare Sub HF_RemoveGroup Lib "OPCClient.dll" Alias "RemoveGroup" (ByVal hConnect As Long, _
ByVal hGroup As Long)
Declare Function HF_GetItemCount Lib "OPCClient.dll" Alias "GetItemCount" (ByVal hConnect As Long) As Integer
Declare Function HF_GetItemName Lib "OPCClient.dll" Alias "GetItemName" (ByVal hConnect As Long, _
ByVal index As Integer, _
ByRef buf As Byte, _
ByVal BufSize As Integer) As Long
Declare Function HF_AddItem Lib "OPCClient.dll" Alias "AddItem" (ByVal hConnect As Long, _
ByVal hGroup As Long, _
ByRef ItemName As Byte) As Long
Declare Sub HF_RemoveItem Lib "OPCClient.dll" Alias "RemoveItem" (ByVal hConnect As Long, _
ByVal hGroup As Long, _
ByVal hItem As Long)
Declare Function HF_WriteItem Lib "OPCClient.dll" Alias "WriteItem" (ByVal hConnect As Long, _
ByVal hGroup As Long, _
ByVal hItem As Long, _
ByRef Value As Variant, _
ByVal DoAsync As Boolean) As Long
Declare Function HF_ReadItem Lib "OPCClient.dll" Alias "ReadItem" (ByVal hConnect As Long, _
ByVal hGroup As Long, _
ByVal hItem As Long, _
ByRef Value As Variant, _
ByRef TimeStamp As FILETIME, _
ByRef Quality As Long) As Long
Declare Function HF_SetDataChangeProc Lib "OPCClient.dll" Alias "SetDataChangeProc" (ByVal hConnect As Long, _
ByVal callback As Long, _
ByVal writecallback As Long) As Long
Declare Function HF_SetShutDownProc Lib "OPCClient.dll" Alias "SetShutDownProc" (ByVal hConnect As Long, _
ByVal callback As Long) As Long
Private Const rDayZeroBias As Double = 109205#
Private Const rMillisecondPerDay As Double = 10000000# * 60# * 60# * 24# / 10000#
Declare Function FileTimeToSystemTime Lib "kernel32" (lpFileTime As FILETIME, _
lpSystemTime As SYSTEMTIME) As Long
Declare Function FileTimeToLocalFileTime Lib "kernel32" (lpFileTime As FILETIME, _
lpLocalFileTime As FILETIME) As Long
Declare Function LocalFileTimeToFileTime Lib "kernel32" (lpLocalFileTime As Any, _
lpFileTime As Any) As Long
Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (hpvDest As Any, _
hpvSource As Any, _
ByVal cbCopy As Long)
Public Function Win32FileTimeToVB(hFileTime As FILETIME) As Date
Dim ftl As Currency, Ft As FILETIME
FileTimeToLocalFileTime hFileTime, Ft
CopyMemory ftl, Ft, Len(Ft)
Win32FileTimeToVB = CDate((ftl / rMillisecondPerDay) - rDayZeroBias)
End Function
Public Function VBToWin32FileTime(hDate As Date) As FILETIME
Dim hft As Currency
hft = (CCur(hDate) + rDayZeroBias) * rMillisecondPerDay
LocalFileTimeToFileTime hft, VBToWin32FileTime
End Function
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -