LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Streaming commands to a python console

Does anybody have any ideas on a way to stream commands to a python console?

 

A little background on the issue: I am able to control instruments in a system through a .dll that I call using python. I have already implemented a VI that can create a script "on the fly" and execute it to perform simple commands. The problem is that this creates a new instance of python every time I execute a command. It would be very advantageous for me to keep python running and only stop execution when I'm done sending commands.

 

I have tried accessing python directly from the python .dll through LabVIEW, but this got ugly very quick and I'm not a software engineer Smiley Very Happy

 

Please let me know if you have any suggestions on what path I should head down, Thanks.

0 Kudos
Message 1 of 6
(3,732 Views)

Thanks, I'll take a look at those links. I would just use labpython, but it doesn't seem to be compatible with python 3.3.

0 Kudos
Message 3 of 6
(3,694 Views)

If you can handle some Python programming...

 

The simplest way I've found to do this is to build a socket listener in Python.  It opens a TCP port, and waits for commands to come in.  You can see the basic idea at http://docs.python.org/3.3/howto/sockets.html.

 

On the LV side, you send commands to the Python socket using the TCP functions (http://www.ni.com/white-paper/2710/en/).

 

When the Python side receives a command, it breaks it down, and routes it to the right dll call.  When the dll call finishes, Python might send a message back to LV with results, if needed.

 

There are always a lot of little details to handle, but if you get the basics of this down, it works very well.



Suggestion from the LAVA forums, in case somebody stumbles across this thread in the future.

Message 4 of 6
(3,686 Views)

Nick, I'd like to try this solution however I am kind of a newbie to both LabVIEW and Python. Is there any chance you could provide a simple example?

0 Kudos
Message 5 of 6
(3,577 Views)

I wasn't ever able to find the bandwidth or the expertise to make this work. I have moved on from that project, diving in head first to automating instruments through python. I'm using the PyVisa wrapper to do my instrument control. Data collection isn't nearly as intuitive as I found it to be with LabView, but on a basic level it isn't too difficult to implement. 

0 Kudos
Message 6 of 6
(3,560 Views)