标签顺序号DimOneReadAsStringDimXieAsStringSetOne=MyOPCGroup.OPCItems(Index)One.acheOneRead=One.Value ‘读数据MyOPCGroup.SyncWriteItemCount,ServerHandles,valuess,Errors ‘同步写数据MyOPCGroup.ache,ItemCount,ServerHandles,ReadValue,Errors ‘同步读数据One.Write(Xie) ‘写数据 若只读取数据,可以使用DataChange事件,当控制器中所要访问的数据一旦发生改变时将会触发该事件,并将该数据自动读到TxtValue文本框。PrivateSubMyOPCGroup_DataChange(ByValTransactionIDAsLong,ByValNumItemsAsLong,ClientHandles()AsLong,ItemValues()AsVariant,Qualities()AsLong,TimeStamps()AsDate) ‘自动刷新数据DimiAsLongFori=1ToNumItemstxtValue(ClientHandles(i))=ItemValues(i) ‘获取项的值txtTime(ClientHandles(i))=TimeStamps(i) ‘获取项的时间戳txtQuantity(ClientHandles(i))=GetQualityString(Qualities(i)) ‘获取项的品质NextiEndSub (5)断开OPC服务器MyOPCServer.OPCGroups.RemoveAll ‘移除所有OPCGroup,空出资源SetMyOPCGroup=NothingMyOPCServer.Disconnect ‘断开连接