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: 

Where to place the Queue in a state machine

I have a state machine setup, which reads the bytes from PCB board - 20 bytes at every 10ms. The bytes are in a type of sequence, so I need to employ a statemachine to get the actual data. 

 

In the attached vi, I have a while loop and three states - each state doing some basic math with the data. The third state has my required information. So I want to send this information to an another while loop. I emkployed producer consumer architecture. However I am losing information, when I put the queue outside of my statemachine. I am losing two data points (defaulted to zero) repeatedly. 

 

So I tried plugging the enqueue inside the state machine (third state), now queue is throwing an error (ERROR 1). And none of the elements are being added to the queue.

 

What would be my alternative? I checked my tunnel assignments, I feel like I could do nothing over there.

 

PS: Employ a sine wave form or something for my serial communication. I believe the state machine is the key, as a random generator worked without the statemachine

0 Kudos
Message 1 of 11
(3,989 Views)

Error 1 is because your queue reference is invalid.

 

Spoiler
Wire the queue reference through all the cases!

CLA CTAChampionI'm attending the GLA Summit!
Subscribe to the Test Automation user group: UK Test Automation Group
0 Kudos
Message 2 of 11
(3,952 Views)

See all of those output tunnels that look like they have little dots in them?  Those are configured to "Use Default If Unwired".  Turn that off for all output tunnels.  This will force you to wire them up and avoid errors like this.  There is also the trick of using Linked Tunnels to autowire the input and output tunnels.


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 3 of 11
(3,947 Views)

Thank you everyone for answers. 

 

In the third state - With False condition - what would be the proper way to assign the tunnel? 

 

I did the queue through all the states, however, what would be the proper way if I just want to taking a data out of a single state? (With or without queue)

 

0 Kudos
Message 4 of 11
(3,944 Views)

Thank you everyone for answers. 

 

In the third state - With False condition - what would be the proper way to assign the tunnel? 

 

I did the queue through all the states, however, what would be the proper way if I just want to taking a data out of a single state? (With or without queue)

 

0 Kudos
Message 5 of 11
(3,943 Views)

Wiring the queue through all the states worked fine. 

 

However before thinking about the queue/ producer consumer architecture, I was using straight up data transfer from a state to outside of the statemachine and my data showed the same error. 

 

So i was almost convinced that it is not due to the queue. However, as few people pointed out it is the queue atleast in the vi I attached. 

 

However, find my full vi, where I am trying to get data from third state of statemachine and do some data manipulation. In this case, how would I do the tunnel assignments here ?

 

I tried default if unwired and it did not work. What are my other options?

0 Kudos
Message 6 of 11
(3,932 Views)

You really should separate your DAQ and serial.  They will not sync up properly and will likely just cause problems with each other.  In this case, I would use two loops and then use a Tag Channel (since you are in LabVIEW 2016) to pass the latest value from your serial port loop to your DAQ loop for combining and analysis.


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 7 of 11
(3,923 Views)

Yes, they are not sycning at all. 

 

I do not know what tag channel is, thats why I choose producer consumer architecture. Which one would you suggest be easier? Tag or Producer and consumer?

0 Kudos
Message 8 of 11
(3,920 Views)

@looser_engineer wrote:

 

I do not know what tag channel is, thats why I choose producer consumer architecture. Which one would you suggest be easier? Tag or Producer and consumer?


A Tag is a type of Asynchronous Channel Wire, a new Construct introduced in LabVIEW 2015 (but "hidden"), partly revealed in LabVIEW 2016, and fully revealed in LabVIEW 2017.  It represents a way of getting data from one parallel (asynchronous) Loop, such as a loop reading from a VISA Device at whatever speed it is going, and into another parallel (asynchronous) Producer Loop, perhaps running off a DAQmx device's Clock.

 

Suppose I have a Producer/Consumer loop, where the Producer outputs 1000 points at 1KHz every second, and bundles this along with the latest value from a Serial device that provides data at "about" 1 Hz (or maybe at 10 Hz, and you only want the "latest value").  Write your P/C Design ignoring, for the time being, the separate VISA Loop -- this will allow you to save your Sampled Data, but won't add the "latest VISA Info".

 

So have your VISA Loop "export" your data using a Tag, and receive it in the Producer Loop.  A Tag is a little like a Notifier in that only the Latest Value is present, but that's what you want, so use that.

 

Let's see if I can whip up a picture:

Tag PC.png

 

See that orange thing that looks like a pipe (instead of a Wire)?  That's an Asychronous Channel Wire.  Orange still means "Real".  The end-pieces on it are a Tag Writer (in the VISA Loop) and Tag Reader (in the Producer).  When the DAQmx Read finishes with its 1000 points, it bundles this, together with the latest Tag Value, and sends it to the Consumer (I didn't write that part of the code, obviously ...)

 

When I first posted this image (2 minutes ago), I realized there may be a problem, depending on how Bundle works, which explains why I stopped and added a Frame around the Bundle.  My idea is to ensure that the latest value of the Tag when the 1000 DAQ points appear gets bundled, not the first one (not sure when Bundling accepts its inputs, "as they come" or "only when all are present" -- I'm trying to "force" the latter, might not be necessary).

 

Bob Schor

 

0 Kudos
Message 9 of 11
(3,904 Views)

Bob,

 

I'd think a better way to force the bundling of the latest VISA data is to put the Tag Reader *and* the bundle inside that frame.  I.E., don't query for latest VISA data until after receiving DAQ data.

 

 

-Kevin P

CAUTION! New LabVIEW adopters -- it's too late for me, but you *can* save yourself. The new subscription policy for LabVIEW puts NI's hand in your wallet for the rest of your working life. Are you sure you're *that* dedicated to LabVIEW? (Summary of my reasons in this post, part of a voluminous thread of mostly complaints starting here).
0 Kudos
Message 10 of 11
(3,900 Views)