03-13-2009 08:39 AM
Hi there,
I have a little issue with parallel while loops accessing the same hardware on a serial port. My two loops both open a connection to my datataker and interogate channels. One loop interogates some channels every 10s and the other loop tries to access the datataker every 60sec. The problem is I think they conflict when they try and execute at the same time.
Is there a way I can get them to attempt to execute only if the other loop is finished? Essentially queing them only if the other is executing.
I did think about a boolean flag when a loops executing and a case structure in both loops which wont let it execute until the flag is false (for instance). I figure there is a better way than this.
Let me know what you think. My code is attached.
03-13-2009 08:53 AM
If I was doing this, I'd make it so there was only one loop doing all the serical communication, and it would distribute data to the other loops, possibly using queues. A 60 second loop wait in your second loop will feel like it takes forever to stop the program. (probably almost 2 minutes)
I would probably just put everything into 1 loop running at a 1 second interval, and only execute the code is the appopriate time has elapsed based on the 2 sampling rates.
Without making major changes to your code, you could also use semaphores before and after each serial subVI so that only one or the other can execute at any instant.
By the way, the index Array node is expandable. (You have already expanded all of them and not used the 2nd output). By expanding them, you can use one Index Array function to get all 7 of your elements.
03-13-2009 09:01 AM - edited 03-13-2009 09:06 AM
Reglar readers of my post are saying (Ben you sound like a broken record).... but here we go again.
An Action Engine (see this link) will help out.
Create an AE with method like
Init - Opens serial port and saves visa ref in shift register
Query1 - It use the VISA ref from the SR to send the query and wait for the reply.
Query2 -It does your other query and waits for the repsonse.
If you read that Nugget on Action Engines you will see that an Action Engine uses a mutex in the back ground to enusre only one caller is active at a time. That Nugget exaplains that behind the scenes a mutex is used. So your thought process was going the right way. AEs are the way to execute your idea.
Ben
03-13-2009 09:02 AM - edited 03-13-2009 09:02 AM
03-13-2009 09:38 AM
Ben wrote:Reglar readers of my post are saying (Ben you sound like a broken record).... but here we go again.
An Action Engine (see this link) will help out.
Ben, I think you should be in line for an award for most linked to nugget.
03-13-2009 09:45 AM
03-13-2009 09:53 AM
Ravens Fan wrote:...Ben, I think you should be in line for an award for most linked to nugget.
Thanks!
That is exactly why I wrote it. I think it was worth the time.
Ben
03-13-2009 10:07 AM
Ben wrote:Thanks!
That is exactly why I wrote it. I think it was worth the time.
Ben
Let me personally thank you for writing it. I had just started using functional global variables and your nugget inspired me to make better use of them.
Back to the original question. If I remember, both loops in the OP's program used the same subVI to encapsulate the communication with the serial device. The subVI wasn't attached so I couldn't look into it. Was is set to be reentrant?
I would say if that subVI was not re-entrant, then the communication in the two loops should not be interefering with each other.
03-13-2009 09:33 PM
Hi there,
Wow you guys are quick on the reply, especially for a saturday. Evidently I have exposed my limited knowledge of Labview and it is bringing me unstuck left right and centre.
I'll work through a few of the ideas mentioned on monday when I have my datataker next to me.
I see someone mentioned I didn't add the sub VI's. How do I save all of the necessary files to the one file so anyone could run that program?
Cheers
Wes