LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Is race condition with serial port (RS232)

Solved!
Go to solution

Hi All,

 

Typical serial port action consists of 2 steps - write and read. In typical race condition example VI has 2 loops and each loop makes serial port action. I assume application will have case like "Loop1 write -> Loop 2 write -> Loop2 read and get Loop1 answer". Am I correct?

Of course, there are some application types when this race condition will not happen. For example, serial port write and read steps are combined in one vi which is not reentrant.

 

Also if I am correct I don't know any instrument driver which use semaphore to avoid race condition.

 

Thanks, Andrey.

Message 1 of 32
(4,163 Views)

Functions can run in any order as long as all of their inputs are available.  So if you have different serial reads and writes in different loops, of course they could run in whatever order.

 

This is a basic principle of dataflow.  Just because it is a serial port doesn't make its functions any different than any other LabVIEW functions.

 

You should centralize all serial port communication for a given port in a single loop or subVI.  Then use queues to send data back and forth to that loop.

0 Kudos
Message 2 of 32
(4,148 Views)

Vasilich2004 wrote:
Am I correct?

Yes.

 

There are, of course, different solutions to the problem. RF pointed out one. You brought up another - place the W/R actions in a single VI and always use that VI for communication.


___________________
Try to take over the world!
Message 3 of 32
(4,115 Views)

It really depends on your instrument for which way is better for avoiding your race condition.  Since it sounds like it is a command-response for getting data, I would use the non-reentrant VI approach to do the write and read process.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 4 of 32
(4,092 Views)

To RavensFan:

=============

You should centralize all serial port communication for a given port in a single loop or subVI.  Then use queues to send data back and forth to that loop.

============

 

When system would be a little complicated - centralization is bad idea. 

0 Kudos
Message 5 of 32
(4,069 Views)

To tst:

========

You brought up another - place the W/R actions in a single VI and always use that VI for communication

========

Not my solution. That is more or less usual approach in all NI third party drivers.

 

I use 2 semaphores:

- one for simple action (write-read)

- second for long complicated action

 

0 Kudos
Message 6 of 32
(4,067 Views)

To crossutz:

===========

... I would use the non-reentrant VI approach to do the write and read process.

==========

 

and in case of 10 or 100 pieces of the same devices in system performance will drop ... 😉

0 Kudos
Message 7 of 32
(4,065 Views)

Actually, can somebody explain me how to add answer of somebody when I reply?

I am tired to make copy-paste

0 Kudos
Message 8 of 32
(4,063 Views)

I don't think there is a multi-quote option, but once you hit reply, hit the Quote button on the upper right of the text box to plop down what they said, like this.

 


@Vasilich2004 wrote:

 

 

When system would be a little complicated - centralization is bad idea. 


I would vote for centralization, it might make things more complicated, but you get code that is more manageable, extensible, modular, and probably more reusable.

0 Kudos
Message 9 of 32
(4,055 Views)

@Vasilich2004 wrote:

To crossutz:

===========

... I would use the non-reentrant VI approach to do the write and read process.

==========

 

and in case of 10 or 100 pieces of the same devices in system performance will drop ... 😉


Over RS-232, I doubt we are dealing with that many instruments.  And I made that comment based on the understanding that this is the only instrument being used.  It is simple and works well.  Yes, it does lack scalability, but it is simple for newbies to create.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 10 of 32
(4,050 Views)