I forgot to follow up on this. imdano has the correct solution.
Code:
class DAQmxDLL(ctypes.WinDLL):
"""Subclass of WinDLL to set a default _FuncPtr.errcheck."""
def daqmx_errcheck(self, ret, func, args):
if ret < 0:
buf = cstr(1024) # alloc a buffer
err_str = "NIDAQ call %s failed with error %d.\n" \
% (func.__name__, ret)
# simple
# if "DAQmxGetErrorString" not in func.__name__:
# self.DAQmxGetErrorString(ret, ctypes.byref(buf), len(buf)-1)
# verbose (same as GetErrorString but returns additional info)
if "DAQmxGetExtendedErrorInfo" not in func.__name__:
self.DAQmxGetExtendedErrorInfo(ctypes.byref(buf), len(buf)-1)
raise DAQmxError(err_str + buf.value)
return ret
def __getitem__(self, name):
func = self._FuncPtr((name, self))
if not isinstance(name, (int, long)):
func.__name__ = name
func.errcheck = self.daqmx_errcheck
return func
Bookmarks