01-31-2019 01:28 PM
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!
02-01-2019 04:32 PM
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.
02-02-2019 11:04 AM
Hi Michael,
Thanks a lot for your reply. I try c_double. However, nothing changes. Still 1018
02-04-2019 04:27 PM
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?