Небольшая программка считывает таг из OPC сервера. Имеет референс на OPCDAauto.dll.
Помогите, плиз, перегнать на C#.
Пробовал программку-конвертер VBto - генерирует кучу ошибок.
Собственно, код:
- Код: Выделить всё
Option Explicit ' every variable has to be declared
Option Base 1 ' every Array starts on Index 1
Private MyOPCServer As OPCServer
Private WithEvents MyOPCGroup As OPCGroup
Private MyOPCItems() As OPCItem
Private Sub btnConnect_Click()
Dim i As Integer
Set MyOPCServer = New OPCServer
'connect the OPC Server
Call MyOPCServer.Connect(txtOPCServerName.Text)
'add one OPC Group
Set MyOPCGroup = MyOPCServer.OPCGroups.Add("Gruppe1")
'apply for DataChange
MyOPCGroup.IsSubscribed = True
MyOPCGroup.UpdateRate = 500
'add Items
ReDim MyOPCItems(1) 'kolichestvo tagov
Set MyOPCItems(1) = MyOPCGroup.OPCItems.AddItem(txtTagName1.Text, 1)
End Sub
Private Sub btnDisconnect_Click()
'disconnect the OPC Server
Call MyOPCServer.Disconnect
Set MyOPCServer = Nothing
End Sub
Private Sub btnRead_Click()
' Dim SHandles(2) As Long 'parameter value
Dim SHandles(1) As Long 'parameter value
Dim Values() As Variant 'return value
Dim Errors() As Long 'return value
Dim Qual As Variant 'return value
Dim TS As Variant 'return value
Dim i As Integer
'save ServerHandles
SHandles(1) = MyOPCItems(1).ServerHandle
Call MyOPCGroup.SyncRead(OPCCache, 1, SHandles, Values, Errors, Qual, TS)
'fill with the read values
txtValue = Values(1) 'column "read"
txtQuality = Qual(1) 'column "quality"
txtTimeStamp = TS(1) 'column "timestamp"
End Sub
Private Sub btnWrite_Click()
Dim SHandles(1) As Long 'parameter value
Dim Values(1) As Variant 'parameter value
Dim Errors() As Long 'return value
Dim i As Integer
'save ServerHandles
SHandles(1) = MyOPCItems(1).ServerHandle
'find out the values which are written into the following cells (line 11+12, column F)
'this values should be writen into PLC
Values(1) = Val(txtWrite.Text)
Call MyOPCGroup.SyncWrite(1, SHandles, Values, Errors)
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)
Dim i As Integer
txtValue.Text = ItemValues(1)
End Sub
Спасибо.