Real-Time Measurement and Control

cancel
Showing results for 
Search instead for 
Did you mean: 

How to Create Multiple threads programmatically on CompactRIO RT Controller?

Hello,

 

I am trying to run a reentrant SubVI multiple times on same time (on cRIO RT Controller). How is it possible programmatically? Attached pic explains what I need to do. Upper one is what I need to do programmatically. At the bottom I tried it in for loop,but of course it is not true, because it waits SubVI to execute next.

I have read those:

http://forums.ni.com/t5/LabVIEW/Community-Nugget-1-29-2007/m-p/469822?query.id=2981219#M226491

http://forums.ni.com/t5/LabVIEW/How-to-create-parallel-tasks-using-parallel-for-loops/td-p/1090891/h...

 

But I don't think it is possible with cRIO.

Can anyone help please?

Thanks in advance.

0 Kudos
Message 1 of 13
(5,803 Views)

Won't this do the same thing?  No re-entrant required.  If there is additional code, what's wrong with your upper case?

 

cRIO IO.png


--Using LV8.2, 8.6, 2009, 2012--
0 Kudos
Message 2 of 13
(5,787 Views)

Thanks for reply.

But I gave an example. I am actually trying something else and I need to run reentrant subvi parallel programmatically. This is my main problem. I just attached that picture to explain my problem better. Besides that code is senseless. 😃

 

Input array length can be change. it can be 50 for example. I don't want to put 50 (or maximum length it can be) reentrant SubVI . I just want to start execute 50 of them parallel in for loop .  But I don't know how to do it on cRIO RT controller.

0 Kudos
Message 3 of 13
(5,783 Views)

Ok, makes a little more sense now.  I think you'll want to use VI scripting.  Open a reference to your reentrant VI and use Invoke Nodes to Set Control Values and Run VI for each instance in a loop.  Make sure you understand what the various options and flags mean for each of these nodes.  You'll need to set the reentrant option on the Open VI Reference node also.


--Using LV8.2, 8.6, 2009, 2012--
0 Kudos
Message 4 of 13
(5,780 Views)

Ok thanks for help. I have tried it.. I hope it will also work for RT. I will try tomorrow.

0 Kudos
Message 5 of 13
(5,776 Views)

I can't do it on cRIO. When I give the VI path it returns:

"Not A Refnum
Refnum (in hex): 0x00000000"

Is it really possible to give a VI path on RT Controller? If so how should I do it? This is the path I gave for the SubVI:  "MyHostCode_subVIs\PID\SetValueIndex.vi"

(PID is virtual folder on controller)

 

And I think it won't be a solution to my problem. Because I need to get outputs in array with the same index I give the inputs.

 

I have a loop at 1Khz. I have to run quantity of "N" reentrant SubVI at 1Khz.

And I see this way increases my loop time. (It changes around 50ms - 700ms)

When I run 5 reentrant SubVI parellely, it works good (Upper code). So now I need to do it programmatically.

I attached the code I tried.

Any help is appreciated.

Download All
0 Kudos
Message 6 of 13
(5,769 Views)

I forgot that the VIs are deployed to the cRIO.  The path would change.  Try this thread, looks like it should work.

 

http://forums.ni.com/t5/Real-Time-Measurement-and/Dynamically-spawning-cRIO-daemons-using-quot-open-...


--Using LV8.2, 8.6, 2009, 2012--
0 Kudos
Message 7 of 13
(5,758 Views)

Thanks for the link.

I also tried it. And it didn't work at first. Then I deploy the SubVI manually then it worked, and doesn't matter if I give the name of the VI or full path.

But this doesn't fix the issue. I have 2 problem with this code.

1.) When I put this code to my control loop, it makes the loop very slow even though I set the "Wait Until Done" to false. I need to run this loop at 1 Khz.

(I get good result when I put 5 SubVIs manually)

2.) I can't get outputs of SubVI. Because I need to set WaitUntillDone to True.

 

I need to get outputs same index with the execution sequence of the SubVIs.

0 Kudos
Message 8 of 13
(5,742 Views)

Hi Tidus,

 

Would you be able to post a screenshot of your updated code so we can better understand why deployment of a single subVI does not work but with 5 there is no problem?  Thanks!

 

 

Aldo A
Applications Engineer
National Instruments
0 Kudos
Message 9 of 13
(5,713 Views)

Hello,

 

I have attached the code I have tried. Left side of the screenshot is what I need to do parallel in for loop. Right side of the screenshot is that I tried to do it with invoke methods. I normally should set Wait untill done to false to run parallely. If I set it to false I can't get the outputs. So probably I should set the outputs in the subVI with the index number to a global variable. But loop rate is problem here. When I dynamicaly load the SubVI, it increases my loop time compared to the left code.

I also tried parallel for loop, but I didn't notice any difference between normal and parallel for loop. I can limit my code up to 20 SubVI's but I just wanna know if there is a way to do left part of the screenshot programmatically with the same efficient?

Thanks.

0 Kudos
Message 10 of 13
(5,705 Views)