1、1,ExcelOPCReadBlockTmStmp,EXCEL通过opc服务器读取数据,以及采集时间' Excel VBA Example Code: Read multiple data elements and display Timestamp using OPC'Dim OPCServer1 As OPCServer 'Dimension OPC Server andDim WithEvents OPCGroup1 As OPCGroup 'Group objectsPrivate Sub cmdDisconnect_Click()
2、 'Terminate OPC Group communications On Error Resume Next 'and connection to OPC Server Set OPCGroup1 = Nothing ' OPCServer1.Disconnect '- Ignore errors if OPC Server or Set OPCServer1 = Nothing ' Group does not existEn
3、d Sub 'Private Sub cmdRead_Click() If OPCServer1 Is Nothing Then 'OPC Server object doesn't exist Set OPCServer1 = New OPCServer '-Create new OPC Server object OPCServer1.Connect "RSLin
4、x OPC Server" '-Connect to OPC Server Set OPCGroup1 = OPCServer1.OPCGroups.Add("MyOPCData") '-Create OPC Group OPCGroup1.OPCItems.AddItem "[SLC]T4:0.ACC,L3", 1 '-Add item to OPC Group 'OPCGroup1.OPCItems.AddItem "[Topic]Item", ClientHandle
5、 OPCGroup1.IsSubscribed = True '-Subscribe to OPC Group End IfEnd SubPrivate Sub OPCGroup1_DataChange(ByVal TransactionID As Long, ByVal NumItems As Long, ClientHandles() As Long, ItemValues() As Variant, Qualities() As Long, TimeStamps() As Date) [A1] =
6、 ItemValues(1)(0) 'When data changes and is sent to application [A2] = ItemValues(1)(1) 'populate each data element into a separate [A3] = ItemValues(1)(2) 'worksheet cell [B1] = TimeStamps(1) ' ' For x = 1 To NumItems
7、 'A better method of handling incoming data using' Select Case ClientHandles(x) 'the ClientHandle assigned in the AddItem method' Case 1 '' [A1] = ItemValues(x)(0) 'Do this when ClientHandle = 1'