From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

RT FIFO, several variables

Solved!
Go to solution

Hi,

 

I'm running 2 loops on a CompactRIO 9074. One is for deterministic I/O synchronized to the scan engine, and the other for network I/O with a client PC. I'm waiting for data in the network loop using network-published shared variables, and when I receive my data, I want to transfer it (the data is 2 arrays, one is an array of double, the other is an array of boolean) to the deterministic loop using RT FIFO's (or any other kind of non-blocking method for that matter).

 

The deterministic loop runs at 10 Hz and reads 2 RT FIFO's that contain the respective arrays. This is probably nitpicking, but I want to make sure that in an iteration of the deterministic loop, the arrays in the RT FIFO's have both been updated. I don't want one of them to have been updated while the other one is in the process of being written to by the network I/O loop, e.g:

 

- Deterministic loop -

RT FIFO read [array of double] (new data) -> RT FIFO read [array of boolean] (old data) -> ...

 

If I could bundle the data somehow using something RT FIFO-like, this could not happen as I would be writing to one variable only.

 

Any suggestions?

 

Best regards

0 Kudos
Message 1 of 6
(2,722 Views)
Solution
Accepted by topic author Miles Young

You could turn the array of boolean values into a integer values (boolean array to U8) and then transfer them in the same FIFO as the doubles.  If you tacked this value onto the end of the double array before placing it in the FIFO, you would just be reading out one array on your other loop.

Chris
Certified LabVIEW Architect
Certified TestStand Architect
0 Kudos
Message 2 of 6
(2,695 Views)

Yeah that would work. I was just thinking that there had to be some other means to do it. It would be a simple thing to do in C with a couple of structs and flipping a pointer.

0 Kudos
Message 3 of 6
(2,680 Views)

I'm not sure this is ever actually going to be an issue, so long as you read from the FIFO fast enough that it never fills.  Make sure you write a group of data to the boolean FIFO every time you write a group of data to the numeric FIFO.  When you do the read, you'll be guaranteed that it's the matching data.  The only situation in which it would not be the matching data would be if the FIFO filled, but you should be able to avoid that situation if you read from it fast enough (or, don't ever write if either FIFO is full).  Alternatively, if there's one boolean for every numeric value, I think you can put them in a cluster and write both together.  I don't understand what you mean about flipping a pointer in C - that's not quite the same as a FIFO in LabVIEW.  If you explain how you think you'd do it in C, we can probably suggest an equivalent in LabVIEW.

0 Kudos
Message 4 of 6
(2,671 Views)

I should elaborate slightly on my previous comment.  When you write the data, say you enqueue the numeric data first, then the boolean.  When you read from the FIFOs, dequeue from the boolean first and you'll be guaranteed that the matching numeric data is also available.  Since a FIFO is a queue, when you dequeue the element is removed so there's no possibility of re-reading old data.  On the write end, if the numeric FIFO is ever full, do not put any data into either FIFO.  Since you'll empty the boolean FIFO before the numeric one, if there is space in the numeric FIFO then there must also be space in the boolean FIFO.

0 Kudos
Message 5 of 6
(2,654 Views)

Also, remember when using an RT FIFO, the context help tells you that when using arrays you need to wire up an array of a proper size to the FIFO Read so that FIFO can preallocate the memory and keep it deterministic.

0 Kudos
Message 6 of 6
(2,649 Views)