import os import sys import ctypes as ct def LoadDLL() : # load the DLL with linux or windows specific invocations. # os.name is 'posix', 'nt', 'os2', 'mac', 'ce' or 'riscos' message = '' if os.name == 'posix' : try: dll = ct.cdll.LoadLibrary("nicaiu.so") #dll = ct.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 = ct.windll.nicaiu #dll = ct.cdll.somelibrary except : dll = 0 else : message = 'This operating system is not supported.' dll = 0 if dll == 0 : message = 'The required dll nicaiu was not found.' return dll, message class Types : def __init__(self) : self.int32 = ct.c_long self.uInt32 = ct.c_ulong self.uInt64 = ct.c_ulonglong self.float64 = ct.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 = ct.create_string_buffer('\000' * buf_size) dll.DAQmxGetErrorString(err, ct.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) print task_handle ErrorCheck(dll, dll.DAQmxCreateTask("",ct.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 print dll print message 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. print th #StartTask(dll, th) # Must have some channels associated with the task before you can start it #---------------------------------------------------------------------------------------------------------------------------------------------------- if __name__ == '__main__' : Test()