Importing a 3rd Party windows DLL for use within th Python

Discussion in 'Python' started by lee.walczak, Apr 4, 2008.

  1. lee.walczak

    lee.walczak Guest

    Hi,

    I have recently started learing how to code/script in Python which I
    am realy enjoying. I am new to this game as my background is RF/HW
    design engineer so coding is not my first skillset , so please bare
    with me!

    I am a little lost with how to procede on this problem. I need to
    write a python script enabling me to comunnicate routines to a pico
    ADC212 oscilloscope. I have been provided with a windows DLL & a
    header filefrom the manufacturer.
    Is it possible for someone to provide the information on the steps
    necessary to access this DLL and treat it like any other pyd library?
    Maybe there is already a tutorial available for performing this task?
    Is this task straight forward?

    Look forward to 'a' response!

    B.Regards,

    Lee

    Feel free to request more information if you feel it is necessary.
     
    lee.walczak, Apr 4, 2008
    #1
    1. Advertisements

  2. lee.walczak

    sturlamolden Guest

    Short answer: Read the ctypes tutorial and reference.

    http://python.net/crew/theller/ctypes/tutorial.html
    http://python.net/crew/theller/ctypes/reference.html


    Other options:
    - Write a pyd wrapper manually in C
    - Write a pyd wrapper using Pyrex or Cython
    - Write a pyd wrapper using Swig
    - Write a pyd wrapper using Boost.Python or PyCXX
    - Inline C++ using scipy.weave
     
    sturlamolden, Apr 5, 2008
    #2
    1. Advertisements

  3. lee.walczak

    Robert Kern Guest

    It depends on how complicated the library is. For a first stab, I recommend
    using ctypes. ctypes lets you load the DLL and call its functions in pure Python
    without having to write an extension module (pyd) first. ctypes comes with
    Python 2.5 already; if you have Python 2.4, you can install it separately.

    http://python.net/crew/theller/ctypes/

    You may eventually want to write an extension module. Here is the tutorial:

    http://docs.python.org/ext/ext.html

    There are a couple of tools to make this task easier. I happen to like Cython
    for things like this:

    http://cython.org/

    One large benefit of using ctypes instead of building an extension is that you
    do not have to compile anything. When wrapping binary-only DLLs on Windows,
    compiling and linking correctly are often the largest hurdles.

    --
    Robert Kern

    "I have come to believe that the whole world is an enigma, a harmless enigma
    that is made terrible by our own mad attempt to interpret it as though it had
    an underlying truth."
    -- Umberto Eco
     
    Robert Kern, Apr 5, 2008
    #3
  4. lee.walczak

    lee.walczak Guest

    Thankyou kindly for all the details you have provided. IT is nice to
    know that there is a community to help.
    I will let you know how I get on!

    Many Thanks,

    Lee
     
    lee.walczak, Apr 5, 2008
    #4
    1. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.