megimoo - 2012-04-30

I'm currently struggling to make libnodave work with my S7-1200 plc over ethernet. The testISO_TCP.exe makes a connection and gets some info out of it, but I cannot for the life of me reproduce this. Every setting I try I get a -1 from libnodave.daveConnectPLC(dc).

My code:

debugEnable = True
def debug(string):
    if(debugEnable):
        print string
import ctypes
import os
daveProtoPPI  = 10    # PPI for S7 200 
daveProtoAS511 = 20    # S5 programming port protocol 
daveProtoS7online = 50    # use s7onlinx.dll for transport 
daveProtoISOTCP = 122    # ISO over TCP */
daveProtoISOTCP243 = 123 # ISO over TCP with CP243 */
daveProtoISOTCPR = 124   # ISO over TCP with Routing */
daveSpeed9k = 0
daveSpeed19k = 1
daveSpeed187k = 2
daveSpeed500k = 3
daveSpeed1500k = 4
daveSpeed45k = 5
daveSpeed93k = 6
daveBlockType_OB = '8'
daveBlockType_DB = 'A'
daveBlockType_SDB = 'B'
daveBlockType_FC = 'C'
daveBlockType_SFC = 'D'
daveBlockType_FB = 'E'
daveBlockType_SFB = 'F'
class daveOSserialType(ctypes.Structure):
    _fields_ = [("rfd", ctypes.c_int),
                ("wfd", ctypes.c_int)]
debug("Starter script")
debug("Laster inn dll")
libnodave = ctypes.windll.LoadLibrary("libnodave_jfkmod.dll")
fds = daveOSserialType()
debug("Prover a koble til")
fds.rdf = libnodave.openSocket(102,'192.168.0.1')
fds.wdf = fds.rdf
if(fds.rfd >= 0):

        di = libnodave.daveNewInterface(fds, 'IF1', 0 ,daveProtoISOTCP ,daveSpeed187k)
        libnodave.daveSetTimeout(di, 500000000)
        res = libnodave.daveInitAdapter(di)
        debug ("InitAdapter: " + str(res))
     
        dc = libnodave.daveNewConnection(di,2,10,0)
        res = libnodave.daveConnectPLC(dc)
        debug( "ConnectPLC: " + str(res))

I've been reading up on it for the last 8 hours and I still have no idea what causes the error.