ctypes: Problems using Windows-DLL from VB example code

Noralf Trønnes notro at tronnes.org
Wed May 9 12:55:42 EDT 2007


Hi

I'm trying to use a DLL from Python using ctypes.
The call to dso_lib.capture_hold_chk() does return 232. So it seem to work.
The call to dso_lib.port_init(init_data) gives:
WindowsError: exception: access violation reading 0x00000006

Any suggestions?

Thanks.

Noralf


Here is my python code:
import os
from ctypes import *

# Hardware control data
class A_INIT(Structure):
    _fields_ = [("time_d_va", c_long),
                ("tri_in_sel", c_int),
                ("ch1_div", c_int),
                ("ch1_in_sel", c_int),
                ("ch2_div", c_int),
                ("ch2_in_sel", c_int),
                ("ram_rw_mode", c_int),
                ("ram_copy_mode", c_int),
                ("ram_copy_delay", c_int),
                ("ho_mode", c_int),
                ("ho_mode1", c_int),
                ("CH", c_int),
                ("TRI_12E", c_int),
                ("Ch1_To_Gnd", c_int),
                ("Ch2_To_Gnd", c_int)]

dso_lib_filepath = os.path.join(os.path.dirname(__file__), 
'dso_2100usb_s.dll')
dso_lib = cdll.LoadLibrary(dso_lib_filepath)
init_data = A_INIT()

init_data.time_d_va = 0
init_data.tri_in_sel = 7
init_data.ch1_div = 4
init_data.ch1_in_sel = 1
init_data.ch2_div = 4
init_data.ch2_in_sel = 1
init_data.ram_rw_mode = 1
init_data.ram_copy_mode = 14
init_data.ram_copy_delay = 0
init_data.ho_mode = 1
init_data.ho_mode1 = 0
init_data.CH = 0
init_data.TRI_12E = 0
init_data.Ch1_To_Gnd = 0
init_data.Ch2_To_Gnd = 0

print dso_lib.capture_hold_chk()  # returns 232

print dso_lib.port_init(init_data)  # WindowsError exception


Here is the code from a Visual Basic example using the DLL:

Type A_INIT                               'hardware control data
    time_d_va As Long
    tri_in_sel As Integer
    ch1_div As Integer
    ch1_in_sel As Integer
    ch2_div As Integer
    ch2_in_sel As Integer
    ram_rw_mode As Integer
    ram_copy_mode As Integer
    ram_copy_delay As Integer
    ho_mode As Integer
    ho_mode1 As Integer
    CH As Integer
    TRI_12E As Integer
    Ch1_To_Gnd As Integer
    Ch2_To_Gnd As Integer
End Type
Public init_data As A_INIT

Public RESULT As Integer

Public Declare Function port_init Lib "dso_2100usb_s.dll" (init_data As 
A_INIT) As Integer

Sub init()
  init_data.ch1_div = 4
  init_data.ch1_in_sel = 1
  init_data.Ch1_To_Gnd = 0
  init_data.ch2_div = 4
  init_data.ch2_in_sel = 1
  init_data.Ch2_To_Gnd = 0
  init_data.ho_mode = 1
  RESULT = port_init(init_data)
End Sub





More information about the Python-list mailing list