LibNoDave S7Online Fehlermeldung

koch-nix

Level-1
Beiträge
1
Reaktionspunkte
0
Zuviel Werbung?
-> Hier kostenlos registrieren
Hallo ich bin neu im Forum,
ich habe gerade begonnen mit LibNoDave und VB 2008 zu arbeiten, also absoluter Neuling in allem.

Ich habe ein Problem bei der S7Online Verbindung und zwar kommt bei mir in der Zeile fds.rfd = libnodave.openS7online("S7online") immer die Meldung "AccessViolationException was unhandled" Es wurde versucht im geschützten Speicher zu lesen oder zu schreiben....

mein Programmcode sieht so aus:

Dim localMPI As Integer = 0, plcMPI As Integer = 2
Dim fds As libnodave.daveOSserialType
Dim di As libnodave.daveInterface
Dim dc As libnodave.daveConnection
Dim res As Integer = 1
Dim Pfad As String = My.Application.Info.DirectoryPath

Private Declare Function daveGetU8from Lib "libnodave.dll" (ByRef buf As Byte) As Byte
Private Declare Function daveGetS8from Lib "libnodave.dll" (ByRef buf As Byte) As Short
Private Declare Function daveGetS16from Lib "libnodave.dll" (ByRef buf As Byte) As Short
Private Declare Function daveGetS32from Lib "libnodave.dll" (ByRef buf As Byte) As Integer
Private Declare Function daveGetFloatfrom Lib "libnodave.dll" (ByRef buf As Byte) As Single

Private Function PLCConnect(ByVal MPIAddress As String, Optional ByVal PLCRack As Integer = 0, Optional ByVal PLCSlot As Integer = 2) As Boolean
Dim ConnectionOpened As Boolean
Dim initSuccess As Integer = 0
Dim i As Integer

For i = 0 To 3
fds.rfd = libnodave.openS7online("S7online")
fds.wfd = fds.rfd
If fds.rfd > 0 Then
Exit For
End If
Next
If (fds.rfd > 0) Then
di = New libnodave.daveInterface(fds, "IF1", 0, libnodave.daveProtoS7online, libnodave.daveSpeed1500k)
di.setTimeout(1000)
Dim j As Integer
For j = 0 To 2
If (0 = di.initAdapter) Then
initSuccess = 1
Exit For
Else
di.disconnectAdapter()
End If
Next
If initSuccess <> 1 Then
MsgBox("Couldn't connect to Adapter!")
Exit Function
End If
dc = New libnodave.daveConnection(di, MPIAddress, PLCRack, PLCSlot)
Dim ErrorCode As Integer = dc.connectPLC()
If ErrorCode = 0 Then
MsgBox("Connection opened.")
ConnectionOpened = True
Else
MsgBox("Error opening connection. Check rack & slot." & " = " & libnodave.daveStrerror(ErrorCode))
ConnectionOpened = False
End If
Else
MsgBox("Error opening access point.")
ConnectionOpened = False
End If
Return ConnectionOpened
End Function

Ich hoffe, dass ich im Forum alles richtig gemacht habe.
Vielen Dank

koch-nix
 
Hallo,

versuch mal:
Code:
[SIZE=2]fds.rfd = openS7online([COLOR=#800000][COLOR=#800000]"S7online"[/COLOR][/COLOR], [COLOR=#0000ff][COLOR=#0000ff]Me[/COLOR][/COLOR].Handle)[/SIZE]


Gruß
Earny
 
Zuviel Werbung?
-> Hier kostenlos registrieren
Hallo ich bin neu im Forum,
ich habe gerade begonnen mit LibNoDave und VB 2008 zu arbeiten, also absoluter Neuling in allem.

Ich habe ein Problem bei der S7Online Verbindung und zwar kommt bei mir in der Zeile fds.rfd = libnodave.openS7online("S7online") immer die Meldung "AccessViolationException was unhandled" Es wurde versucht im geschützten Speicher zu lesen oder zu schreiben....

mein Programmcode sieht so aus:

Dim localMPI As Integer = 0, plcMPI As Integer = 2
Dim fds As libnodave.daveOSserialType
Dim di As libnodave.daveInterface
Dim dc As libnodave.daveConnection
Dim res As Integer = 1
Dim Pfad As String = My.Application.Info.DirectoryPath

Private Declare Function daveGetU8from Lib "libnodave.dll" (ByRef buf As Byte) As Byte
Private Declare Function daveGetS8from Lib "libnodave.dll" (ByRef buf As Byte) As Short
Private Declare Function daveGetS16from Lib "libnodave.dll" (ByRef buf As Byte) As Short
Private Declare Function daveGetS32from Lib "libnodave.dll" (ByRef buf As Byte) As Integer
Private Declare Function daveGetFloatfrom Lib "libnodave.dll" (ByRef buf As Byte) As Single

Private Function PLCConnect(ByVal MPIAddress As String, Optional ByVal PLCRack As Integer = 0, Optional ByVal PLCSlot As Integer = 2) As Boolean
Dim ConnectionOpened As Boolean
Dim initSuccess As Integer = 0
Dim i As Integer

For i = 0 To 3
fds.rfd = libnodave.openS7online("S7online")
fds.wfd = fds.rfd
If fds.rfd > 0 Then
Exit For
End If
Next
If (fds.rfd > 0) Then
di = New libnodave.daveInterface(fds, "IF1", 0, libnodave.daveProtoS7online, libnodave.daveSpeed1500k)
di.setTimeout(1000)
Dim j As Integer
For j = 0 To 2
If (0 = di.initAdapter) Then
initSuccess = 1
Exit For
Else
di.disconnectAdapter()
End If
Next
If initSuccess <> 1 Then
MsgBox("Couldn't connect to Adapter!")
Exit Function
End If
dc = New libnodave.daveConnection(di, MPIAddress, PLCRack, PLCSlot)
Dim ErrorCode As Integer = dc.connectPLC()
If ErrorCode = 0 Then
MsgBox("Connection opened.")
ConnectionOpened = True
Else
MsgBox("Error opening connection. Check rack & slot." & " = " & libnodave.daveStrerror(ErrorCode))
ConnectionOpened = False
End If
Else
MsgBox("Error opening access point.")
ConnectionOpened = False
End If
Return ConnectionOpened
End Function

Ich hoffe, dass ich im Forum alles richtig gemacht habe.
Vielen Dank

koch-nix

Und Ich würde das ganze auch nicht in einer Schleife machen, sonst bekommst du die hier beschriebenen Probleme: http://www.sps-forum.de/showthread.php?t=35831 . Und bei OpenS7Online ist auch 0 ein gültiger Wert!.

Kannst aber auch noch meine COnnection Library anschauen, da hab Ich die ganzen Funktionen gekappselt! http://jochensserver.dyndns.org/wordpress/?page_id=55
 
Zurück
Oben