📄 opcserverclass.cls
字号:
ShowOPCLastUpdateTimeError:
Call DisplayOPC_COM_ErrorValue("LastUpdate", Err.Number)
GetLastUpdateTime = False
SkipOPCLastUpdateTimeError:
End Function
' Get the major version number of the connected server
'
Function GetMajorVersion(ByRef MajorVersion As Integer)
'Set error handling for OPC Function
On Error GoTo ShowOPCMajorVersionError
' Attempt to get the server MajorVersion.
MajorVersion = OPCServerObj.MajorVersion
GetMajorVersion = True
GoTo SkipOPCMajorVersionError
ShowOPCMajorVersionError:
Call DisplayOPC_COM_ErrorValue("MajorVersion", Err.Number)
GetMajorVersion = False
SkipOPCMajorVersionError:
End Function
' Get the minor version number of the connected server
'
Function GetMinorVersion(ByRef MinorVersion As Integer)
'Set error handling for OPC Function
On Error GoTo ShowOPCMinorVersionError
' Attempt to get the server MinorVersion.
MinorVersion = OPCServerObj.MinorVersion
GetMinorVersion = True
GoTo SkipOPCMinorVersionError
ShowOPCMinorVersionError:
Call DisplayOPC_COM_ErrorValue("MinorVersion", Err.Number)
GetMinorVersion = False
SkipOPCMinorVersionError:
End Function
' Get the build number of the connected server
'
Function GetBuildNumber(ByRef BuildNumber As Integer)
'Set error handling for OPC Function
On Error GoTo ShowOPCBuildNumberError
' Attempt to get the server BuildNumber.
BuildNumber = OPCServerObj.BuildNumber
GetBuildNumber = True
GoTo SkipOPCBuildNumberError
ShowOPCBuildNumberError:
Call DisplayOPC_COM_ErrorValue("BuildNumber", Err.Number)
GetBuildNumber = False
SkipOPCBuildNumberError:
End Function
' Get the Vendor Info of the connected server
' The vendor info will return a string describing the
' name of the vendor of the OPC server. In some cases this string
' will return the name of the OPC Server toolkit vendor if
' the connected OPC server uses a toolkit.
'
Function GetVendorInfo(ByRef VendorInfo As String)
'Set error handling for OPC Function
On Error GoTo ShowOPCVendorInfoError
' Attempt to get the server VendorInfo.
VendorInfo = OPCServerObj.VendorInfo
GetVendorInfo = True
GoTo SkipOPCVendorInfoError
ShowOPCVendorInfoError:
Call DisplayOPC_COM_ErrorValue("VendorInfo", Err.Number)
GetVendorInfo = False
SkipOPCVendorInfoError:
End Function
' Get the Server State property of the connected server
' The value retured will be one of the following
' OPC_STATUS_RUNNING - 1 - Server is running normally
' OPC_STATUS_FAILED - 2 - Vendor specific fatal error has occured
' OPC_STATUS_NOCONFIG - 3 - Server Running but no Configuration Data available
' OPC_STATUS_SUSPENDED - 4 - Server is suspended and not receiving data
' OPC_STATUS_TEST - 5 - Server in test mode
' OPC_STATUS_DISCONNECTED - 6 - Server has disconnected
'
Function GetServerState(ByRef ServerState As Long)
'Set error handling for OPC Function
On Error GoTo ShowOPCServerStateError
' Attempt to get the server ServerState.
ServerState = OPCServerObj.ServerState
GetServerState = True
GoTo SkipOPCServerStateError
ShowOPCServerStateError:
Call DisplayOPC_COM_ErrorValue("ServerState", Err.Number)
GetServerState = False
SkipOPCServerStateError:
End Function
' This function returns an OPC browse object from the server object
' held in this instance of the OPCServerClass. This function may return
' a true condition indicating that the function succeeded, however the
' the OPCBrowserObject may still be set to Nothing if the connected
' server does not support browsing. With that in mind check the
' returned object for "Nothing" before use.
Function GetServerBrowseObject(ByRef OPCBrowserObject As OPCBrowserClass)
'Set error handling for OPC Function
On Error GoTo ShowOPCBrowserError
Dim OPCBrowserObj As OPCBrowser
' Attempt to get the server browse object
Set OPCBrowserObj = OPCServerObj.CreateBrowser
If Not OPCBrowserObj Is Nothing Then
Set OPCBrowserObject = New OPCBrowserClass
OPCBrowserObject.SetBrowserObject OPCBrowserObj
Else
Set OPCBrowserObject = Nothing
End If
GetServerBrowseObject = True
GoTo SkipOPCBrowserError
ShowOPCBrowserError:
Call DisplayOPC_COM_ErrorValue("Browser Object", Err.Number)
GetServerBrowseObject = False
SkipOPCBrowserError:
End Function
' The next section of this module covers the management of OPC groups
' within the OPCServerClass object. When adding an OPC group the initial
' state of the groups atrributes must be set. A group has the following
' attributes, GroupName, Update Rate, DeadBand, and ActiveState. The
' actual ServerGroups.Add function only allows you to specify the group
' name when adding a new group. To set the attributes listed above you
' can use the Set Default functions that follow to establish the initial
' conditions for a new group.
' The SetDefaultGroupIsActive allows you to set the default active
' condition on the ServerGroups object determining the active
' state of a newly added group. Once a group is added you can change
' these attributes by using the functions found in the OPCGroupClass
' object. The active state of a group allows you to literally turn the
' data in this group on or off. For the OPC server this means that
' your application either needs the data in the group(On/Active) or
' it doesn't(Off/Inactive). Using the active state of the group
' your VB application can tailor how much data the OPC server is trying
' read from your devices. By turing a group off that you don't
' currently need you can reduce the amount of data the OPC server is
' reading from a device. This of course has the benefit of increasing
' the performance of the OPC server for the data items that you do still
' need to acquire. I recommend using the active state of the group or
' of the item(shown later), instead of continuously adding and removing
' items from a group as a means of controlling what data the OPC server
' is gathering from the devices.
'
Function SetDefaultGroupIsActive(ByVal State As Boolean)
'Set error handling for OPC Function
On Error GoTo ShowOPCDefaultGroupIsActiveError
ServerGroups.DefaultGroupIsActive = State
SetDefaultGroupIsActive = True
GoTo SkipOPCDefaultGroupIsActiveError
ShowOPCDefaultGroupIsActiveError:
Call DisplayOPC_COM_ErrorValue("DefaultGroupIsActive", Err.Number)
SetDefaultGroupIsActive = False
SkipOPCDefaultGroupIsActiveError:
End Function
' The SetDefaultGroupUpdateRate allows you to set the default UpdateRate
' condition on the ServerGroups object determining the Update Rate
' of a newly added group. Once a group is added you can change
' these attributes by using the functions found in the OPCGroupClass
' object. The update rate is entered in milliseconds. The range is
' 0 to 2147483647 milliseconds which is about 596 hours. Entering
' value of 0 tells the OPC server you want it to acquire data in this
' group as fast as possible. The update rate on a group is very
' powerful tool for optimizing your application's communications.
' If you set every group you add to a server to an update interval of
' 0 the server will attempt to gather all of your data as quickly as
' possible. If all of your data requires the best possible update
' speed then this is probably OK. But what if some of your data doesn't
' really change but once every 10 minutes or so. To read this as fast
' as possible would waste a considerable amount of the communications
' bandwidth of your OPC server. Since the OPC server allows you to add
' multiple groups to the server you can separate your data into separate
' groups, with each group having its own update rate. In this way fast
' data can be gathered quickly and slow data can be gathered slowly.
'
Function SetDefaultGroupUpdateRate(ByVal Rate As Long)
'Set error handling for OPC Function
On Error GoTo ShowOPCDefaultUpdateRateError
ServerGroups.DefaultGroupUpdateRate = Rate
SetDefaultGroupUpdateRate = True
GoTo SkipOPCDefaultUpdateRateError
ShowOPCDefaultUpdateRateError:
Call DisplayOPC_COM_ErrorValue("SetDefaultGroupUpdateRate", Err.Number)
SetDefaultGroupUpdateRate = False
SkipOPCDefaultUpdateRateError:
End Function
' The SetDefaultGroupDeadBand allows you to set the default Deadband
' condition on the ServerGroups object determining the DeadBand
' of a newly added group. Once a group is added you can change
' these attributes by using the functions found in the OPCGroupClass
' object. Deadband is an interesting feature of the an OPC server.
' Deadband allows you to limit the amount of data changes the OPC
' will return for items in this group. It does this by establishing the
' ratio of change that must occur in a given item before the OPC server
' will pass the changed value back to the connected OPC client.
' The Deadband ranges from 0 to 100 percent. The actual percentage of
' effect that the deadband has upon changing data depends of the
' data tpye of the OPC item. If the data type of the OPC item is a BYTE
' which has a range of 0 to 255 a deadband value of 1 percent would
' require that the value contained in this BYTE item must change by
' atleast 2.5 before the OPC server will inform the OPC client of the
' change. Unlike the the Active state and Update Rate of a group the
' Deadband feature will not optimize the communications bandwidth of the
' OPC server. Deadband is more likely to be used to prevent an
' application like a data logger from logging every little change in
' value due to a noisy enviroment as an example.
'
Function SetDefaultGroupDeadBand(ByVal DeadBand As Single)
'Set error handling for OPC Function
On Error GoTo ShowOPCDefaultGroupDeadBandError
ServerGroups.DefaultGroupDeadband = DeadBand
SetDefaultGroupDeadBand = True
GoTo SkipOPCDefaultGroupDeadBandError
ShowOPCDefaultGroupDeadBandError:
Call DisplayOPC_COM_ErrorValue("SetDefaultGroupDeadBand", Err.Number)
SetDefaultGroupDeadBand = False
SkipOPCDefaultGroupDeadBandError:
End Function
' The name say it all, gets the default active state from the
' ServerGroups collection object.
'
Function GetDefaultGroupIsActive(ByRef State As Boolean)
'Set error handling for OPC Function
On Error GoTo ShowOPCGetDefaultGroupIsActiveError
State = ServerGroups.DefaultGroupIsActive
GetDefaultGroupIsActive = True
GoTo SkipOPCGetDefaultGroupIsActiveError
ShowOPCGetDefaultGroupIsActiveError:
Call DisplayOPC_COM_ErrorValue("GetDefaultGroupIsActive", Err.Number)
GetDefaultGroupIsActive = False
SkipOPCGetDefaultGroupIsActiveError:
End Function
' The name say it all, gets the default UpdateRate from the
' ServerGroups collection object.
'
Function GetDefaultGroupUpdateRate(ByRef Rate As Long)
'Set error handling for OPC Function
On Error GoTo ShowOPCGetDefaultUpdateRateError
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -