Reference:
The code is as follows:
Option Explicit
Dim WithEvents ServerObj As OPCServer
Dim WithEvents GroupObj As OPCGroup
Dim ItemObj As OPCItem
Private Sub Command_Start_Click ()
Dim OutText As String
On Error GoTo ErrorHandler
Command_Start.Enabled = False
Command_Read.Enabled = True
Command_Write.Enabled = True
Command_Exit.Enabled = True
OutText = "connecting to OPC Server"
Set ServerObj = New OPCServer
ServerObj. Connect ("XXXSERVER") 'xxxserver is the name of an OPC Server.
OutText = "Adding an Item to the group"
Set ItemObj = GroupObj. OPCItems. AddItem ("XXXITEM", 1) 'xxxitem is the name of the added ITEM
Exit Sub
ErrorHandler: 'if an exception occurs, an error is returned.
MsgBox Err. Description + Chr (13) + _
OutText, vbCritical, "ERROR"
End Sub
Private Sub Command_Read_Click () 'synchronous read
Dim OutText As String
Dim myValue As Variant
Dim myQuality As Variant
Dim myTimeStamp As Variant
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.