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
Rem ph = openS7online(acspnt$) ' to use Siemes libraries for transport (s7online)
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