OPC client program (VB-synchronization)

Source: Internet
Author: User
Tags goto
Create the following form:

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 = "Add group"
Set GroupObj = ServerObj. OPCGroups. Add ("Group ")

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

On Error GoTo ErrorHandler
OutText = "read ITEM value"
ItemObj. Read OPCDevice, myValue, myQuality, myTimeStamp
Edit_ReadVal = myValue
Edit_ReadQu = GetQualityText (myQuality)
Edit_ReadTS = myTimeStamp

Exit Sub

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.