Looking for suggestion, loop terminate on time conditions - labview

I am trying to implement a simple python based code into the LabVIEW and for this, I am trying to implement this logic by using loop-timer termination but don't know how to run a loop that will terminate on time conditions.
Looking for your suggestions.

The problem is solved by using local variables and while loop combinations .

Related

Thread queue with timeout in VB . NET

I have a function which does some tasks in database trough a function contained in a dll. That function need to be executed many times with different parameters, but sometimes it takes too much time and need to kill the process and continue with the queue. The function in de dll doesn't have any timeout option, so I tried to control this creating a thread. I'm not used to work with threads, but after some research I made something like this code:
Dim Thread As New Threading.Thread(AddressOf Function)
Thread.Start()
Thread.Join(maxTime)
If(Thread.IsAlive) Then
WriteLogFile("Error [....]")
Thread.Abort()
End If
Probabily it isn't the smartier or most elegant way to do it, but it seemed to work when I tested it, but now I see that the "timeout" doesn't work. Well, it seems to work well if I set the timeout with a few seconds. But if I set it to 10 minutes, which is what I need, takes much more time than 10 minutes. I can expect that maybe Thread.join() is not totally accurate, but the difference is not jsut few seconds.
I tried many similar ways, so i don't know if i have the right focus of the problem. Maybe the malfunction of the code comes from the way of work of the .dll function, but first I need to discard the posibility of a mistake from myself (which i think is more probabily).
¿Can anyone tell me where is the mistake, or another way of doing this safer?
Thanks in advance.
Answered from comment of Hans. In order to control the execution of unmanaged code, threads can't provide a proper handling to finalize the function, so to implement a true timeout limiter, is needed to launch that function inside other project called as a process, to be able to call Kill() function, which really stops the process.

Labview 2012 Passing Dynamic data into/out of a while loop

I'm trying to pass data which is continuously changed from the inside of one While loop to the inside of another While loop of a sub-vi. The main program on the left is constantly reading new data and the program on the right is adding 1 to the new value. My issue is that I cannot input new values to a While loop which is already running and thus my sub-vi is never updated. I've tried a global variable ("write" from the main program control and then "read" into the sub-vi) but that doesn't work either (same result as if the main were just passing data into the sub).
I apparently don't have enough reputation to post a picture of my program but I'm basically trying to run parallel loops (almost inside each other). Can anyone lend me an experienced hand?
The most common problem with while loops are based on lack of knowledge how exactly does the while loop work in LabVIEW.
First of all the information will be given outside the loop only if the condition terminal (right down corner of the loop) will be flagged as true.
If you want to pass the data earlier (while the loop is running) you have to choose easiest option:
Use queue (is the most common and well working). I can elaborate how this one work in practise if you want, or just try to run an example from LabVIEW help.
local/shared variables - you can define in your own library variables and pass the data by READ/WRITE option.
Please try to upload some documentation to an external server (as you are blocked here), and post a link, and then I could help you with a specific example.
Help»Find Examples. Search for "queue". Pick out an example with parallel loops.
You might want to look into Queues or Notifiers as means of passing data between running loops.

Create a thread, keep it running, and reuse it / make calls on it

I'm not sure if this is possible or not, and I'm afraid I have no code at the moment, but I'm working on it. I've been searching for techniques like what I'm trying to do, but I'm not sure if anything is out there... let me explain conceptualy what I'm trying to do...
I have a small multi-threaded VB.net application I'm writing. In this application I'm using a com object. Initially I was trying to share this object between multiple threads - no dice. It was breaking on a wait for event line, which was when I learned about message pumping... Which I'm not sure I'm up to.
So, what I would like to try to do is set up a thread with that object and keep it running in a loop waiting for input from one of the other threads. When it gets such input, I'd like it to use the com object to perform a few tasks and then update a private class level collection, and then return to looping until I kill it.
I've been looking around to see if any sort of functionality like this is described anywhere, but I'm coming up dry. I'd most likely be creating this thread as a task... here's sort of what I'm thinking the first part would look like...
Dim openCheckTask As Task
openCheckTask = Task.Factory.StartNew(Sub() openOrderCheck())
...
Sub openOrderCheck()
Dim myComObject As ComObject = New ComObject
Do
Wait for input '<- ? This sort of plays into what I'm looking for...
myComObject.doSomeStuff
SomeCollection.Add(someValue)
Loop
End Sub
I really have no idea how to proceed from there. It's also worth noting that this thread would need to have a cue of commands, it could be executing one and have another or more waiting to be executed... not sure if that is possible either.
Any hints or suggestions are appreciated! Thanks again for your time everyone.

Deadlock using third party Ingear.Net .dll?

I am using a .dll from Ingeardrivers.com. I realize this question would more appropriately be asked on that site and have posted to there as well but more people on here makes my chances of it getting answered better.
I am a novice programmer and this is my first experience with threading. Basically I have two main loops in my program, and when I run each loop as the 'main thread' by itself - they both work fine individually. The problem is when I am starting two threads and running the main loop inside these threads, at some point in the loop they both are trying to use the Ingear.net dll and when one loop already has created an instance of the class, the second loop just sits on the constructor and doesn't do anything.
Does anyone have any suggestions on how to resolve?
I'd recommend firstly that you check with the vendor to see if the library is thread safe.
But in the mean time you could try creating a single instance of the class and passing it to your two threads/loops as part of the constructor (or setting a property with it).
It'll most likely not work, but you won't know until you try.
The add-on is thread safe -
I was manually disconnecting the controller each time via 'controllername.disconnect()'
For some reason this didn't actually close the connection and I was maxed out on CIP connections. When I removed that, the controller somehow knew to disconnect by itself.
Strange but it works.

How can I force a progress bar to update during a long-running operation in VB.NET?

I am running a test program for VB.NET, and it will simply crunch a million numbers in for loop. I've linked a variable implying the progress of the for loop with the progress bar, but it seems that when I run the program, the progress bar does not update itself. The bar itself has only value 0-100 as input (as stated in the document) and I've tested it without using the for loop, and it works.
I think this has to do with threads, but I am not sure how things work in VB.NET exactly yet. So I want to seek an advice from an expert first.
Any advice is appreciated.
Don't know if this still applies for .net (or if this is a VB6 question), but Application.DoEvents was generally the solution in VB6 days.
Try Application.DoEvents inside your loop that updates the progress bar.
long time ago but i think you need the
DoEvents
statement