最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
OPC客户程序(VB篇――同步)
时间:2022-07-02 11:16:08 编辑:袖梨 来源:一聚教程网
建立如下窗体:
引用如下:
代码如下:
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 = "连接OPC服务器"
Set ServerObj = New OPCServer
ServerObj.Connect ("XXXSERVER")'XXXSERVER为某OPC服务器名称
OutText = "添加组"
Set GroupObj = ServerObj.OPCGroups.Add("Group")
OutText = "Adding an Item to the group"
Set ItemObj = GroupObj.OPCItems.AddItem("XXXITEM", 1)'XXXITEM为添加的ITEM名称
Exit Sub
ErrorHandler: '如果出现异常,则报出错误。
MsgBox Err.Description + Chr(13) + _
OutText, vbCritical, "ERROR"
End Sub
Private Sub Command_Read_Click()'同步读
Dim OutText As String
Dim myValue As Variant
Dim myQuality As Variant
Dim myTimeStamp As Variant
On Error GoTo ErrorHandler
OutText = "读ITEM值"
ItemObj.Read OPCDevice, myValue, myQuality, myTimeStamp
Edit_ReadVal = myValue
Edit_ReadQu = GetQualityText(myQuality)
Edit_ReadTS = myTimeStamp
Exit Sub
引用如下:
代码如下:
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 = "连接OPC服务器"
Set ServerObj = New OPCServer
ServerObj.Connect ("XXXSERVER")'XXXSERVER为某OPC服务器名称
OutText = "添加组"
Set GroupObj = ServerObj.OPCGroups.Add("Group")
OutText = "Adding an Item to the group"
Set ItemObj = GroupObj.OPCItems.AddItem("XXXITEM", 1)'XXXITEM为添加的ITEM名称
Exit Sub
ErrorHandler: '如果出现异常,则报出错误。
MsgBox Err.Description + Chr(13) + _
OutText, vbCritical, "ERROR"
End Sub
Private Sub Command_Read_Click()'同步读
Dim OutText As String
Dim myValue As Variant
Dim myQuality As Variant
Dim myTimeStamp As Variant
On Error GoTo ErrorHandler
OutText = "读ITEM值"
ItemObj.Read OPCDevice, myValue, myQuality, myTimeStamp
Edit_ReadVal = myValue
Edit_ReadQu = GetQualityText(myQuality)
Edit_ReadTS = myTimeStamp
Exit Sub
相关文章
- 《无限暖暖》围巾蚯蚓具体作用介绍 12-24
- 《无限暖暖》星夜守望连衣裙获得方法介绍 12-24
- 《无限暖暖》魔物试炼幻境解锁方法介绍 12-24
- 《无限暖暖》磐岩晶石获得方法介绍 12-24
- 《无限暖暖》巨石岩仔打法攻略分享 12-24
- 《无限暖暖》布布果在哪 12-24