04-07-2017 11:19 PM
Hi, i want to create a real time dll to run in LabVIEW real time PXI system, my program has to read a lot of data from text files and runs a numerical algorithm to find minimum for the input provided these initial operations takes long time and I cannot do it in time constrained loop in LabVIEW RT, hence I want to do these initial operations first without time constrains and I want to continue execution on the same dll in RT loop.
I have tried to put two "call library function" twice one out of RT loop and the other inside, but it started as different process and all my initiated variable are lost.
I want to know weather it is possible to share the variable as I intend to do, and how to do it?
04-08-2017 12:26 AM
my doubt is, if I call the same function in a dll once from a call library function out of while loop and next time onwards inside while loop using another call library function will it continue in the same dll function alredy opened outside the loop or will it create a new copy of dll function execution. if I want to continue on the same dll function what should I do. my first iteration is read file database and others are real time simulation program that uses the data read in first iteration.
04-08-2017 12:08 PM
@Boopathirajan wrote:
my doubt is, if I call the same function in a dll once from a call library function out of while loop and next time onwards inside while loop using another call library function will it continue in the same dll function alredy opened outside the loop or will it create a new copy of dll function execution. if I want to continue on the same dll function what should I do. my first iteration is read file database and others are real time simulation program that uses the data read in first iteration.
I might be misunderstanding what you are asking, but no, everytime you call a function it starts at the function entry point and runs through the function until it encounters a return statement or the end of the function. Anything else is not practical in a any way.
It would seem to me that you want to do something akin to what is usually called asynchronous operation (or in Windows speak they often call it overlapped operation). This is not done by calling funcitons partially and hoping they will somehow continue somewhere when called again later, but by maintaining a state data structure that remembers where the function stopped last time so it can continue next time from there. However the level of your question would make me advise you to first study some basic C programming techniques including data pointers before even trying to attempt this at all. Asynchronous operation is definitely an advanced programming technique, that can get hard to wrap your mind around, and without a very sound understanding of pointers and function execution, it's going to be impossible to get this ever do more than a big mess.
04-08-2017 12:10 PM
@Boopathirajan wrote:
my doubt is, if I call the same function in a dll once from a call library function out of while loop and next time onwards inside while loop using another call library function will it continue in the same dll function alredy opened outside the loop or will it create a new copy of dll function execution. if I want to continue on the same dll function what should I do. my first iteration is read file database and others are real time simulation program that uses the data read in first iteration.
I might be misunderstanding what you are asking, but no, every time you call a function it starts at the function entry point and runs through the function until it encounters a return statement or the end of the function. Anything else is not practical in a any way.
It would seem to me that you want to do something akin to what is usually called asynchronous operation (or in Windows speak they often call it overlapped operation). This is not done by calling functions partially and hoping they will somehow continue somewhere when called again later, but by maintaining a state data structure that remembers where the function stopped last time, so it can continue next time from there. However the level of your question would make me advise you to first study some basic C programming techniques including data pointers before even trying to attempt this at all. Asynchronous operation is definitely an advanced programming technique, that can get hard to wrap your mind around, and without a very sound understanding C programming, pointers and function execution, it's going to be impossible to get this ever do more than a big mess.
04-08-2017 12:39 PM
well, actually I wanted to know weather LabVIEW can do such operation or I have to do it in the program, since you have pointed out that has to be done at program leave, i will try that, but I am using Fortran 90 and visual Fortran compiler, any suggestions?
Thank you very much for your reply.
04-08-2017 12:57 PM
It doesn't matter if it is Fortran, C or any other similar programming language, as long as they are procedural, a function that is called starts at its entry level and runs through until it encounters an explicit return statement or the end of the function body. Once LabVIEW calls that function it has no control over the controlling thread until your function feels graceful enough to return to the caller.
However your entire problem seems to go around the assumption that LabVIEW code is inherently slow and moving this part into an external component will speed it up. The first assumption that LabVIEW code is inherently slow is completely wrong. The problem with LabVIEW code is that it is very easy to develop an algorithm that somehow works despite that it is using an abominable implementation. In C (or Fortran) you usually have to spend some time ahead to actually design the algorithm and then find a way to implement it in a way that won't crash your system. It is harder to come up with a working algorithm that won't crash your system, but once you have that, there is a good chance that the entire implementation is more sound than when you let a non-programmer implement the same algorithm in LabVIEW. But given similar programming experience and development effort it is almost always possible to come up with an algorithm that is similar in execution speed than what you can get with a reasonably developed C code routine.
And if you get into algorithmes that can use massive parallel programming, you get that in LabVIEW pretty much without any extra effort, while in C at least this makes the whole programming at least an order of magnitude more complicated.
04-08-2017 01:00 PM - edited 04-08-2017 01:09 PM
Sorry about the duplicated post! This forum sometimes keeps telling you that there is a problem and you have to retry a little later again and afterwards one has to find out that it somehow committed the post anyways.
04-08-2017 01:12 PM
Hi, first thanks for your reply.
i am not going to come out of a function in intermediate step, the dll has to read data when one of it's input is zero and it runs a simulation program from next call. Every call to the dll encounters an end statement. When I run the dll from a single call library function inside a while loop, it is able to initiate in first iteration and simulation runs from next iteration, but I want to run the first iteration before while loop, weather any reference can be passed between these call library functions so that I can use the data from my first iteration.
Else wether I can put the dll inside while loop and give time constrain from second iteration by connecting my step time variable to the terminal at the end of while loop, so that my next iteration runs with a time constrain, but I am using ʿwait until multiple timesʿ, just before while loop and a priority combination with other threads, so that start of my while loop synchronous with my other threads that are already running and the priority will determine in which order these threads should run, if I use non time constrained first while loop iteration my synchronisation is lost, so how to synchronous the thread with other threads from second iteration of this while loop.
04-08-2017 01:25 PM - edited 04-08-2017 01:28 PM
It's not so easy to understand what you try to do, but if I'm not mistaken you most probably want to allocate a pointer to some memory in your first call, store whatever information you need to maintain across functions calls and return that pointer as a pointer sized integer from that call, then in subsequent calls pass this pointer back to the function and use the information in that memory in whatever way you need. Don't forget to call at the end another function in your DLL which deallocates that pointer.
But unless you have already the entire algorithm more or less ready made in that other programming language, I still would suggest to not abandon the idea to do it all in LabVIEW. Your assumption that LabVIEW code is inherently slow is simply that, an assumption and a wrong one at that.
04-08-2017 08:31 PM
No, i am not assuming that LabVIEW is slow, LabVIEW is fast but the first initialize iteration of dll is not slow I would rather say big, as it has to read a lot of data and has to perform a numerical minimization and a linearization which ate iterative process hence a lot of time, nearly 3 seconds, but my simulation I have to run at 400hz, 2.5 ms.
I have three vis in my RT for I/O to other system. I want to run in the order of Receive, Model, Transmit, my I/O loops will be running first, whose process lies next to each other at the beginning of regular intervals 2.5 ms. Which I have achieved by assigning priority 200 to receive loop and priority 120 to transmit loop. These two while loops are synchronized by using " wait until milli second multiple" with a millisecond constant 25, just outside while loop so that these two while loops start exactly at the same time and since receive loop has high priority it will run first and once the process is completed, usually 200 microsecond the transmit loop will run, i have verified this using Real Time Trace Viewer.
Now I want to start my model and I want the process of model just between the process of receive and transmit loop, so with a timed loop priority of 160 and a wait until millisecond multiple of 25 ms will put my model start time at the same time as receive and transmit loop runs and because of priority the model process runs just in-between receive and transmit process, if I run my model without initiate iteration, and my model simulation takes around 100 micro seconds but my model initiate loop takes roughly 3 seconds because of all not LabVIEW. This disturbed the sequence it runs further hence I want to run my first iteration out of real time loop.
my code is ready completely and I just have to run in LabVIEW RT.
I had another idea to assign 5 seconds as dt to the timed loop with a priority 100- normal priority, while starting the while loop and for second iteration I will change the priority to 160 and dt to 2.5 ms, so that it runs in Real Time from second iteration. But how will make sure my second iteration starts at 25 millisecond multiple, so that it runs between my receive and transmit loops.