Public Class S7ConClass
Private fds As libnodave.daveOSserialType
Private di As libnodave.daveInterface
Private dc As libnodave.daveConnection
Private res As Integer
Private buf(100) As Byte
Private localMPI As Integer = 0
Private rack As Integer = 0
Public slot As Integer = 1
Private plcMPI As Integer = 2
Public IP As String = "0.0.0.0"
Public Connection As Boolean = False
Public ConnectionStatus As String = "Disconnected"
Public Sub Connect()
fds.rfd = libnodave.openSocket(102, IP)
fds.wfd = fds.rfd
If fds.rfd = 0 Then
MsgBox("IP adress not reachable", MsgBoxStyle.Information, "Error")
ConnectionStatus = "Disconnected"
Connection = False
End If
If fds.rfd > 0 Then ' if step 1 is ok
di = New libnodave.daveInterface(fds, "IF1",
0, libnodave.daveProtoISOTCP,
libnodave.daveSpeed187k)
di.setTimeout(1000000)
res = di.initAdapter
If res = 0 Then ' init Adapter is ok
' rack amd slot don't matter in case of MPI
dc = New libnodave.daveConnection(di, 0,
rack, slot)
res = dc.connectPLC()
If res = 0 Then
Connection = True
ConnectionStatus = "Connected to " + IP
End If
End If
End If
End Sub