Python code for libnodave

Python in C/C++ embedden, C-Module, ctypes, Cython, SWIG, SIP etc sind hier richtig.
Antworten
jakubokaj
User
Beiträge: 1
Registriert: Montag 18. Juli 2011, 15:41

I have a problem with Python script for libnodave.
Currently I try to find a problem but I'm nor sure if script code is ok?

Here is my code:

Code: Alles auswählen

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)]

print "start skryptu"
#APPDIR = os.path.dirname(os.path.abspath(__file__))
#DLL_LOC = os.path.join(APPDIR, 'libnodave', 'win', 'libnodave.dll')

libnodave = ctypes.windll.LoadLibrary("libnodave.dll")
fds = daveOSserialType()
fds.rdf = libnodave.openSocket(102,'192.168.208.131')
fds.wdf = fds.rdf

if(fds.rfd >= 0):
 
	
        di = libnodave.daveNewInterface(fds, ctypes.c_char_p('IF1'), 0 ,daveProtoISOTCP ,daveSpeed187k)
        libnodave.daveSetTimeout(di, 5000000)
        res = libnodave.daveInitAdapter(di)
        print "InitAdapter: " + str(res)

        dc = libnodave.daveNewConnection(di,0,0,2)
        res = libnodave.daveConnectPLC(dc)
        print "ConnectPLC: " + str(res)

        buf = ctypes.create_string_buffer(100)
        res = libnodave.daveReadBytes(dc,daveBlockType_DB,1,0,2,buf)
        print "ReadBytes: " + str(res)


Can you tell me if somethink looks bad?
Zuletzt geändert von Anonymous am Montag 18. Juli 2011, 16:27, insgesamt 1-mal geändert.
Grund: Quelltext in Python-Code-Tags gesetzt.
Antworten