Using ctypes with National Instruments nilibddc.dll

Discussion in 'Python' started by aewindhorn@gmail.com, Mar 26, 2009.

  1. Guest

    I would like to use Python ctypes with this "DiaDEM Connectivity
    Library", but it only has examples for C and Matlab. I have got a
    couple of things to work by trial and error, but it is slow. Has
    anyone here used this library with Python?

    Here's what I have so far:

    --------------------------------------------------
    # Module to handle *.tdm and *.tdms National Instruments TDM
    # format files
    #
    from ctypes import *

    #Define short names for required dll functions
    DDCOpen = windll.nilibddc.DDC_OpenFile
    DDCNumGroups = windll.nilibddc.DDC_GetNumChannelGroups
    DDCReadGroups = windll.nilibddc.DDC_GetChannelGroups
    DDCGroupStrPropLen =
    windll.nilibddc.DDC_GetChannelGroupStringPropertyLength
    DDCGroupProperty = windll.nilibddc.DDC_GetChannelGroupProperty

    # File handles are pointers to 32 bit integer
    czero = c_int(0)
    FileHandle = pointer(czero)

    # Retrieve a handle to the file
    DDCErrCode = DDCOpen('Test_0919.tdms', 'TDMS', FileHandle)
    print(DDCErrCode) # Should be zero
    myfile = FileHandle.contents #The actual file handle

    # Find number of groups
    grpnum = c_int(0)
    numptr = pointer(grpnum)
    DDCErrCode = DDCNumGroups(myfile, numptr)
    print(DDCErrCode)
    # if DDCErrCode == 0: print(numptr.contents, grpnum)

    # Read the groups [UNTESTED]
    groups = c_int(0)*grpnum
    grpptr = pointer(groups) # Needs to be a pointer to memory to hold
    grpnum
    # of DDCChannelGrouphandle fields
    DDCErrCode = DDCReadGroups(myfile, groups, grpnum)
    print(DDCErrCode)
    if DDCErrCode == 0: print(groups)

    # Length of group name [UNTESTED]
    namelen = c_int(0)
    nlenptr = pointer(name)
    DDCErrCode = DDCGroupStrPropLen(groups[0], 'name', namelen)
    print(DDCErrCode)
    if DDCErrCode == 0: print(namelen)

    #Make a buffer to hold the name, then retrieve it [UNTESTED]
    grpname = create_string_buffer(namelen+1)
    nameptr = pointer(grpname)
    DDCErrCode = DDCGroupProperty(groups[0], 'name', nameptr, namelen+1)
    print(DDCErrCode)
    if DDCErrCode == 0: print(grpname.value)

    # Read the channels in the group and get the names [UNTESTED]

    # Read the channel # of data values [UNTESTED]

    # Read the channel data values [UNTESTED]

    # Process the data values [UNTESTED]

    # Write the processed data to a file in a different format [UNTESTED]
    --------------------------------------------------

    The "UNTESTED" sections are pseudocode of a sort. I have figured out
    how to get back (integer) file and object pointers, but I don't know
    yet how to get a pointer to an array of strings, which is the next
    step.

    I can supply a copy of the library if you want to try it, or it is
    available from ni.com. Thanks in advance for any help.

    Regards,
    Allen
    --
    Allen Windhorn, P.E. (MN) (507) 345-2782
    Kato Engineering
    P.O. Box 8447, N. Mankato, MN 56002
     
    , Mar 26, 2009
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. CHANGE username to westes

    Sample Code That Instruments Java Byte Code?

    CHANGE username to westes, Oct 14, 2003, in forum: Java
    Replies:
    1
    Views:
    1,025
    Robert Olofsson
    Oct 14, 2003
  2. Henk Punt
    Replies:
    0
    Views:
    403
    Henk Punt
    Jul 23, 2004
  3. Momo
    Replies:
    4
    Views:
    373
  4. Replies:
    0
    Views:
    506
  5. Asbjørn Bjørnstad
    Replies:
    0
    Views:
    441
    Asbjørn Bjørnstad
    Oct 9, 2008
Loading...

Share This Page