import ctypes import numpy from string import * ## Load the windows-type dynamic link library nicaiu.cll supplied by NI. nidaq = ctypes.windll.nicaiu ## Setup some data type classes and some constants. These correspond with the types and values appearing in the header file ## C:\Program Files\National Instruments\NI-DAQ\DAQmx ANSI C Dev\include\NIDAQmx.h. """ The data type classes to be used: class ctypes.c_long Represents the C signed long datatype (32-bit integer). Same type as c_int and c_int32. The constructor accepts an optional integer initializer as in c_long(314); no overflow checking is done. class ctypes.c_ulong Represents the C unsigned long datatype. Same type as c_uint32. The constructor accepts an optional integer initializer; no overflow checking is done. class ctypes.c_ulonglong Represents the C unsigned long long datatype. Same type as c_uint64. The constructor accepts an optional integer initializer; no overflow checking is done. class ctypes.c_longlong Represents the C signed long long datatype (64-bit integer). Same data type as c_int64. The constructor accepts an optional integer initializer; no overflow checking is done. class ctypes.c_double Represents the C double datatype (64-bit floating point). The constructor accepts an optional float initializer. """ int32 = ctypes.c_long uInt32 = ctypes.c_ulong uInt64 = ctypes.c_ulonglong float64 = ctypes.c_double TaskHandle = uInt32 ## Create a mutable string buffer for up to 10 bytes, and initialize the buffer entries to NUL (0x00). Either statement below will work: ## the_buffer = ctypes.create_string_buffer('\x00' * buffer_size) ## the_buffer = ctypes.create_string_buffer(buffer_size) """ ctypes.create_string_buffer(init_or_size[, size]) This function creates a mutable character buffer. The returned object is a ctypes array of c_char. init_or_size must be an integer which specifies the size of the array, or a string which will be used to initialize the array items. If a string is specified as first argument, the buffer is made one item larger than the length of the string so that the last element in the array is a NUL termination character. An integer can be passed as second argument which allows to specify the size of the array if the length of the string should not be used. If the first parameter is a unicode string, it is converted into an 8-bit string according to ctypes conversion rules. """ ## The memory block contents can be accessed (or changed) with the raw property; if you want to access it as NUL terminated string, ## use the value property. buffer_size = 10 the_buffer = ctypes.create_string_buffer(buffer_size) ## Use the DAQmxGetSysDevNames() function of nicaiu.dll, which writes into the buffer the names of the devices recognized by this dll. ## Ignore this statement: nidaq.DAQmxGetErrorString(err,ctypes.byref(buf),buf_size) """ repr(object) Return a string containing a printable representation of an object. This is the same value yielded by conversions (reverse quotes). It is sometimes useful to be able to access this operation as an ordinary function. For many types, this function makes an attempt to return a string that would yield an object with the same value when passed to eval(), otherwise the representation is a string enclosed in angle brackets that contains the name of the type of the object together with additional information often including the name and address of the object. A class can control what this function returns for its instances by defining a __repr__() method. """ ## The buffer has both raw and value properties. nidaq.DAQmxGetSysDevNames(the_buffer, buffer_size); print(ctypes.sizeof(the_buffer), repr(the_buffer.raw)) print(the_buffer.raw) # Labels for devices found by nicaiu print(the_buffer.value)