文档详情

VB+OPC代码.doc

发布:2017-12-10约5.44千字共4页下载文档
文本预览下载声明
OPC的VB例子 Option Explicit Option Base 1 Private QOpcServer As OPCServer Private QGroups As OPCGroups Private WithEvents QGroup As OPCGroup Private QItems As OPCItems Private QItemServerHandles() As Long Private Sub Form_Load() On Error GoTo ErrorHandler ????建立与OPC服务器的连接 ????Set QOpcServer = New OPCServer ????Call QOpcServer.Connect(S7200.OPCServer) S7200.OPCServer是固定的OPC名称 ???? ????建立一个数据群组 ????Set QGroups = QOpcServer.OPCGroups???????? Get OPCGroups Collection Object from QOPCServer ???? Set Default Properties for Group Collection ???? These Properties are used to set the Properies for new Groups ????QGroups.DefaultGroupIsActive = 500?? Set Default Group Update Rate to 500 ms ????QGroups.DefaultGroupIsActive = False Set Default Group Active State to Inactive ????Set QGroup = QGroups.Add(QGroup1)?? Add a new Group to the Group Collection ???? Set Group Properties ????QGroup.IsSubscribed = True?? Enable Callbacks ????QGroup.UpdateRate = 100???? 这个群组的刷新速度是100ms ???? ????往群组里添加要传送的地址单元 ????Dim i As Long ????Dim ErrorFlag As Boolean ????Dim ItemObj As OPCItem ????Dim ItemIDs(2) As String ????Dim ItemClientHandles(2) As Long ????Dim Errors() As Long???????????? Array for returned Item related errors ????ErrorFlag = False ????Set QItems = QGroup.OPCItems?????????? Get OPCItems Collection Object from QOPCServer ???? Initialize the [IN] parameters for the Add Items call ???? ItemIDs - ItemIDs of the Items to add ???? ItemClientHandles - Client defined handles for the Items. The Server sends these handles in the Callbacks ????ItemIDs(1) = 2,q1.0,bool?? Read ItemId 1 from Text Box ????ItemIDs(2) = 2,VW10,Word?? Read ItemId 2 from Text Box ????ItemClientHandles(1) = 1 ????ItemClientHandles(2) = 2 ???? [OUT] parameters are ???? ItemServerHandles - Server defined handles for the Items. The client must use these handles for all Read/Write calls ???? Errors - Item related errors ???? Add Items to the Group ????Call QItems.AddItems(2, ItemIDs, ItemClientHandles, QItemServer
显示全部
相似文档