ich hab mal eine Verständnisfrage zu ctypes und einbinden von DLLs in Python.
In der Doku zu der verwendeten DLL (XL Driver Library http://www.vector-worldwide.com/vi_xl_d ... ,2816.html) steht folgendes:
Wenn ich die Funktion der DLL richtig verstanden hab, dann bildet mir die DLL dieses struct automatisch.C SyntaxDescriptionXLstatus xlGetDriverConfig(XLdriverConfig *pDriverConfig)Input ParametersAllows reading out more detailed information about the used hardware. This function can be called at any time after a successfully xlOpenDriver. After each call the result describes the current state of the driver configuration.Return ValueXLdriverConfig
Points to a user buffer for the information, which the driver returns. See details below for further information.XLdriverConfigReturns an error code.
The driver returns the following structure containing the information:
SyntaxXLchannelConfigCode: Alles auswählen
typedef struct s_xl_driver_config { unsigned int dllVersion; unsigned int channelCount; unsigned int reserved[10]; XLchannelConfig channel[XL_CONFIG_MAX_CHANNELS]; } XLdriverConfig;
The following sub structure is used in structure XLdriverConfig (above-mentioned).usw....Code: Alles auswählen
typedef struct s_xl_channel_config { char name [XL_MAX_LENGTH + 1]; unsigned char hwType; unsigned char hwIndex; unsigned char hwChannel; unsigned short transceiverType; unsigned int transceiverState; unsigned char channelIndex; XLuint64 channelMask; unsigned int channelCapabilities; unsigned int channelBusCapabilities; unsigned char isOnBus; unsigned int connectedBusType; XLbusParams busParams; unsigned int driverVersion; unsigned int interfaceVersion; unsigned int raw_data[10]; unsigned int serialNumber; unsigned int articleNumber; char transceiverName [XL_MAX_LENGTH + 1]; unsigned int specialCabFlags; unsigned int dominantTimeout; unsigned int reserved[8]; } XLchannelConfig;
Was muss ich an die Funktion von Python aus übergeben damit ich dieses struct und die Werte zurückbekomme?
Oder muss ich eine class die dieses struct enthält erstellen und diese dann übergeben. Dann wäre die Frage wie erstelle ich die geforderten "sub structure" und übergebe das ganze dann an die DLL.
Code: Alles auswählen
from ctypes import *
class test_struct(Structure):
_fields_ = [
("dllVersion", POINTER(c_uint)),
("channelCount", c_uint),
("reserved[10]", c_uint),
("channel", c_void_p) #Hier sollte die Substructure sein
]
dll = windll.LoadLibrary("vxlapi.dll")
# Treiber laden
XLstatus = dll.xlOpenDriver()
print c_char_p(dll.xlGetErrorString(c_int(XLstatus))).value
# Channel Index
xlChannelIndex = c_int(dll.xlGetChannelIndex(c_int(15), c_int(-1), c_int(-1))).value
# Treiber Konfig
XLstatus = dll.xlGetDriverConfig() # Diese Funktion braucht das Struct oder evtl. einen Pointer
# Treiber schliessen
XLstatus = dll.xlCloseDriver()
print c_char_p(dll.xlGetErrorString(c_int(XLstatus))).value
Gruß
Damaskus