Windows Error Using ps2000aEnumerateUnits()

Forum for discussing PicoScope version 6 (non-automotive version)
Post Reply
MikeT
Newbie
Posts: 0
Joined: Wed Mar 06, 2013 11:53 pm

Windows Error Using ps2000aEnumerateUnits()

Post by MikeT » Thu Mar 07, 2013 12:00 am

I have a PS2206 scope and I’m putting a Python ctypes wrapper around the PS2000a.dll functions required for block acquisition. So far the programming has gone pretty well with the exception of one function: ps2000aEnumerateUnits(…). I get a Windows access violation when I try to evaluate this function. Here is the Python code segment:

Code: Select all

import ctypes as C
psLib = C.WinDLL('PS2000a.dll')

EnumerateUnits = psLib.ps2000aEnumerateUnits # (*count, *serials, *serialLen)
EnumerateUnits.argtypes = ( C.POINTER(C.c_short), C.POINTER(C.c_char), C.POINTER(C.c_short))
EnumerateUnits.restype = C.c_ulong

# Test EnumerateUnits(...)
count = C.c_short(0)
p_serials = C.create_string_buffer(64)
serialLen = C.c_short(64)
# For some reason this throws an error but does write the correct SN to p_serials
try: 
    EnumerateUnits( C.pointer(count), p_serials, C.pointer(serialLen) )
except WindowsError as err:
    print('WindowsError: {}'.format(err))
finally:
    print('Serial Number String: {}'.format(p_serials.value))

The result of running the script is:

WindowsError: exception: access violation reading 0x00000004
Serial Number String: AX768/138

Interestingly, the function does correctly return the device serial number in p_serials character buffer. But any further calls to the dll functions fail to execute properly and the Python shell needs to be restarted to clear the badness. Can anyone on this forum help?

Martyn
Site Admin
Site Admin
Posts: 3225
Joined: Fri Jun 10, 2011 8:15 am
Location: St. Neots

Re: Windows Error Using ps2000aEnumerateUnits()

Post by Martyn » Thu Mar 07, 2013 7:31 am

It may be worth initialising p_serials with a string, maybe 64 spaces, rather than nuls.
Martyn
Technical Support Manager

Post Reply