LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Can LVOOP Based HAL be called from Python?

Hi All,

 

Just like the topic says, I have a HAL I created with LVOOP and in packed library style plugin format. I have some teams outside my immediate working group that is interested in using the HAL, but they mainly program in Python...so now I am wondering if there is a way of calling the HAL from Python. 

 

I looked around and saw mostly info dealing with enabling the ActiveX server, but didn't find additional information regarding calls to LVOOP or packed libraries.

 

Thanks,

Mike

0 Kudos
Message 1 of 6
(2,711 Views)

Here are the options I know of:

 

1. Calling the vi using ActiveX.  This shouldn't change if its a PPL or LVOOP. It is using vi Server stuff, and if its part of a PPL you will just have the vi path set to PPL\viPath. For example:

 

lvapp.GetVIReference("c:\myHAL\myHAL.lvlibp\HALStart.vi")

 

Disclaimer: I've never actually tried this, but from everything I know about vi Server it should work this way.

 

2. Compiling your HAL into a DLL for distribution. This likely will feel the most "native" to most text programmers.

 

3. Creating a standalone application in LabVIEW that listens for a localhost TCP connection and accepts commands/sends data back over TCP/IP.

 

There are a few variations of 3, but all basically require you to write a standalone server. You can even make the server run as a background process

 

 

Personally, I'd choose option 2 first, option 3 second. ActiveX would be my last choice.

Message 2 of 6
(2,699 Views)

Probably not directly.  In most cases LabVIEW passes values by value, not reference, and the "value" of an LVOOP object is... crazy.

 

However, if you made a bunch of wrappers for your library that use classes inside of DVRs, it might work.  See this post about LVOOP in DLLs, which isn't exactly the same but is quite similar in concept (allows external code to handle LVOOP objects as if they are pointers or 32-bit numbers).

 

If you know (or can figure out) your way around the VI scripting calls, it should be not too hard to script up something to do a bulk conversion.

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

Thank to you both for the feedback.

 

So sounds like this is doable by compiling it into a DLL, but the problem lies in passing lvclass as an argument? The way around it is to wrap each function inside a DVR so Python doesn't have to deal with lvclass types.  Does this sound about right?

 

I guess my follow up question is I am using dynamic dispatch with packed libraries and factory method. In LV, the parent would end up calling the child packed library...what would be the equivalent in the DLL world? Would I build a parent DLL, and then build each child into DLLs as well or leave the children as packed libraries?

 

Regards,

Mike 

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

@mygroundbiz wrote:

Thank to you both for the feedback.

 

So sounds like this is doable by compiling it into a DLL, but the problem lies in passing lvclass as an argument? The way around it is to wrap each function inside a DVR so Python doesn't have to deal with lvclass types.  Does this sound about right?

 

I guess my follow up question is I am using dynamic dispatch with packed libraries and factory method. In LV, the parent would end up calling the child packed library...what would be the equivalent in the DLL world? Would I build a parent DLL, and then build each child into DLLs as well or leave the children as packed libraries?

 

Regards,

Mike 


Thank you for sharing article and information. this is very helpful for beginner.

0 Kudos
Message 5 of 6
(2,629 Views)

For anyone who is interested, I did a follow up here with a sample project and got the sample project working. Next up is tackling the HAL itself.

 

https://forums.ni.com/t5/LabVIEW/LVOOP-Factory-Pattern-with-PPL-in-a-Labview-DLL/td-p/4037597

 

I followed the suggestion by Kyle and wrapped the functions and my factory with DVR, then type cast the DVR refnum into an u32 int so I don't have to deal with Labview reference in the DLL.

 

Regards,

Mike

Message 6 of 6
(2,593 Views)