[Python] OSError: exception: access violation reading 0x00000001

Discussão em 'Python' iniciado por Stack, Agosto 15, 2025.

  1. Stack

    Stack Membro Participativo

    I try to communicate with a HV-Supply through a c dll with python. The most simple Function i get to work. But if i call the more complex function CAENHVInitSystem i get an Error: OSError: exception: access violation reading 0x00000001. I am quite new to ctypes in Python. As far as i know, this error maybe shows because some of my arguments have a wrong type. But how i can debug it more to know exactly which argument is wrong? does anyone see my mistake?

    import os
    from ctypes import *

    bib = CDLL("CAENHVWrapper")

    ret = bib.CAENHVLibSwRel() # This call works
    print(c_char_p(ret))

    sysType = c_int(1) #SY2527
    link = c_int(0) #TCP/IP
    #arg = c_char_p(b'149.217.10.241') #i change it for test to c_void_p but later the arg should be the ip adress
    arg = c_void_p()
    user = c_char_p(b'admin')
    passwd = c_char_p(b'admin')
    sysHndl = c_int()

    # c function definition in the header file
    #CAENHVLIB_API CAENHVRESULT CAENHV_InitSystem(
    # CAENHV_SYSTEM_TYPE_t system,
    # int LinkType,
    # void *Arg,
    # const char *UserName,
    # const char *Passwd,
    # int *handle);

    # definition of the enum of the first argument
    #typedef enum {
    # SY1527 = 0,
    # SY2527 = 1
    #} CAENHV_SYSTEM_TYPE_t;

    bib.CAENHVInitSystem.argtypes = [c_int, c_int, c_void_p, c_char_p, c_char_p, POINTER(c_int)]
    ret = bib.CAENHVInitSystem(sysType, link, arg, user, passwd, byref(sysHndl))

    print(ret)
    print(bib.CAENHV_GetError(sysHndl))

    Continue reading...

Compartilhe esta Página