import os import sys import ctypes def LoadDLL() : # load the DLL with linux or windows specific invocations. # os.name is 'posix', 'nt', 'os2', 'mac', 'ce' or 'riscos' message = 'The required dll nicaiu was not found.' if os.name == 'posix' : try: dll = ctypes.cdll.LoadLibrary("nicaiu.so") #dll = ctypes.CDLL("nicaiu.so") # create an instance of a dll except : dll = 0 elif os.name == 'nt' : # cdll loads libraries which export functions using the standard cdecl calling convention. # windll libraries call functions using the stdcall calling convention. try: dll = ctypes.windll.nicaiu #dll = ctypes.cdll.somelibrary except : dll = 0 else : message = 'This operating system is not supported.' dll = 0 return dll, message class Types : def __init__(self) : self.int32 = ctypes.c_long self.uInt32 = ctypes.c_ulong self.uInt64 = ctypes.c_ulonglong self.float64 = ctypes.c_double self.task_handle = self.uInt32 self.written = self.int32 self.read = self.int32() def ErrorCheck(dll, err): """a simple error checking routine""" if err < 0: buf_size = 100 buf = ctypes.create_string_buffer('\000' * buf_size) dll.DAQmxGetErrorString(err, ctypes.byref(buf), buf_size) raise RuntimeError('Call failed with error %d: %s'%(err, repr(buf.value))) def CreateTask(dll, types, task) : task_handle = types.task_handle(task) ErrorCheck(dll, dll.DAQmxCreateTask("",ctypes.byref(task_handle))) return task_handle def StartTask(dll, task_handle) : ErrorCheck(dll,dll.DAQmxStartTask(task_handle)) def EndTask(dll, task_handle) : dll.DAQmxStopTask(task_handle) def ClearTask(dll, task_handle) : dll.DAQmxClearTask(task_handle) def Test() : dll, message = LoadDLL() # Establish a handle to the dll if dll == 0 : print 'Library not loadable. ' + message sys.exit() t = Types() # Define some recognizable data types. th = CreateTask(dll, t, 0) # Create the handle for task 0. StartTask(dll, th) #---------------------------------------------------------------------------------------------------------------------------------------------------- if __name__ == '__main__' : Test()