LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Error on dll call from python

Hello,

 

I write simple addition and subtraction vis then create dll file. I use ctypes package of python to call this dll file. Although I can load the file successfully, I find that the output is always 1018 no matter what the inputs are. I suspect that 1018 is the error code of LabVIEW. How can I solve this problem? Thanks a lot!

0 Kudos
Message 1 of 4
(3,148 Views)

Hi KK97,

 

LabVIEW should provide its own error handling by default in the form of popup error windows.  The output value of the VI is not used to indicate errors.

 

Most likely this issue is related to a datatype conflict.  I noticed that you are using doubles in the LabVIEW code but c_float in the ctypes code.  You'll need to double check, but I suspect those are not the same binary format.  LabVIEW expresses doubles in a 64 bit IEEE 754 format.  I am not familiar with ctypes enough to say what their format is for c_float, but my guess is that it's 32 bit like a C float.

Michael B.
Product Support Engineer
National Instruments
0 Kudos
Message 2 of 4
(3,114 Views)

Hi Michael,

 

Thanks a lot for your reply. I try c_double. However, nothing changes. Still 1018

0 Kudos
Message 3 of 4
(3,107 Views)

Hi KK97,


What is the return type of the library function when it's called in Python?  I believe ctypes requires you to set a return type, otherwise it assumes int, which would not work.  You could quickly test that in the same code by changing your LabVIEW functions to use integers, and rebuilding the DLL.

 

I did find this post with a similar issue: https://stackoverflow.com/questions/6073599/python-ctypes-return-values-question

 

The solution implies that ctypes is inspecting the call stack for the DLL and trying to find the returned value there.  If that is true, and the return type is ill defined, the results may be unexpected and unpredictable.

 

 

Are you able to successfully call this same DLL from LabVIEW itself?

Michael B.
Product Support Engineer
National Instruments
0 Kudos
Message 4 of 4
(3,093 Views)