Libnodave und CP5512

dirknico

Level-2
Beiträge
218
Reaktionspunkte
14
Zuviel Werbung?
-> Hier kostenlos registrieren
Ich möchte aus Excel eine Kommunikation zu einer CPU315-2 DP über CP5512 aufbauen.

Das ganze scheitert allerdings schon am starten / stoppen der CPU.

Hab mich schon durch diverse Beiträge gelesen, komme aber nicht weiter.

Habe folgendes geändert:
Code:
Private Declare Function openS7online Lib "libnodave.dll" (ByVal peer As String, ByVal handle As Long) As Long
Code:
Sub stopPLC()
Cells(1, 2) = "Testing Start PLC"
Dim ph As Long, di As Long, dc As Long
res = initialize(ph, di, dc)
If res = 0 Then
    res2 = daveStop(dc)
    Cells(14, 1) = "result:"
    Cells(14, 2) = res2
Else
    e$ = daveStrError(res)
    Cells(9, 4) = "error:"
    Cells(9, 5) = e$
End If
Call cleanUp(ph, di, dc)
End Sub
Code:
Private Function initialize(ByRef ph As Long, ByRef di As Long, ByRef dc As Long)
ph = 0
di = 0
dc = 0
Rem uncomment the daveSetDebug... line, save your sheet
Rem run excel from dos box with: excel yoursheet >debugout.txt
Rem send me the file debugout.txt if you have trouble.
Rem call daveSetDebug(daveDebugAll)
initialize = -1
baud$ = Cells(3, 5)
If (baud$ = "") Then Call initTable
Cells(12, 2) = "Running"
res = -1
port = Cells(2, 5)
baud$ = Cells(3, 5)
parity$ = Cells(4, 5)
peer$ = Cells(7, 5)
acspnt$ = Cells(8, 5)
'ph = setPort(port, baud$, Asc(Left$(parity$, 1)))
' Alternatives:
Rem ph = openSocket(102, peer$)    ' for ISO over TCP
Rem ph = openSocket(1099, peer$)' for IBH NetLink
'ph = openS7online(acspnt$) ' to use Siemes libraries for transport (s7online)
ph = openS7online(acspnt$, res)
Cells(2, 1) = "port handle:"
Cells(2, 2) = ph
If (ph > 0) Then
    di = daveNewInterface(ph, ph, "IF1", 0, daveProtoMPI, daveSpeed187k)
' Alternatives:
'di = daveNewInterface(ph, ph, "IF1", 0, daveProtoPPI, daveSpeed187k)
'di = daveNewInterface(ph, ph, "IF1", 0, daveProtoMPI_IBH, daveSpeed187k)
'di = daveNewInterface(ph, ph, "IF1", 0, daveProtoISOTCP, daveSpeed187k)
'di = daveNewInterface(ph, ph, "IF1", 0, daveProtoS7online, daveSpeed187k)
'
'You can set longer timeout here, if you have  a slow connection
'    Call daveSetTimeout(di, 500000)
    res = daveInitAdapter(di)
    Cells(3, 1) = "result from initAdapter:"
    Cells(3, 2) = res
    If res = 0 Then
        MpiPpi = Cells(6, 5)
'
' with ISO over TCP, set correct values for rack and slot of the CPU
'
        dc = daveNewConnection(di, MpiPpi, Rack, Slot)
        res = daveConnectPLC(dc)
        Cells(4, 1) = "result from connectPLC:"
        Cells(4, 2) = res
        If res = 0 Then
            initialize = 0
        End If
    End If
End If
End Function
Wobei ich mir nicht wirklich sicher bin ob das hier so richtig ist:
Code:
ph = openS7online(acspnt$, res)
 
Mit excel habe ich das noch nicht gemacht, aber aus einem Delphi-Programm heraus hat das funktioniert. Du mußt dazu aber Step7 auf dem PC installiert haben, denn es wird mit der dort eingerichteten Schnittstelle gearbeitet. Dazu muß die PG-Schnittstelle im Step7 auf die CP5512 eingestellt werden.
 
Zurück
Oben