C# vs Python

C# vs Python

Postby ReversE_3ngineeR » 20 Apr 2016, 00:00

Recently got Mk 2/4 to automate some measurements for research. In undergrad I worked as research assistant and made some code in C# for a grad student to make a Mk 2/4 do some scanning similar to what I'll be doing. I've been .NET my whole programming career so I was thrilled to see C# API, but I'm really getting into and loving Python lately. Anyone know pros/cons to interfacing with Python? For example, not knowing position or something when there is a function for it in the C# API? Python's ease of use and cross-platform compatibility make it look like a real winner to me.
Posts: 2
Joined: 19 Apr 2016, 23:51
Controller: Mk2/4

Re: C# vs Python

Postby pform » 13 Jun 2016, 20:37


I too would be interested in using python.

Posts: 2
Joined: 13 Jun 2016, 20:36

Re: C# vs Python

Postby Support » 17 Jun 2016, 09:50

The case here is, if Python is able to use API Windows files...
Posts: 2657
Joined: 07 Apr 2014, 17:39
Controller: Many controllers

Re: C# vs Python

Postby NeoTech » 26 Aug 2016, 19:24

you should be able to use ctypes in Python handling the API if its in solid DLL.

Code: Select all
import ctypes

# Load DLL into memory.

hllDll = ctypes.WinDLL ("c:\\PComm\\ehlapi32.dll")

# Set up prototype and parameters for the desired function call.

hllApiProto = ctypes.WINFUNCTYPE (
    ctypes.c_int,      # Return type.
    ctypes.c_void_p,   # Parameters 1 ...
    ctypes.c_void_p)   # ... thru 4.
hllApiParams = (1, "p1", 0), (1, "p2", 0), (1, "p3",0), (1, "p4",0),

# Actually map the call ("HLLAPI(...)") to a Python name.

hllApi = hllApiProto (("HLLAPI", hllDll), hllApiParams)

# This is how you can actually call the DLL function.
# Set up the variables and call the Python name with them.

p1 = ctypes.c_int (1)
p2 = ctypes.c_char_p (sessionVar)
p3 = ctypes.c_int (1)
p4 = ctypes.c_int (0)
hllApi (ctypes.byref (p1), p2, ctypes.byref (p3), ctypes.byref (p4))
Posts: 6
Joined: 26 Aug 2016, 10:48
Controller: Mk3

Return to API

Who is online

Users browsing this forum: No registered users and 2 guests