发表于:2006-04-01 15:26:00
楼主
前一段时间接触OPC,大概有了个了解 ,我所在的单位使用CS3000,软件包带有OPC SEVER
自己用vb写了客户端程序 ,能动态的读入OPC SEVER的数据 ,我把代码贴出来 。希望对大家有所启发。
Option Explicit
Const MaxTagItems = 2
Dim StationName As StringPrivate Sub Command1_Click()
Timer1.Enabled = True
End Sub
Private Sub Form_Load()
StationName = InputBox("PLEASE ENTER STATIONNAME:")
End Sub
Private Sub Timer1_Timer()
Dim TagItems(MaxTagItems) As String ' TagNames
Dim i As Integer ' Work
Dim Values As Variant ' Process value
' Set up item information
For i = 0 To MaxTagItems
TagItems(i) = Text1(i).Text
Next i
CENTUM1.StationName = StationName ' Get opc sever name
CENTUM1.GetTagQuality = False
CENTUM1.Transpose = False
Values = CENTUM1.GetTagData(TagItems)
' Show process data
For i = 0 To MaxTagItems
Label1(i).Caption = Values(i)
Next i
End Sub
其中加入TIMER1控件,并设其interval 是1000,能刷新数据。