首页 > 解决方案 > Python ctypes 访问冲突读取

问题描述

我正在尝试通过带有 python 的 DLL 与设备通信,但我收到“OSError:异常:访问冲突读取 0x00000000”。我已经阅读了其他主题,尝试了那里的解决方案,但没有任何效果。

这是代码:

from ctypes import *

Papo32 = WinDLL("lib\\Papo32.dll")
Interlnk = WinDLL("lib\\Interlnk.dll")
Intfac32 = WinDLL("lib\\Intfac32.dll")
Spider32 = WinDLL("lib\\Spider32.dll")

ACQ_setup = Spider32.S8_ACQSetup
ACQ_setup.argtypes = [c_long, POINTER(c_long)]
ACQ_setup.restype = c_long

chans = [1]
n_chans = len(chans)
chans = (c_long * 8)(*chans)

error = ACQ_setup(n_chans, chans)
print(error)

这是错误:
error = ACQ_setup(c_long(n_chans), chans_array(*chans))
OSError:异常:访问冲突读取 0x00000000

数组为空时不会发生错误。

我从文档中得到了这个:

S8_ACQSetup

Syntax:
    result = S8_ACQSetup(Num, *Chans);

Parameters:
    Input:
        • Num - long
          Number of measured values per channels
        • Chans - long
          List of measured channels

    Output:
        Result of the function (long):
        If the result of the function is non-zero, an error has occurred.

Description:
    The desired channels will be activated for measuring.

我在 VB5 中按照制造商提供的这个示例进行操作:

Declare Function S8_ACQSetup& Lib "SPIDER32.DLL" (ByVal num As Long, Chans As Long)

Dim ChanArray(10) As Long

ChanArray(1) = 0
S8_Error = S8_ACQSetup(1, ChanArray(1))

提前致谢

标签: pythonctypes

解决方案


推荐阅读