opc client for php,使用vb/vba作为OPC client

使用vba/vb做client可以使opc的访问变得简单,以下是基于excel的简单opc client代码:

Option Explicit Public WithEvents MyOPCSvr As OPCAutomation.OPCServer Public WithEvents MyOPCGroup As OPCAutomation.OPCGroup Private Sub CommandButton1_Click() On Error GoTo error ' 利用OPC自动化接口连接;建立组;加入/读写项 Set MyOPCSvr = New OPCServer MyOPCSvr.Connect Me.TextBox1.Text Set MyOPCGroup = MyOPCSvr.OPCGroups.Add("testMyOPCGroup") Dim item As OPCItem Set item = MyOPCGroup.OPCItems.AddItem("_system" + Chr(26) + "Now", 1000) MyOPCGroup.IsSubscribed = True 'item.Read (OPCCache) 'item.Write (12345) 'MsgBox item.Value Exit Sub error: MsgBox Err.Description CommandButton2_Click End Sub Private Sub CommandButton2_Click() ' 断开连接 If Not MyOPCSvr Is Nothing Then MyOPCSvr.Disconnect Set MyOPCSvr = Nothing End If End Sub Private Sub MyOPCGroup_DataChange(ByVal TransactionID As Long, ByVal NumItems As Long, ClientHandles() As Long, ItemValues() As Variant, Qualities() As Long, TimeStamps() As Date) ' 数值改变时。。。 Worksheets("Sheet1").Range("A1").Value = ItemValues(1) End Sub Private Sub MyOPCSvr_ServerShutDown(ByVal Reason As String) ' 服务器断开 MsgBox Reason End Sub

图:

o_untitled.JPG

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值