LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

labview fpga dll issue

Hello 

 

I am quiet new with labview FPGA and have a question regarding controlling an FPGA via a third party host; in this case C# visual studio executable/application.

I wrote a simple program in my SBRIO9636 FPGA module that has two input; one is a FPGA input pin (that i control via hardware button) and the other one is a software button that i want to control via software, in this case a C# executable. both buttons send a boolean signal in an FPGA AND gate and output to an external FPGA pin (connected to a LED)

I generated a DLL of the FPGA that opens the "FPGA VI reference" before going to a while loop in which i call my FPGA VI (via "read/write control").  I use the DLL into my C# aplication to be able to control the Software botton inside my FPGA vi and get a boolean feedback everytime a click the software button. see attached codes

 

When I execute the C# application, and i click on the software button, the LED light up (showing that my C# application works) but  the signal get stuck inside the DLL while loop and as a results my C# application get stuck as well as the FPGA. If I remove the DLL while loop and the "close FPGA VI reference" then recompile everyrhing, it start working as expected but the FPGA module stops working after a few clicks on my C# application. 

 

Can anyone help. Any advice will be more than welcome.See attached Labview code and C# code.

 

Many thanks in advance

 

 

Download All
0 Kudos
Message 1 of 8
(4,184 Views)

Hi Turtur,

 

I would just like to check if you are ever hoping to get out of the while loop in the small_VI_5.vi? As you have wired a false to the stop button so this will never allow the while loop to end.

 

I think is would also be good to check through this article: https://support.microsoft.com/en-us/kb/815065

 

It mentions some common problems with using a DLL that could be happening with your application if it is getting stuck e.g. breaking the dependency.

 

Regards,

 

Luke

0 Kudos
Message 2 of 8
(4,138 Views)
Hi Luke
Thank you very much for taking the time to read and reply 🙂
To respond to your question I used a while loop in the small_vi_5 just because i got the code from the NI website and modified it a little to add my bottom and indicator. When I use it to create an executable via labView it works perfectly, never crashes. So I thought that if I use it to create a dll to use in a Windows executable it would work as well but surprisingly it doesn't work with my visual studio c# executable as well. It accept the first input then get stuck in the whole loop 😞
When I remove the whole loop it only executed once since I close the FPGA reference in the end of my DLL ( small vi 5) and if I do not close the FPGA reference it work as expected but after a few clicks the link between the FPGA and the host executable stops. I have to close my windows application and open it again to carry on controlling the FPGA for a few more click then the link dies again.
I want to maintain the link alive for as long as possible.
Any suggestions? Should I use DMA FIFO for this application?

Thanks again

Artur
0 Kudos
Message 3 of 8
(4,112 Views)

This is what you would expect to happen. Let's say you wrote a function in your C# code that contained a while loop that ran forever. When you called that function, your code would sit there forever running the while loop, and never return to your main code, right? That's exactly what you're doing here when you call a function in the LabVIEW-built DLL that contains a while loop. How did you think this would work?

 

I haven't opened your code, so this is more generic advice than specific to your situation, but split up your LabVIEW code into several functions. Store the FPGA reference in a functional global variable (FGV). You'll want to create VIs such as Open FPGA Reference (which you'll call once, and it will open the reference and store it in the FGV), read from FPGA, write to FPGA, and close FPGA. The while loop that calls the read and write (and whatever other) functions needs to be in your C# code, NOT in LabVIEW.

0 Kudos
Message 4 of 8
(4,095 Views)
Hi nathand

So why would my FPGA run with the while loop when I create a labView executable ??? And not run when I create a Windows executable ???
0 Kudos
Message 5 of 8
(4,069 Views)

I'm on an older version of LabVIEW so I can't open your code to see what you're doing. Is the VI that you're building into an executable the same VI that you're building into a DLL, or does your LabVIEW application call the DLL?

 

It makes sense for your LabVIEW VI to contain a while loop if it's running as an application; without a while loop, it will only run once. However, as I mentioned previously, if you then call that same VI as a function in a DLL, that function doesn't return until the while loop exits, and your while loop never exits, so your code hangs. Same thing would happen in C# (although in your minimal C# code, the main while loop is hidden by the Application.Run method - but it's running a loop, as mentioned in the documentation) if you tried to run your top-level code as a function called from somewhere else.

0 Kudos
Message 6 of 8
(4,045 Views)
Hi Nathand
I can send you a snapshot of my labView code tomorrow when I get to work. Yes the same labView that I use for the executable is the same that I use for the DLL.
So when I remove the while loop and do not close the FPGA reference in the labView code that I turn into dll, it run fine and respond well to my windows executable. However it only runs for a few seconds than the FPGA get stuck and stop responding until I close my windows executable and open it again then the FPGA start responding for few second and get stuck again.
What can or should I do so that the FPGA carry on responding to my windows application for ever without having to restart my windows application.
What causes the FPGA to stop responding?

Thank you again for your comment. It helps a lot to talk to someone who has good experience.
0 Kudos
Message 7 of 8
(4,035 Views)

I suspect the problem there is that you re-open the FPGA reference on every call to the DLL, which you should not do. Please re-read my earlier message. You need to break up your VI into several functions, and include a functional global variable (FGV) to store the FPGA reference between calls.

0 Kudos
Message 8 of 8
(4,032 Views)