From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Passing String to LABVIEW DLL via Python 3.3.2 version (Please help...)

Hi there,

 

I have a problem passing string to LABVIEW DLL via Python. 

 

Basically, Input as a STRING from Python i.e “INIT” or whatever. Then pass it into LABVIEW then Output read as “INIT” from Python. But, what I read is nothing at the moment.

 

 

Python code as below,

from ctypes import *
from sys import exit

X = ('INIT')
STATE=c_wchar_p(X)

CallDLL = cdll.LoadLibrary("C:\Python33\\DLLs\\String.dll")

Output = CallDLL.String

OutputString= Output(STATE)

print ("String:",OutputString)

exit()

 

 

This is a result I am getting see below,

 

String: 0
Traceback (most recent call last):
File "C:\Walter\Pyhton_Examples\Math\String.py", line 15, in <module>
exit()
SystemExit

 

I have attached Labview code.

Download All
0 Kudos
Message 1 of 2
(2,436 Views)

I don't know Python, but as far as I can tell you're not calling the DLL properly. You configured the DLL to have 3 parameters (string input, string output, and output string length) and no return value. It looks like you expect the output string to be in the return value, which won't work because there is none. You need to preallocate space for the output string, then pass a pointer to that preallocated string along with its length as parameters to the DLL call. The DLL will copy bytes from the input string to the output string.

0 Kudos
Message 2 of 2
(2,419 Views)