Python ctypes - Memory read Error when calling a function in a DLL

Edward Xu dwrdx5 at gmail.com
Thu Mar 22 23:23:55 EDT 2012


Hi all,
I'm writing a script to control a *PCMCIA* device, the driver provided by
the vendor is a dll file. I just want to call functions in it, but i just
don't know why I keep getting a *[**The instruction at "0x7c9108d3"
referenced memory at "0xfffffff8". The memory could not be "read"**]. *Here
is the documents say:

*//declaration*
*XLstatus xlGetDriverConfig(XLdriverConfig *pDriverConfig) *
*
*
*typedef struct s_xl_driver_config  { *
*    unsigned int      dllVersion; *
*    unsigned int      channelCount;  *
*    unsigned int      reserved[10]; *
*    XLchannelConfig   channel[XL_CONFIG_MAX_CHANNELS]; *
*} XLdriverConfig; *
*
*
*//types*
*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;      //here  *
*    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; *
*
*
*typedef unsigned __int64 XLuint64;*
*
*
*typedef struct {
              *
*  unsigned int busType;*
*  union {*
*    struct {*
*      unsigned int bitRate;*
*      unsigned char sjw;*
*      unsigned char tseg1;*
*      unsigned char tseg2;*
*      unsigned char sam;  // 1 or 3*
*      unsigned char outputMode;*
*    } can;*
*    struct {*
*      unsigned int  activeSpeedGrade;*
*      unsigned int  compatibleSpeedGrade;*
*    } most;*
*    unsigned char raw[32];*
*  }data;*
*} XLbusParams; *

There is my python script below:

*
from ctypes import *
vxlapi = WinDLL("vxlapi.dll")
PyxlGetDriverConfig = vxlapi.xlGetDriverConfig

class PyXLchannelConfig(Structure):
    _fields_ = [("Pyname",c_char*32),
                ("PyhwType",c_ubyte),
                ("PyhwIndex",c_ubyte),
                ("PyhwChannel",c_ubyte),
                ("PytransceiverType",c_ushort),
                ("PytransceiverState",c_ushort),
                ("PyconfigError",c_ushort),
                ("PychannelIndex",c_ubyte),
                ("PychannelMask",c_longlong),
                ("PychannelCapabilities",c_uint),
                ("PychannelBusCapabilities",c_uint),

                ("PyisOnBus",c_ubyte),
                ("PyconnectedBusType",c_uint),
                ("PybusParams",c_uint),

                ("PydriverVersion",c_uint),
                ("PyinterfaceVersion",c_uint),
                ("Pyraw_data",c_uint*10),

                ("PyserialNumber",c_uint),
                ("PyarticleNumber",c_uint),

                ("PytransceiverName",c_char*32),

                ("PyspecialCabFlags",c_uint),
                ("PydominantTimeout",c_uint),
                ("PydominantRecessiveDelay",c_ubyte),
                ("PyrecessiveDominantDelay",c_ubyte),
                ("PyconnectionInfo",c_ubyte),
                ("PycurrentlyAvailableTimestamps",c_ubyte),
                ("PyminimalSupplyVoltage",c_ubyte),
                ("PymaximalSupplyVoltage",c_ubyte),
                ("PymaximalBaudrate",c_uint),
                ("PyfpgaCoreCapabilities",c_ubyte),
                ("PyspecialDeviceStatus",c_ubyte),
                ("PychannelBusActiveCapabilities",c_ushort),
                ("PybreakOffset",c_ushort),
                ("PydelimiterOffset",c_ushort),
                ("Pyreserved",c_uint*3)
                ]

class PyXLdriverConfig(Structure):
    _fields_ = [("PydllVersion",c_uint),
                ("PychannelCount",c_uint),
                ("Pyreserved",c_uint*10),
                ("Pychannel",PyXLchannelConfig*64)
                ]

*
if __name__ == "__main__":
    drivercfg = PyXLdriverConfig()
    PyxlGetDriverConfig(byref(drivercfg))

Could you  help me out of this, Thank you very much!

-- 
Best Regards
Edward
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20120323/3f39be41/attachment.html>


More information about the Python-list mailing list