State machines caveat

I have been using the state machine design pattern in programs for a
while. In this technique, it is a common practice to define boolean
switches to trigger actions in the next iteration of the machine (eg.
"TurnLaserON", "Quit", "Compute", "SetAlarm1"...). Thus, the boundary
between data and processing is easily trespassed.
This sounds to me like a possible source of errors, that should be
limited by some design rule of thumb. I tend to believe that boolean
triggers in state machines should be looked at with the same precautions
as a "GOTO" control structure.
Do you have any experience or theoretical frame to enlighten these
considerations ?
oz

Hi,
I always prefer a state machine with a state buffer. This means, every state
can, potentially, call several other states. In practice, there is a shift
register with an array of strings in it. The first string is called, and
removed. Every state can modify the buffer, so:
+ states can be put before, after or between the buffer
+ states can be removed
+ states can be filtered, sorted etc.
+ buffered states can be copied
This makes programming with state machines a lot easier. You can simply make
a state TurnLaserON, and in the calling state(s) diside what the state after
TurnLaserON has to be. This makes the program a lot clearer.
Some design rules I use (mainlly because if I don't use them, there is no
way of documenting the program):
+ states may only put states before the buffer (I call them sub states)
+ buffered states cannot be removed in a state
Using these rules, I can put the entire program on paper, without any
problem.
Still, I have to transfere information between states. This 'information'
can be a shift register with a bundle, indicators on the front panel (not
visible to the end user), a GLI, buffers, ini file reference, or whatever. I
have never found any big advantage or disadvantage for eny of them, but I
prefer indicators (mixed with buffers when convenient), because they are the
fastest to use (for me), and easiest to debug (IMO).
Regards,
Wiebe.
"O. Zimmermann" wrote in message
news:[email protected]...
>
> I have been using the state machine design pattern in programs for a
> while. In this technique, it is a common practice to define boolean
> switches to trigger actions in the next iteration of the machine (eg.
> "TurnLaserON", "Quit", "Compute", "SetAlarm1"...). Thus, the boundary
> between data and processing is easily trespassed.
>
> This sounds to me like a possible source of errors, that should be
> limited by some design rule of thumb. I tend to believe that boolean
> triggers in state machines should be looked at with the same precautions
> as a "GOTO" control structure.
>
> Do you have any experience or theoretical frame to enlighten these
> considerations ?
>
>
> oz
>

Similar Messages

  • Data acquisition in a state machine

    I've recently learned how to implement state machines, but I have a question that I haven't been able to find an aswer to.
    Question:
    How do I record uninterupted data (presently i'm using the DAQ assistant to record a single channel at 10kS/s at 1kS intervals) without interfering with my state machine?  
    Background:
    I have a time sensitive test setup (measuring pressure in a rocket chamber), and I'm using labview to both record a single pressure transducer as well as operate the valves (O2, N2, igniter, etc).  I'm using a state machine Labview architecture (just learned how).  Presently, the DAQ assistant sits in the "Idle" state, and timers (valves need to be turned on at specific times) and manual buttons control when the other states are activated.  I have a 10ms timer controlling how often each state is run, and this is the root of my concern.  
    Main concerns:
    I'm worried that:
    1)  I'm forced to change my data recording to 10ms intervals to match the 10ms timer, and
    2)  The 10ms timer will interrupt my data recording when it's in another state.  
    It's very important that the pressure data is recorded without interruption but that I have high time resolution in controlling my valves as well.
    Thoughts:
    1)  Maybe I put the 10ms timer in the "Idle" state only, and this way the other states won't interrupt the data acqusition
    2)  Maybe there is a way to completely isolate the state machine for controlling the valves and the data acqusition.  I'm not sure how to do this.
    3)  People on the forums have been talking about Queuing their data acqusition, but I'm not sure how this would benefit my situation.  
    Thanks to everyone for their feedback!

    The data acquisition and state machine timer do not have to be equal, you should however have the same data write rate as you have data read rate, otherwise over the course of long running programs you can build up a large buffer of data to be written using a lot of memory, or lose data.
    Your data acquisition should be continuous, the most common way of doing this is every time you receive data write it to a queue, then when you are in other states except your data write stage you simply build up data in the queue that is to be written when you enter the write state again.
    Think of it as traffic reaching a set of lights:
    The traffic represents the data acquisition, there is a constant flow of it always coming through, the state of your state machine is the lights, green is the data write state clearing the queue, red is when in any other state, letting the traffic build up behind the lights.
    It is just important that the light is green long enough to let the traffic not build up too much, otherwise you have a jam.
    EDIT: For the basics of how queues work, look at the Queue basics example from the example finder. 

  • Data acquisition & state machine

    Hi all,
    I am working on a project that is capable of data acquisition, analyse, and record processes. I have to acquire data of temperature from 8-32 channels and that of pressure from 7 channels. After analysis, I have 48 outputs. I want to record raw data (acquired) and analysis data at the same time.
    1) Is it possible to record two text files (raw data and analysis data records) at the same time?
    I also want to adjust acquired sample rate but I have doubts about utilizing it in a state machine. For now, I have just used time elapsed function to acquire data once in 60 seconds.
    2) How could I set sample rate of acquisition except using time elapsed function?
    I also have one more doubt about timing. If I needed to acquire sample once in 60 seconds, but the analysis took more than 60 secs, what would happen?
    3) How can I prevent data loss in this case?
    I have not prepared a user interface yet.
    4) How can I utilize it? Do I put graphs and indicaters in the same VI or is it better to prepare another vi just for user interface?
    Thanks in advance
    Egemen
    Attachments:
    Program.llb ‏433 KB

    Hi Egemen
    -          If we need to acquire data and analyze it at the same time we recommend the architecture producer-consumer to prevent data loss, and yes you can record two text files at the same time. Please take a look to this architecture.
    -          http://www.ni.com/white-paper/3023/en
    -          Basically you use the first loop to acquire data and the second one to analyze and record data (using queues).
    -          https://decibel.ni.com/content/docs/DOC-2431
    -          You can also find examples about this architecture at the developer zone.
    Regards

  • How can I keep a state machine readable when using large amounts of in/outputs

    Hello, I am new to Labview,
    Read trough the fundamentals and the
    getting started and a lot of examples.
    What I want to do is use a standard
    state machine from the template, and add some stages, for example
    orange, apple, banana. At this point I can use numeric controls to
    put in the amount of oranges, apples, bananas there are. I can even
    use a led to tell the user which state of the state-machine is
    active.
    The thing is there will be more numeric
    controls and more leds and it would be nice if the code would still
    be readable when there are 20 inputs and 20 outputs.
    Questions
    (1) It would be nice if I could use the
    typedef to select the right state AND the corresponding numeric
    controls and leds out of a cluster or an array kind of structure to
    keep the number of wires low. Is this possible, how can I do this?
    (2) I tried to put the numeric controls
    into a cluster but that way I can't put the numeric control for the
    apples in the upper right corner and the numeric control for the
    oranges in the lower left down corner of the front panel.
    (3) An example would be really nice, I
    know that I saw some examples describing this problem but there are
    so many examples that after a few hours of searching I haven't found
    the right one yet.
    Thanks in advance for the effort.
    p.s. I will not use Labview to do
    calculations on fruit, I am only using this to make the question
    easier to understand.

    I can only start a proper answer but I might as well start with that.
    When I am developing State Machines I have to think about what data is used and manipulated in each state. I then have to think about where am i going to keep and manage the data. I list all of the fields that are "touched" in each state and what values are used together and which are independent form the others. After this phase of the analysis, I usually have some data structure defined (cluser array etc).
    Then I flipp from thinking about the state to thinking about the data (after all this is LabVIEW and the data-flow paradigm is critical). If I see data that is only used by the State machine and is used in many of the states, then the data structure get put in a shift-register for easy access in each state. This maybe enough of an answer for your fruity question.
    When i see data that is shared or only used in a handful of states then I concider putting the data in an Action Engine. Depending on how you design your AE, you can access each of the fruit totoal by name or increment etc as required.
    If your app demands many fileds that are all related (can't be broken into distinct data structures) then create a cluster that has all of your values that are used by the AE. Then create an Wrapper VI for each call of the AE but only put the associated fields on the FP of the wrapper and then bundle that value into the cluster and invoke the AE.
    Ben
    PS: Sorry about reverting to neBulus mode but this topic could take days to cover in detail.
    Ben Rayner
    I am currently active on.. MainStream Preppers
    Rayner's Ridge is under construction

  • How to use a event structure with a state machine

    First, I would like to inform you that I only work on LabView part time, and have much to learn.  Anything I do learn, I usually forget until I need it again, because I only work on it part time.
    Using your StopWhileLoopMOD[1].vi, I am trying to put a state machine inside the event structure.  
    Related link: http://forums.ni.com/t5/LabVIEW/How-to-stop-while-loop-in-Event-case/td-p/465564/page/2
    Here is my application:  on the front panel, the user can select any combination of 7 different tests.  I have created cases to perform each step of each test in the correct order, but if the user presses stop, the tests won't stop because some of the cases have a while loop inside the event structure (like you mentioned is a bad idea).  The user should be able to stop the test, reselect tests to perform, and re-start the tests. 
    When the start button is pressed for the event structure, I need all the cases to run in the proper order, unless stop is pressed.
    In the past I have indexed an array and used that to run the state machine, but it won't stop immediately.  
    I have sub VIs that are built in while loops because the outputs of the product needs time to stabilize.  The state machine stops and waits up to a certain number of iterations.  If it passes the test, the while loop stops and the next state starts.  If it takes too long, it exits and reports an error.  Maybe I need to just use the state machine and not an event structure?
    Is there a good example of an event structure?
    metzler CLAD
    Solved!
    Go to Solution.

    I'm not sure exactly what you are asking, but it sounds like you want to script a bunch of tests and if the user says stop, to immediately stop the current test and abandon the others?  I'm going to assume that you know how to clear the array so that it will abandon the others, so I'm guessing that you are having trouble abandoning the current test?  If this is indeed the case, then the problem is that you are not able to propagate the message from the main VI FP which is the GUI to the sub vi which is the test, where the test may or may not have a GUI (FP visible) of it's own.  Threading was the first thing to come to mind, but this may not be necessary using events.
    You can do this by passing a refnum of the stop button to the subVI, where you can then add that wait to the event case structure.
    I've attached 2 VIs, mainvi.vi which is just a loop displays the count*2 (number of seconds passed since running) that will call subvi.vi and then check to see if the stop button is pressed.  mainvi.vi is by no means a state engine, it is just a simple loop for demonstration purposes.  subvi.vi just waits 2 seconds and leaves, it is a better structured state engine with an init state to start a poll case to wait for events and an exit state to clean up.  You can modify this any way you wish to get it to do what you want.  You will note that even if subvi.vi is being executed, it will terminate immediately when the stop button is pressed.
    Hope this helps.
    A
    Attachments:
    mainvi.vi ‏17 KB
    subvi.vi ‏33 KB

  • How to use elapsed time function with state machine in Lab VIEW

    Hello
    I've been trying to use state machine with elapsed time function in order to sequentially start and stop my code. The arrangement is to start the code for 1 minute then stop for 5 minutes. I've attached the code, the problem is when I place the elapsed time function out of the while loop it doesn't work, on the other hand when I place it inside the loop it does work but it doesn't give the true  signal to move to the next state. 
    Could you please have a look to my code and help me to solve this issue.
    Regards 
    Rajab
    Solved!
    Go to Solution.
    Attachments:
    daq assistance thermocouple(sate machine raj).vi ‏436 KB

    Rajab84 wrote:
    Thanks apok for your help
    even with pressing start it keeps running on wait case 
    could you please explain the code for me, the use of Boolean crossing, increment , and equal functions 
    Best Regards 
    Rajab 
    OK..I modded the example to stop after 2 cycles. Also recommend taking the free online LabVIEW tutorials.
    run vi. case statement goes to "initialize", shift registers are initialized to their constants. goto "wait"
    "start"= false, stay in current state. If true, transition to "1 min" case
    reset elapsed timer with True from shift register(counter starts at zero)."time has elapsed"=false, stay in current state(1 min). If true, goto "5min" case
    reset elapsed timer with True from shift register of previous case(counter starts at zero)."time has elapsed"=false, stay in current state(5 min). If true, goto "1min" case. Also, bool crossing is looking for "true-false" from "5 min" compare function to add cycle count.
    Once cycle count reaches 2, stop while loop.... 
    Attachments:
    Untitled%202[1].vi ‏42 KB

  • Relay Testing with State Machine

    Hi,
    Yesterday I very kindly had some help from "crossrulz" in setting out the following procedure.  Today, the National Instruments representative called and said I should implement my programme as a "State Machine", which I have attempted in the programme attached.  I was wondering how I might now implement the procedures 3 to 5 in this State Machine format as it seemed very complecated in the brief time we had. 
    What I am trying to do is test relays, using an automated test procedure.
    The procedure takes the following steps:
    1.       A NI9472  DO card and transistor drive turns the relay on/off via energising the coil (needs the time period to be variable).
    2.       Counts how may cycles the relay contacts have operated, this will easily be in excess of 100,000 cycles.
    3.       Every 100 cycles (again variable), the contacts are held closed, the load circuit (the current the relay is switching, which will be 15A at 30V) is disconnected, via another relay and a measurement is taken via a separate four wire method.  This consists of a 6V supply being placed across the contacts (switched in again via a relay) with a 1A current flowing through the contacts, the voltage drop across the contacts is then inputted into the NI AI NI9219 card (this is in the region of 10’s of mA) and is directly proportional to the contact resistance, which is what I want to measure.
    4.       The measurement is taken and stored and the measurement circuit disengaged, the load circuit re-engaged, and another 100 cycles is counted before the process goes back to stage 3.
    5.       This process goes on until the relay fails and hopefully a large set of contact resistance data is gathered.
    I have no real experience with NI Labview.  
    I have looked at the basic academic tutorials and have come up with the following programme for stage 1, however I can't get the DAQ Assistant to output every cycle
    Would this be a very difficult programme to implement for the novice?  The academic tutorials seem straight forward but when I try to do someting it seems very difficult.
    Hoping someone may be able to help, thanks
    Andy
    Solved!
    Go to Solution.
    Attachments:
    Relay Test State Machine.vi ‏207 KB
    Relay Test State Machine.vi ‏207 KB

    Hi James,
    I've tried to implement some logic as suggested.  I can now get the 1A coil to engauge after the nth cycle and I think it's taking a measurement, but can't seem to get the 15 A coil to disengauge at the same moment, which is crucial else the measurement will be across 16 A rather than just the 1 A.  Any ideas?  I just want to get it working so we can get started with testing.
    I'm going to get my supervisor to book me on a course at Newbury for future projects, it's very difficult to pick up of your own back.
    Kind regards,
    Andy
    (Helps if I attach it)
    Attachments:
    Relay Test State Machine.vi ‏209 KB

  • How do you create array of enums for transitions in a state machine?

    Hello,
    I am trying to build a state machine, but, I am struggling with understanding the methods for determining which state to transition to next.  In other words, I have several states, but, I don't want to go in any particular sequence.  If I have states numbered 1 through 10, I want to be able to go 1-4-2-5-6-2-6-1-10 etc. in no particular order. I want the transition to the next state  (and actions) to be determined by the streaming data, which can be random and require access to any of my 10 states at any time and in any sequence.
    I saw this picture on the "Application Design Patterns: State Machines" white paper, but, it leaves out some important details.  How does one create the structure in BLUE shown in 3C?  When I try to create this array of enums, all of them are the same. I am not able to make a list of different enum values.  In other words, when I type in "2", then, all the values in the array display as "2."
    There is a nice, simple video example of a state machine for dispensing soda for $0.15, however, this state machine moves in a single sequence, from 5 cents, to 10 cents to dispense; it does NOT illustrate how to select a state "out of order."  I need to understand how a state machine can move from "5 cents" state to dispense directly, with the addition of 10 cents to the "5 cents" state.
    Can anyone suggest a really good tutorial on how to make the selector work in a state machine?  I have been reading some of the available material on ni.com, but, I can't find a good detailed explanation of how to do it.  I remain confused. 
    Or, can you just explain how they created the BLUE array in the attached picture?  Maybe I can figure it out from there.
    Thanks,
    Dave
    Solved!
    Go to Solution.
    Attachments:
    next state.jpg ‏75 KB

    Hi Kathryn,
    Yes, this is EXACTLY what I want to accomplish...
    So it would basically run:
    State 1
    Read input
    Determine next state (say 3)
    State 3
    Read input
    Determine next state
    State
    Read input
    Determine next state
    And so on...
    But, I am quite new to programming Labview state machines, and can't figure out how to even start when the sequence of states is random instead of fixed!!! I can do 1,2,3,4, like the vending machine VI example, but,  not 1,3,2,2,2,5,2,1 etc. based on external input.  Is there some simple example case I can study?  I can't believe I am inventing this for the first time.
    "select the state to run" 
    But, HOW do I do this???????   This is exactly the question I am asking...how is this done?  Please see the attached 3-state system....how do I hook this up????  I am totally lost here...can you help me understand how to wire this thing??  In this simpe RED/GREEN/BLUE case, my input is just the number a user would input on the front panel....  Apparently, there are two files necessary... a vi and .ctl???  What  is .ctl?
    Thanks,
    Dave
    Attachments:
    forum nov 12 red green blue.vi ‏7 KB
    forum nov 12 red green blue.ctl ‏5 KB

  • Advantages of Using Queued Message Handler vs. Standard State Machine

    Hello,
    What are the advantages of using a Queued Message Handler?  Also, why are they more powerful than using Standard State Machines?
    Thanks!

    They are really just sort of an extension of a state machine.  The general idea is that you have one loop doing a specific job.  You then use a queue to tell it how/when to do this job.  For instance, I might have a log file loop.  I will send it commands to open a file, write some data, write some more data, and finally close the file.  Each of those commands are coming from the queue.  The beauty with this setup is that anybody that can get a reference to that queue can send the command to that loop.
    So the QMH is "better" than a state machine mostly because of the decoupling of functions.  In a given application, I will have a loop for log file writing, GUI updates, reading of a DAQ, instrumenet communications, server communications, etc.  Trying to do all of that in a single loop state machine is a major pain in the rear end.  Seperating them out makes life so much easier.
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines

  • New LabHSM Toolkit - Agile development of complex event-driven maintainable LabVIEW applications with active objects / actors based on a universal Hierarchical State Machine / statechart template.

    Dear Fellow LabVIEW programmers:
    Most of the systems you deal with are reactive. It means that their
    primary function is constant interaction with their environment by
    sending and receiving events. But most likely, they can have something
    happening inside them too, even when they are not processing messages
    received from outside. So, such systems have to continuosly react to
    external and internal stimuli. Right? Moreover, most likely, they
    consist of subsystems that are reactive too and, in turn, can have
    their own "life", to an extent independent from other parts (with
    which they still communicate, of course). Reactive (event-driven)
    systems are more naturally modeled with active objects. So, why then
    should we try to model and code them with GOOP and its passive
    ("dead"!) objects?
    "Flat" State Machines have been known for decades to have severe
    limitations. It's been more than 20 years since Dr. Harel invented
    Hierarchical State Machines (statecharts) to fight those limitations.
    Then why does NI still tout the same old good Moore FSM as the
    ultimate tool for event-driven programming in LabVIEW in its $995
    State Diagram KIt?
    The LabHSM toolkit we are happy to present, makes it possible to
    easily create and then maintain complex event-driven applications in
    LabVIEW as a collection of HSM-driven active object VIs using a higher
    level of abstraction and agile software development methodologies.
    These active object VIs are created based on a universal Hierarchical
    State Machine ( HSM or statechart ) template. So. all your code looks
    similar regardless of its functionality!
    We all love just jump to code, right? However, to be good boys, we
    need to do design first. Then implement it in code. If the logic is
    modified we need to redo the design first and then redo the code. When
    using LabHSM where behavior information is abstracted into a separate
    HSM data file editable with a supplied editor, there is no need for
    coding separate from design any more. The modified behavior becomes
    code automatically as soon as the HSM file is saved. Design is code!
    The implementation basically follows Dr. Samek's Quantum Programming
    paradigm. (see http://www.quantum-leaps.com). However, as already
    mentioned, LabHSM stores the behavior information in a file separate
    from the code itself. It also adds state dependent priorities to
    events, a separate queue for public events/messages, and, of course,
    some LabVIEW specific code like capturing front panel user events and
    putting them into the private Events queue. Communication and
    instantiation functions are also rather specific for LabVIEW.
    It is available for UNLIMITED PERIOD trial. Please visit
    http://www.labhsm.com for details and download. The site also contains
    references which you may want to check to learn more about
    hierarchical state machines and active object computing.
    Since this is our debut we will appreciate any comments and
    suggestions. Our contact information is available on our site, of
    course.
    Have a G'day!

    Symtx is currently hiring the following position. Please contact me if interested.
    Amy Cable
    Symtx, HR
    [email protected]
    Symtx, the leading supplier of functional test equipment, hires the brightest & most talented engineering professionals to design & manufacture complex custom electronic systems for advanced technology leaders in the defense, aerospace, communications, medical, transportation & semiconductor industries. Symtx’ challenging & dynamic work environment seeks to fill openings with highly qualified electronic engineering design professionals.The ideal candidate will be responsible for defining the requirements, software design and code development, and integration of test control software for custom functional test systems. Candidate should be familiar with data acquisition concepts, instrument control, complex test, measurement and calibration algorithm development and definition and implementation of control interfaces to hardware. Prefer familiarity with instrument control via GPIB, VXI, MXI, RS-232 desirable. Requires BS/MSEE and 3 -7+ yrs of experience in one or several of the following test applications in a Windows NT/2000/XP environment using Labwindows CVI, TestStand, Labview, Visual Basic, C++ and knowledge of RF systems is a plus. Job responsibilities will include software design, development, integration, team leadership, and interfacing with customers( includes PDR’s & CDR’s).

  • Producer consumer vs state machine

    Hi there,
    I have been on and around for quite a while to understand how can I re-design an application, which was originally built using a mix of sequence structure, while loops and event structures. And now I am making a newer version of the same application, for research purposes, while learning the LabVIEW techniques. Earlier I used LabVIEW versions 5 and 6 to make simple programs for fuzzy logic and neural networks. And that's not a good reference.
    Ok, after learning that Producer Consumer (PC) and Standard State Machines (SSM or SM) are two new approaches for a better (scalable, flexible and efficient) coding as suggest by veterans, in one thread where I asked about another issue, I have started digging into this topic and now I am on a point where I have to implement it finally (spent pretty much time in the learning phase).
    I have several questions.
    To start the discussion, I would give a brief description of my application.
    It's a networked application, where the network communication happens using DataSocket (one reason to use LabVIEW as the environment).
    We are talking about the client application, which communicates with other applications on remote computer, via Internet.
    User interface involves a tab control, with several pages-
    On startup, the controls/indicators (now onwards referred as controls only), are initialized, datasocket connection is checked (rather internet is checked, and a connection established with the remote datasocket server) (page 1)
    If connected to the datasocket server, the user selects Login/Registration (page 2)
    Login and/or Registration happen on page 3/4
    Then the user sees a table of remote users to connect to (page 5)
    Upon selection of a remote user, and after clicking on "connect", the user will see a video indicator, with a lot of other controls. (page 6)
    On this page with video indicator and controls, the user has a lot of activities, in which many messages are sent and received to/from the remote machine.
    the user may disconnect and go back to page 5, and log out and go back to page 2 and so on.
    I hope this is clear.
    I have thought about two different ways to do this application. Using PS or by SSM.
    In the attachments, I have given a diagram (with errors, of course, because of unlinked controls), for each of the approach, plus the original application's diagram.
    I hope this is sufficient for anybody to understand my case and give suggestions.
    I am looking for suggestions about which is a better model for my type of case. I have been to discussions like this one and saw that there are many issues regarding dequeue in PC model. So I am curious to know if SSM is a better and latest model or it's more primitive? Which looks better for my application's performance?
    Thanks ahead!
    Vaibhav
    Attachments:
    OldDesign.vi ‏41 KB
    PCDesign.vi ‏42 KB
    SSMDesign.vi ‏46 KB

    Vaibhav wrote:
    @ Harold
    Thanks. Any suggestion how can I start and stop that loop in parallel with other loops? Like, if some event occurs, the loop should start execution, and keep on moving, while other events are being traced and executed.
    In those examples where you had a while loop inside a case structure, that bit of code will only execute one time.  It will immediately read the boolean at the start of the program, if the value was true before the porgram started, then the while loop will run.  Once that while loop stops, the case structure will end.  It will never execute again unless you completely stop and restart your program.  If the boolean is false before the program starts, the false case will execute immediately.  Nothing happens since it is empty and it is done, never to run again (unless you stop and restart your VI)  You should turn the structure around.  Put the case structure in the while loop.  Make sure you put a small wait statement in the loop so that it doesn't run full speed eating up CPU cycles just polling the status of the boolean.
    @ Ravens
    Thanks for the detailed comment.
    One thing I would clarify. The user will not be able to switch between the pages using the tab control. The program will direct appropriate page to the user. I kept the tabs visible just for your idea of the pages. Sorry, I didn't mention that.
    Do you think it's still a bad design?
    If the tabs will be hidden or disabled, you will probably be okay.  I wouldn't call it a bad design.  I wouldn't do it that way.  But as long as you understand the possibility of problems and prevent that.  Especially some time down the road when you modify the program in some other way that could lead to a problem because you forgot about the dependencies of the event structures on the state of the state machine. 
    Yes, I agree about only one event structure to handle all the events. But since the user will not be able to click somewhere else, other than those possible controls, I thought to keep it like this.
    I thought the events are captured only if we are in that case. I think I am wrong, right? Events are captured at any time, even if the case has never executed before, or will never execute.  Ok, The events will be captured, but will not be executed until in that case.
    And that's the reason why I have two separate event structures, in two separate phases of the program.
    Because, prior to page 6, the events will occur sequencially. The user will click somewhere, then some message will be transmitted over DataSocket, then some message may come , then again some user action and so on. But, when the user starts using page 6, there will be parallel process of user controls events and actions, and incoming messages and corresponding actions. For this, in the page 6, I need a different kind of execution. So I separated the two event structures.
    At first I thought to have SSM, and then I thought to PC, just because I can have two separate parallel processes - one for user events, and another for messages (because that way I can take maximum advantage of message tracking). But looking at other complexities, I find SSM more appropriate. Can you please tell me how can I have my message loop and events loop parallel to each other and just one event structure?
    You can have a dequeue function in your state machine loop and have it be a consumer loop.  Use a timeout on the Dequeue.  If there is a timeout, have the statemachine execute normally after that perhaps just passing the enum wire straight into the case structure of the state machine.  If it doesn't timeout meaning you got a message, then look at the message that is dequeued and act on it.  Perhaps it means ignoring the enum coming in from the shift register and changing the enum to something else to feed into the case structure of the state machine.  Attached is an example
    Attachments:
    PCDesign[1]_BD.png ‏6 KB

  • Producer Consumer with a state machine within the consumer

        Hi All,
    I have been trying to develop a data acquisition system with the producer consumer architecture.  To the left of the two main loops I initialize the serial port and any constants and variables im using.  I also have an obtain queue VI needed for enqueue and dequeue. Then in the producer loop i have a state machine.  The first state is where I wait for a button press on the front panel to write a GO signal on the serial line which will tell the device connected to the serial port to begin sampling data.  After this button press I go into the next state which is called my read state.
    In the read state I use a property node to read all of the available bytes at the serial port and then enqueue this collected data into a queue.  The state machine then is directed to continously go to the read state again and collect more data.
    Now this is where my dilemma is......  The consumer loop has the dequeue VI inside it and after this VI i have a state machine (while loop and case structure) which contains the following states
    1.  Build Array - build an array from the dequeue element and if there is any left over data from the parsing states it will build an array with the left over data and the dequeued data
    2.  Determine packet type - this state looks for the packet type byte(not necessarily the first byte in the message) and also check the next byte (packet length) to ensure that I am at the begininng of this chunk of data.  This state may be a little slow because there can be three different packet types and based on this byte and the packet length it may have to search the array several time to find the valid starting point.  This state also determine the next state to go to based on the packet type.
    3 packet type 1 parsing - parse data and store the remaining data it leftOver array.  Go to exit state.
    4 packet type 2 parsing - "" ""
    5 packet type 3 parsing - "" ""
    6 exit - leave this state machine and fall back to the consumer while loop.
    After it exit I think it should fall back to the consumer while loop and dequeue more data and enter the state machine again to build a new array with the dequeued data and leftover data.  It seems to work when I trace the execution using the Highlight execution feature, however when I run this all at full speed, it seems to go into the consumers 1st and 2nd states back and forth and not completely go through the state machine.
    I tried adding in a delay in the producer loop to give the consumer loop time, but I didnt notice any difference.  Is it possible that my dequeue element is retreiving more data while im still in the state machine, causing the execution to leave the state machine before it finished all states?
    Is there a better approach to take to solve this problem. Basically I need to read data at a 1,000,000 baudrate and parse it as quickly as possible so that I can break it up into 3 different packet types, write the data to a file, and graph the actual data (header info removed) in realtime.  I need to also ensure that I am not losing any of the collected data.  Data loss cannnot occur.

    A couple of things more to go along with Ben's pointers:
    You convert your data from a string, to a U8 array, to a Hex string array in the producer loop, then convert back to a integer to determine what to do with it.  In the process, you create two or three copies of your data, slowing yourself down quite a bit.  The code would be quite a bit more efficient if you left the data as a U8 array.  You can change the format of the controls and indicators to show hex values instead of integer by right clicking on them and selecting Format and Precision...
    Your search code is fairly inefficient.  I made a whack at making it a bit better.  See attachment below.
    If you continue to run into race conditions, you can debug them using a calls to the Windows debug write sprinkled liberally about your code.  Check out the post here for more information.
    Don't let your lack of format LabVIEW training stop you.  The biggest thing to get is the data flow paradigm (aka data is wires, not registers).  Once you get past that and learn how to pass data around using shift registers, queues, events, etc, you are most of the way to mastering LabVIEW.  The rest is just learning the plethora of functionality LabVIEW gives you (yes, I have reimplemented LabVIEW native code more than once in the process of learning).
    Let us know if you need more help.
    This account is no longer active. Contact ShadesOfGray for current posts and information.
    Attachments:
    serialUtil_V3_DFG.zip ‏137 KB

  • State machine VS producer consumer architecture - Time Analysis

    After learning various methods to program efficiently and learn how to use SM and Producer consumer. I built a program to control stepper motor in both these techniques.
    Here is the RESULT. As we can see a simple state machine without any complicated producer consumer technique performs faster than the second one.
    I am not sure which is still the best based on performance and optimization. Please advise which one should I keep and why.
    Abhilash S Nair
    Research Assistant @ Photonic Devices and Systems lab
    [ LabView professional Development System - Version 11.0 - 32-bit ]
    LabView Gear:
    1. NI PXI-7951R & NI 5761
    2. The Imaging Source USB 3.0 monochrome camera with trigger : DMK 23UM021
    OPERATING SYSTEM - [ MS windows 7 Home Premium 64-bit SP-1 ]
    CPU - [Intel Core i7-2600 CPU @ 3.40Ghz ]
    MEMORY - [ 16.0 GB RAM ]
    GPU - [ NVIDIA GeForce GT 530 ]

    This is with state machine alone
    Abhilash S Nair
    Research Assistant @ Photonic Devices and Systems lab
    [ LabView professional Development System - Version 11.0 - 32-bit ]
    LabView Gear:
    1. NI PXI-7951R & NI 5761
    2. The Imaging Source USB 3.0 monochrome camera with trigger : DMK 23UM021
    OPERATING SYSTEM - [ MS windows 7 Home Premium 64-bit SP-1 ]
    CPU - [Intel Core i7-2600 CPU @ 3.40Ghz ]
    MEMORY - [ 16.0 GB RAM ]
    GPU - [ NVIDIA GeForce GT 530 ]
    Attachments:
    Control 1.ctl ‏6 KB
    Control 2.ctl ‏6 KB
    Motor-UNI_Directiona Dev 3-TIME_ANALYSIS-2.vi ‏54 KB

  • Create Multiple tasks for Single Item in List using state machine workflow in sharepoint

    Hi,
    I want to create multiple create tasks for Single Item in List based on Assigned to column using state machine Workflow through visual studio
    Here Assigned to column allows multiple users. so i have to create task for every user based on column .
    I'm trying for this but i didn't got any solution
    Please provide solution for this.

    Hi,
    According to your post, my understanding is that you wanted to allow multiple users to approve.
    There are some articles about creating parallel tasks in state machine workflow, you can have a look at them.
    http://www.codeproject.com/Articles/477849/Create-Parallel-Task-in-State-Machine-Workflow-in
    http://msdn.microsoft.com/en-us/library/office/hh128697(v=office.14).aspx
    http://social.technet.microsoft.com/Forums/office/en-US/b16ee858-4360-479a-a686-4ee35b7be9db/sharepoint-2010-workflow-creating-multiple-tasks?forum=sharepointdevelopmentprevious
    Thanks & Regards,
    Jason
    Jason Guo
    TechNet Community Support

  • Adding multiple states in state machine

    Hi all,
    I have a state machine with many states.  I am using an enum to select state.  I didn't add all the state in the enum at the beginning, so I am adding more statess to the enum and to the state machine as I go.  I found the following pretty troublesome.
    If after I made the first 3 state, and I realized that that next 3 states are very similar to the first 3 states.  I want to copy duplicate the first 3 case all at once, instead of duplicating one case at a time.
    If I duplicate one state, and the wrong enum is assigned to the state, is there a quick way to change it? 
    Are their anything out there that would help plan and keep track of the state machine?
    Let me know if you have any cool tips to speed up state machine development, especially topic on enum and case structure (adding, deleting, multiple copy, etc).
    Yik
    Kudos and Accepted as Solution are welcome!

    jyang72211 wrote:
    after I made the first 3 state, and I realized that that next 3 states are very similar to the first 3 states.  I want to copy duplicate the first 3 case all at once, instead of duplicating one case at a
    If at all possible, never copy and paste code that is very similar to another piece of code! Try to write modular code. If there are several states that are almost identical except for a few slight differences, wrap those differences in a small case structure within the case.
    If you ever find yourself tempted to copy and paste a diagram of code that is larger than a POSTAGE STAMP, reconsider!
    a.lia-user-name-link[href="/t5/user/viewprofilepage/user-id/88938"] {color: black;} a.lia-user-name-link[href="/t5/user/viewprofilepage/user-id/88938"]:after {content: '';} .jrd-sig {height: 80px; overflow: visible;} .jrd-sig-deploy {float:left; opacity:0.2;} .jrd-sig-img {float:right; opacity:0.2;} .jrd-sig-img:hover {opacity:0.8;} .jrd-sig-deploy:hover {opacity:0.8;}

Maybe you are looking for

  • How to search for text inside multiple pdf file at once in ipad

    Hi I am student and i need search a word or subject or sentences on my all pdf files,i have tested some applications like ibook, ipdf, addobe reader, good reader ,....  But couldn't find what i need to have. Please kindly help me to find the best app

  • Reports Graphics and OAS 10g

    I made a report with a pie char in developer 10g, it runs OK and i see the char in my desktop. When I execute the report (.rep) in OAS 10g (Forms a Reports Services) via the rwservlet, the resulting PDF file contains everything but the chart doesn't

  • Less wifi with ios 7

    Hi since I installed the new IOS 7 I have less wifi in my ipad. I usuakky got full range (three lines) and now I have only one and it takes ages to download. I am in the same room as before. Anyone has the same problem?

  • Rtmp not connecting, sample video not streaming

    I am developing an application in Flash that runs locally and it uses FMS 4.01, locally. I have been using adobe FMS 4.01 for months with no problem. Today I cannot connect to my server and I cannot even play the sample video on the Flash Media Serve

  • How to use .class files from jsp

    hi i want to use .class files in my jsp program can any one help me