LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Python calling LabVIEW shared Library

Highlighted

Hi Ppl,

 

I'm trying to call a shared library/DLL built from LabVIEW using the application builder from Python. I'm using ctypes to call these DLL's. I was able to pass in simple data types, like Integers, Stings and Booleans. But I was not able to pass in Structures/Clusters. Are there any examples availble for passing in Clusters/Arrays to these DLL. I found few examples in C# and VC++, but a Python example will be really help ful.

 

Thanks,

Sathish

Message 1 of 6
(2,435 Views)

Hasn't anyone done this before. Plz help me out.

 

Thanks,

Sathish

0 Kudos
Message 2 of 6
(2,390 Views)

Hi lordsathish, can you please tell me how do you call DLLs with ctypes ?

When I call a Labview compiled library in Python, it always return an error: "Procedure probably called with too many arguments".It seems DLL prototype is not recognized.

Thanks in advance

Angelo1

0 Kudos
Message 3 of 6
(2,234 Views)

Hi Angelo,

 

Good to see that someone else is also trying something that I did. Coming to the point. I load the DLL using the cdll.LoadLibrary function. This loadlibrary function will return the handle to the DLL. Now you can use the handle to call the functions within the DLL.

 

dll_handle=cdll.LoadLibrary("<dll_path>")

dll_handle.Add(<parameter_1>,<parameter_2>,<parameter_2>)

 

Add will be the function name that you used in the define prototype window while building the DLL. all the parameters should be ctypes data types. I'm able to pass simple data types like string,int, boolean. I was not successful in passing clusters yet.

 

Hope this helps.

 

BTW I'm curious to know what kind of application you are trying to call the LabVIEW shared library from Python.

 

Thanks,

Sathish

0 Kudos
Message 4 of 6
(2,223 Views)

I don't know about ctypes or calling DLLs in Python but LabVIEW clusters are simple C structs too unless they contain variable sized elements such as strings or arrays. Leaving those out of this since that is clearly beyond 99.9% of LabVIEW and Python users ability anyhow you simply would have to do a ctype in Python that matches a given C structure. To get an idea how that C structure looks you can best look into the header file generated by the LabVIEW DLL builder. If Python allows to create structure ctypes then that has to work. You need to be aware that LabVIEW uses byte packing in structures, so no alignement here with fill bytes.

 

Hopefully ctype allows to creat C structures. But looking here for how to do that is not really useful. Either Python has examples for that or you are out of luck.

Rolf Kalbermatter
Averna BV
LabVIEW ArchitectLabVIEW ChampionLabVIEW Instructor
0 Kudos
Message 5 of 6
(2,180 Views)

Hey Rolf,

 

Great to see you here. Your LabPython was really very useful. It was great Smiley Happy.

 

BTW we can create structures using ctypes. Here is the link to the documentation. I was successful in passing clusters without arrays and strings. LabVIEW does not expose strings within clusters as C string pointer, instead they are only LabVIEW string handle. That's why I think I was not able to pass in clusters with strings.

 

Thanks,

Sathish

0 Kudos
Message 6 of 6
(2,177 Views)