LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

two parallel while loops wait for each other, VI-based Server, DSC, serial communication

It's more a discussion:

You want to do two things on the same serial port
or other hardware. Action A is regularly performed
(e.g. read value) and action B only sometimes
(e.g. write value), if a certain event happens.
You want to do the things in two parallel while loops.
You want to be sure that there is only one action
at a time on the hardware (e.g. serial port).
(I need this for a "VI-based Server")
This is my idea, but I'm sure, that there is a more
clever way do the same thing.
Regards, Stefan
0 Kudos
Message 1 of 6
(3,226 Views)
I am using 6.1 so I can't review your example, but this sounds like a good place to use a semaphore.
0 Kudos
Message 2 of 6
(3,222 Views)
I had a similar action in one of my programs, where I needed to be constantly reading a GPIB device, and at certain point in time in another loop, I needed to record what loop iteration a certain value happened at in the other loop. The way I solved the problem was with notifiers. On the even occurring, it sent out a notification, which the other loop was waiting for. Now that means that the loop waiting on notification only ran when notification was sent, but that's what I wanted for my app.

I apologize if this isn't really applicable, but I can't d/l zip's since my network refuses them (not my choice!).

Geoff
0 Kudos
Message 3 of 6
(3,220 Views)
Yes, this is exactly what semaphores are for. I modified your program to use semaphores. I also eliminated the sequence structures. I did not take the time to convert to a state machine architecture, but I recommend you look into it.

You can probably eliminate most if not all of the local variables that way also.

Lynn
Message 4 of 6
(3,214 Views)
Hi Lynn,

that is a great solution. Thank you very much!!!
Once I tried the semaphores,
but was not lucky to understand it.
In the meantime I studied the difference between
"reentrant VI" and "not reentrant VI",
perhaps this is also an idea, to perform the
actions in one common "not reentrant VI"
(e.g. a sub-VI with a case structure,
one case for action A and one case for action B).
If it works I will post my example.

Regards, Stefan
0 Kudos
Message 5 of 6
(3,200 Views)
Hi Linn, BEHajder and the others,

I created a version with a "no reentrant sub-VI",
it seems that it works as fine as the version
with semaphores, but I don't know if my version
has a bad side effect. Regards, Stefan

PS: For beginners, I made use in my example
of a strict type definition, this is really a
nice feature.
0 Kudos
Message 6 of 6
(3,180 Views)