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

L

lee.walczak

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.
 
S

sturlamolden

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?

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
 
R

Robert Kern

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?

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
 
L

lee.walczak

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
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top