LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Queued State Machine Arcitecture questions....

Hello,

I am working on a queued state machine architecture project that I have inherited from others. As there is absolutely no documentation, I am slowly working through what was done, and why. Most of what I am looking at is truly awful, but at the same time, I am far from an expert, so I thought I might ask some general questions and try to educate myself. If I am going to press to re-write all of what I am seeing, I certainly do not want to make more mistakes that can be avoided. Thanks to everyone in advance for their help. No code to post at this time, just gerneral sorts of questions... (I have asked a few questions in the past about this one, and people were very helpful).

 

1. This application is on a real time PXI box (8135 controller), connected to a windows machine with a LAN connection. They seem to be using a TCP/IP type of code to sum up all of the queue's together (both on the RT side and the windows side), and them move them as bundle elements through the TCP/IP. I had thought that you could (and should) create a bundle shared variable instead (I thought I read you could do this from a custom created control). And that once you do that, the Labview code makes the association between shared variables saved on the RT target, and reading them out again on the windows machine. If this works as I am thinking, will this also work for the .exe created as a stand alone later? There might be some sort of "gotcha" here that I was not considering.

 

2. I notice that they are using a lot of "functional global variables" (I think that is what they are called) This is when they are using a .vi with a shift register in it, to save an element inside the confines of the shift register, and then read out that infomation later. Why would you want to do that, vs. using a shared variable? I have spoken with the labview tech support folks many times, and their stance seems to be to only use shared variables. At least that way you have easy access to read and write to variables, and you can see which ones a program is using.

 

I have read the article "LabVIEW Queued State Machine Consumer Producer Architecture" by Anthony Lukindo which was really helpful, and seems to be the blueprint that they started with. Are there perhaps other ariticles that I can be pointed to? I am trying to gather all of the information and educate myself as much about real time and queued state machine architecture as I can. I want to make sure the next attempt at this is done in such a way they we will not have to replace it all again in a few years, or suddenly realize we need to redo everything because there is some additional information that we had not considered. Thanks.... Dan

0 Kudos
Message 1 of 10
(2,117 Views)
The reason I use functional globals is that they are easy to use, and they are reliable -- unlike shared variables! Same argument for the TCP/IP connection, easy and reliable.
In terms of State Machines, queued or otherwise, they can be helpful when developing a system that can be defined in terms of a series of clearly-defined states. Unfortunately a lot of people have no idea about what the difference is between a "state" and "the next thing to do".
Post some snippets if you can.

Mike...

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 2 of 10
(2,096 Views)

If you have the Real-Time Module installed for LabVIEW 2012 or 2013, there should be a Project Template available called "LabVIEW Real-Time Waveform Acquisition and Logging (NI-DAQmx".  If you create a sample Project with this Template, it will present a Queued Message Handler on both the Host and RT Target side, and will establish a pair of Networ Stream communication paths that allow the Host and Target to exchange messages using TCP/IP.  There is also reasonable Documentation that explains most of the component parts, and would be a good starting point to learn how the QMH can work, along with Network Streams for Host/Target communication.

 

It sounds like the project you inherited might have been based on a Template like this, or at least use some o the pieces that are documented in the example Template.  See if this helps.

 

Bob Schor

 

P.S. -- Functional Global Variables, also sometimes called VIGs (VI Globals), are a form of Action Engine that serves as a flexible form of "global memory" that can be accessed from multiple VIs.  The problem with a traditional "Global Variable" is that becauee is is accessible from everywhere, you can get into "race conditions".  An example is incrementing the variable -- you need to read the Global, increment it, and then save it back, but before you do the save, another VI might jump in and change it.  With a VIG, you make "increment" an "Action" of the VIG -- once you call the VIG, and it starts to run, no other process can get at its internals (where it is incrementing the saved data) until it is done.  {Sorry for the awkward explanation -- I hope you understand what I'm trying to say.  I'm sure if you search the Web for something like "Problems with LabIVIEW Global Variables", you can find a better explanation ...]

 

BS

0 Kudos
Message 3 of 10
(2,080 Views)

@Z4CRUZN wrote:

Hello,

I am working on a queued state machine architecture project that I have inherited from others. As there is absolutely no documentation, I am slowly working through what was done, and why. Most of what I am looking at is truly awful, but at the same time, I am far from an expert, so I thought I might ask some general questions and try to educate myself. If I am going to press to re-write all of what I am seeing, I certainly do not want to make more mistakes that can be avoided. Thanks to everyone in advance for their help. No code to post at this time, just gerneral sorts of questions... (I have asked a few questions in the past about this one, and people were very helpful).

 

1. This application is on a real time PXI box (8135 controller), connected to a windows machine with a LAN connection. They seem to be using a TCP/IP type of code to sum up all of the queue's together (both on the RT side and the windows side), and them move them as bundle elements through the TCP/IP. I had thought that you could (and should) create a bundle shared variable instead (I thought I read you could do this from a custom created control). And that once you do that, the Labview code makes the association between shared variables saved on the RT target, and reading them out again on the windows machine. If this works as I am thinking, will this also work for the .exe created as a stand alone later? There might be some sort of "gotcha" here that I was not considering.

 

2. I notice that they are using a lot of "functional global variables" (I think that is what they are called) This is when they are using a .vi with a shift register in it, to save an element inside the confines of the shift register, and then read out that infomation later. Why would you want to do that, vs. using a shared variable? I have spoken with the labview tech support folks many times, and their stance seems to be to only use shared variables. At least that way you have easy access to read and write to variables, and you can see which ones a program is using.

 

I have read the article "LabVIEW Queued State Machine Consumer Producer Architecture" by Anthony Lukindo which was really helpful, and seems to be the blueprint that they started with. Are there perhaps other ariticles that I can be pointed to? I am trying to gather all of the information and educate myself as much about real time and queued state machine architecture as I can. I want to make sure the next attempt at this is done in such a way they we will not have to replace it all again in a few years, or suddenly realize we need to redo everything because there is some additional information that we had not considered. Thanks.... Dan


It would be a truly odd thing to have something written as advnaced as a QSM and be truly awful.

 

Some advice on re-writing something complicated like this obviously is from the ground up... DON'T!!!  Even if you truly understand what the code is doing, you probably don't know everything, and trying to fix something may have unintended consequences.

 

If you insist on rewriting some stuff, start with cosmetic changes.  Label things, clean up messy wiring, that sort of thing.  Next, start grouping code that belongs together into subVIs, but keep the subVIs from being too complicated.  A good rule of thumb is: "If you can't explain everything going on in a paragraph or two, it's probably too complicated and should be broken down into subVIs that can... This goes for the top-level VI, too!!!

 

Beyond this... be VERY careful when you optimize things like formulas.  For instance, replacing doubles with integers just because the answer is always a whole number may or may not have consequences down the line.  In fact, in the DoD or aerospace industry, changing the way a formula calculates something my set off a whole chain reaction that may require you to re-verify the whole test on multiple units to make sure that the answers are consistent with the "old" way.  Pretty hefty money being unnecessarily spent if the "old" way was adequate to begin with.  Not to mention that if, at a later date, a trend is found where units are starting to fail that test when they pass using the "old" way, the customer may demand that all their previously accepted units be shipped back and re-tested... on YOUR dime.

 

Also, be careful when optimizing the way a test functions.  Just because a test would be more efficient and take less time with, for example, a QSM or QMH doesn't mean it SHOULD be changed.  What if, by optimizing the code, a part of the code that depended on a race condition stops working correctly?  You will spend a lot of time figuring out how to fix it before you realize you should've left it alone.

 

Now if it was your BOSS that decided they should spend money optimizing the software, make them aware of the subtle things I just talked about.  He/she may not give you more time and money to complete the project, but when it bogs down, you can at least remind them that you foresaw the difficulties!  😉

 

You seem to be at least peripherally aware of unintended consequences of your optimization efforts; I just wanted to make sure that they were front and center.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 4 of 10
(2,064 Views)

@billko wrote:

It would be a truly odd thing to have something written as advnaced as a QSM and be truly awful.

 


Really? My experience is that MOST applications I have see written with a QSM are "truly awful".

 

  • Applications that use states instead of subVIs
  • Applications that use a state machine because it's the "correct" way to do sequential operations in LV.
  • Applications that let you rearrange steps because the developer didn't really understand what he was doing.
  • Applications that don't really have any states

...and these are just the things that come off the top of my head.

 

Still, the rest of you advice is good. Refactoring and optimizing code is an iterative process. Handle the low-hanging fruit first (like using strings for the state machine value, using the wrong kind of wait, etc.) and then proceed from there to the more complex issues as you learn the code.

 

Mike...


Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 5 of 10
(2,040 Views)

Thanks to everyone for their thoughts and wisdom. You are correct, a full re-write will probably not happen due to the huge expense and time involved. I am doing the very small things for now. Mostly re-aranging the code making it easier to see what is going on, etc. There are many subvi's where subvi's are on top of the connecting wires etc. Thanks also for the explaination of why the Functional Globals are used. That would definately make sense why they were chosen. They are queing and dequeing from a dozen places all at the same time. I think it just might be one of those things that the more I look at it, the more sense it will make to me.. However, there are a few things that they did (our team in Bangalore India) that I will have to make sure is understood is just not allowed any more. Those things that I have found in the code are:

 

1. They used property nodes to change indicators on the main front panel from within other subvi's. Completely breaking program flow, and making it impossible to tell which subvi's contain the property nodes you are looking for. At the very least, you need to put a note in there explaining where the subVI is. There must be a least 100 subvi's to look through... not a fun treasure hunt.

 

2. Each .vi needs to have the descritption filled in, and to start using comments, as there are none in the whole program. I need to get across the idea that working but undocumented code by definition, is NOT good code.

 

3. They did wire the error wire in several places, but did not use an error handler anywhere. Something tells me this is why the program is so inconsistent. That there are probably several minor errors that have not been fixed.

0 Kudos
Message 6 of 10
(2,034 Views)

They are queing and dequeing from a dozen places...


 

 

Check those queues carefully. It is OK to enqueue in multiple places but if you dequeue (from the same queue) in more than one place, you may have big problems with data integrity.

 

Lynn

Message 7 of 10
(2,028 Views)

@mikeporter wrote:

@billko wrote:

It would be a truly odd thing to have something written as advnaced as a QSM and be truly awful.

 


Really? My experience is that MOST applications I have see written with a QSM are "truly awful".

 

  • Applications that use states instead of subVIs
  • Applications that use a state machine because it's the "correct" way to do sequential operations in LV.
  • Applications that let you rearrange steps because the developer didn't really understand what he was doing.
  • Applications that don't really have any states

...and these are just the things that come off the top of my head.

 

Still, the rest of you advice is good. Refactoring and optimizing code is an iterative process. Handle the low-hanging fruit first (like using strings for the state machine value, using the wrong kind of wait, etc.) and then proceed from there to the more complex issues as you learn the code.

 

Mike...


I guess it says something for diverse experiences (and that I freely admit that I don't have as much experience as you do).  Maybe it's because the only people I've seen that use them are people who actually knew how to use them.  Currently, software I am working on actually makes use of the fact that you can execute in any order because it is diagnostic software that is designed to be run manually.

 

But I appreciate that you can present an alternative view and I now know that outside of my little world lurks demons hiding in dark corners.  😉

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 8 of 10
(2,022 Views)

@Z4CRUZN wrote:

Thanks to everyone for their thoughts and wisdom. You are correct, a full re-write will probably not happen due to the huge expense and time involved. I am doing the very small things for now. Mostly re-aranging the code making it easier to see what is going on, etc. There are many subvi's where subvi's are on top of the connecting wires etc. Thanks also for the explaination of why the Functional Globals are used. That would definately make sense why they were chosen. They are queing and dequeing from a dozen places all at the same time. I think it just might be one of those things that the more I look at it, the more sense it will make to me.. However, there are a few things that they did (our team in Bangalore India) that I will have to make sure is understood is just not allowed any more. Those things that I have found in the code are:

 

1. They used property nodes to change indicators on the main front panel from within other subvi's. Completely breaking program flow, and making it impossible to tell which subvi's contain the property nodes you are looking for. At the very least, you need to put a note in there explaining where the subVI is. There must be a least 100 subvi's to look through... not a fun treasure hunt.

 

2. Each .vi needs to have the descritption filled in, and to start using comments, as there are none in the whole program. I need to get across the idea that working but undocumented code by definition, is NOT good code.

 

3. They did wire the error wire in several places, but did not use an error handler anywhere. Something tells me this is why the program is so inconsistent. That there are probably several minor errors that have not been fixed.


1.  If a test depends on "real time" updates to the front panel, it might make sense to update the main FP with property nodes - but it might be feasible to do sub-panels, too.  I don't think I can generalize about which one you should use, though.  And it's only not fun to look through the subVIs if they aren't documented.  If they were, it would be fairly easy to figure out where the panels are being updated.  (But of course, this isn't the case with the code you were handed.)  One place that is often overlooked in documentation is subVI names.  A descriptive name is half the battle.  You should be able to understand the basic function of each subVI just by looking at it in the project explorer.

 

2.  Ugh.  Spending two minutes documenting a subVI could save hours or even days of work later on.  😞  No one seems to understand that.  I make extensive use of free labels.  There were projects I worked on where I would even include requirements paragraph numbers so it could be easily found in a search.

 

3.  Definite no-no.  I am a stickler for at least rudimentary error handling.  Besides making it easy on the next guy, it does YOU a favor by letting you know what part of the code you screwed up.

 

I fail to see why people who are so meticulous making comments in text-based languages be so bad at commenting in LabVIEW.  If anything, it's easier to document in LV because you can actually draw and insert pictures.  And it's beyond my comprehension why the would be so sloppy with the wiring and stuff.  They wouldn't dream of using random indents in their code, so why code so wires run behind objects, wire objects in unconventional manners and stuff?  I mean, the computer doesn't care if you use random indents, or that a wire runs behind another wire and looks like it's aired to the case structure, but humans sure do!

 

At any rate, my condolences for being chosen to work on this project.  😉

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 9 of 10
(2,019 Views)

I get the definate impression from what I have seen so far, and the few converstations we have had with the team in Banagalore, that it is somewhat by design. Some engineers tend to believe that if they design something that is so complicated that only THEY understand it, then they have designed in their own career longevity. Not a design philosophy that I agree with. They claim they have no documentation, and that only two people have coded all of it. But the more I see of it, I am starting to doubt that. Granted I am far from the best labview programmer ever, but I have worked on lots of projects etc. And I would think it to be almost super-human to be able to keep the workings of 80-100 .vi's all working together in your head with nothing to refer back to.

At any rate, I will be pushing in the weeks ahead to start a massive documentation campaign. In my opinion.... magic code that only a few in a group understand is not acceptable... 🙂

Message 10 of 10
(1,996 Views)