Simple state machine Where to begin?

Hello
Got a question that is simple for the experienced people here I guess. But don't know where to start..... Here is what I want to try to do:
I have got a lot of inputs, to keep the question simple I have only drawn a few of them but eventually there will be tens of inputs. For now I will only use the front panel and no real IO box (hardware), just to see if I can make a State machine that can handle this "problem" in a organized / proper way.
What I want is to do is read a sensor, for example sensor B1 and multiply it with the multiplication factor (column Process input) and show the result on the front panel.
There will be different types of sensors, some need multiplication, others sensors need just a constant be added to the input before the result is shown in the Result column etc.Of every sensor there will be a lot, so just wiring them all in one place will create chaos, and I don't like chaos (only dr chaos in South park is fun but I would not have him in my labview code either).
Can anyone tell me how to approach this "problem" ?
Thank you for the advice!!

Hello altenbach,
thank you for your reply,
I think the question might not have been completely clear. I can devide the question in different parts I think. I will give it a try lets see
(1)There Will be a lot of sensors and a lot of different type of sensors. There will be sensors that behave:
(A)as a switch Called them Type A in the picture
(B)as a voltage source For example mV per degree celcius
and then there are more
(C)sensors that behave as a current source
(D)and a other type of sensor
ow noooo there are more
and even more
(K)sensors that have got a voltage output but measure something else as B for example a distance.
Of every type of sensor there will be more than 1 sensors. So there could be 10 sensors of type A 8 of type B 15 of type C etc. It would also be nice to ad or remove a sensor after a while.
The sensors need to have a usefull name. Like "Temperature in chamber A". I want to be able to use this name everywhere in the code. So I if I need to process the "Temperature in chamber A" I want to have a human readable name. (type def?).
I think I need to have a other name to indentiefie what kind of sensor it is: temperature, distance etc. This would make it easier to make a subfunction or SM deciding how to handle this information.
So I think the question should be how can I make a big highway of data comming out of the front pannel in one wire, If I have wire's A till K the code will become unreadable. I was thinking of some kind a arry of strucs?
I tried to keep the qestion as simple as possible at first but maybe it made it too unclear I think the question might sugest it will stay a simple program but it will not, it is just a first step.
The first step I want to try is to just multiply a voltage with a number (just to test the functioning of the supper-highway of data).
If I know that that works I will try this superhighway of data in a State machine then the value will to be prosseced in different ways.
After that I hope to have the Hardware IO It is a NON FPGA frame with a few cards in it from NI, cabable of measuring digital IO analog IO etc analog output etc. So at that point the frontpannel will be party replaced for the HArdware IO. As I want to test the software in different stages of development I first wanted to start simple so I could test the written software in different stages of development.
So can anyone tell me how to get this supperhighway of data out of the fron pannel?
I hope the question is a clear, if not just ask.
Thank you for the help so far!!

Similar Messages

  • Simple State Machine Vs Queued State Machine

    Using LV2009 + WIN7+Pentium 4 @ 2.5Ghz with 3 GB RAM.
    I have a machine control code inside a 10mS main loop that has 7 ( yes seven ) Queued State Machines (  QSM) and I find the  Finished Late boolen keeeps poppping often. Not a very good sign if you ask me.
    And the code itself does not have too much of computation or FP activity. But it has four Graphs with one plot on each of them. These are updated once every 10ms. Can slowing this update ( say once every 250ms ? ) help ? 
    A simple query : In terms of performance overhead, does a QSM  demand more than a  Simple State Machine ( SSM ) ? Can I avoid the Finished Late warning by switching over to SSM at least in three of the cases out of the seven ?
    Thanks 
    Raghunathan
    LV2012 to Automate Hydraulic Test rigs.

    I think your question demonstrates my point.  Unfortunately, I don't have a good example to point you to and don't have the time to write one.  I will try to explain better.  Let's take a simple example - a landscape watering controller (sprinkler controller).  This controller will have several states (e.g. initializing, waiting, watering, closing). Each of these states will accept several commands, but not all commands are accepted in all states.  For example, if the system is watering, a command to start watering could be ignored.
    In most programs, at least some states should be interruptible.  For example, if it starts to rain, the watering system should stop watering immediately instead of watering for a set length of time.  However, if the system is in the initialization state, this will probably not be interruptible (but also short).
    As you said, the classic LabVIEW way to implement such a thing is to have a case statement to represent the state, and a case statement (usually queue driven) in each state frame to handle the commands.  You thus have a loop with a double case structure.  This can get somewhat unwieldy for large programs.  Note that which case structure represents what will be determined by the relative number of each item. For example, if you have fifty commands and three states, the state should go into the command case.
    So how do LabVIEW classes help?  They can eliminate one or both levels of these case structures through the use of dynamic dispatch.  This is done as follows.  A parent class is created that is a generic command.  It has commands for each state.  For each actual command, a class is derived from the parent class.  There are VIs in the specific command class for each state.  A command is generated by creating the correct object for the current state, then calling the parent class command.  Dynamic dispatch will execute the code for the correct command.  The command execution loop is then reduced to a single command VI which dynamically dispatches based on the actual command and the current state.
    In practice, things as usually not quite this simple, and you may want different cases for either different commands or different states so that you can change the connector pane of the dynamically dispatched VI as needed.  Look up the LabVIEW examples on dynamic dispatch to see this in action.
    I am afraid I have still not made myself clear.  Keep asking questions and I will try to keep answering.
    This account is no longer active. Contact ShadesOfGray for current posts and information.

  • State Machine Demo

    Hi Folks,
    I am a newbiew LabVIEW developer studying & working towards my CLAD certification.
    I already took LabVIEW Basics I & II and I decided to make a simple state machine (please see attached VI).
    I was hopping if there is anyone out there who find a way for the VI be optimized so I can see my weakness.
    ThanX in ADVANCE!!!!!
    Attachments:
    StateSimulatorfromEE428.vi ‏71 KB

    Overly complicated and convoluted is the word.
    I haven't even tried to undestand what you are juggling with all these string operations, but there's gotta be a better way!
    Case 4 and 5 are identical except for a diagram constant. They can be comined into one case.
    "state operation" is a control, but you are constantly writing to it via local variables. This mean it cannot be reliably operated, because the set value could be reset before it is used due to race conditions.
    It is confusing that you replace the "state" of a typical state machine with a "state operation", while the "state" is actually in a string that does not really influnece operation. Whatever you have is not a state machine.
    In state operation=2 you delete from the 2D string array, but later you always seem to iterate over 9 elements (one too many to begin with) in the inner while loop.
    Since the 2D string array can shrink but never grow, you might stop the program once its size reaches zero.
    You write to a local variable in virtually each state, it would be more reasonable to pull this local variable write before the case structure.
    The attached quick modification illustrates some of the above points. This is not a finished or even reasonable program. It would need a complete rewrite.
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    StateSimulatorfromEE428MOD.vi ‏64 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

  • Terminate state machine

    Attachment is the simple state machine i did and for ur better understanding.
    I have a state machine and which initially is at case "wait". After pressed the start button, it go to case "First" which sum the values and then got to case "Second" which subtract the values. And it will back to the wait again.
    Wait i wish to is
    1) I wish the state machine to stop after the case "Second" or after subtract the 2 values and switch on the LED (2nd Sequence) in the second flat sequence frame.
    2) I only want the loop to run for one time only and do not repeat.
    Thanks for ur help and time or reading.
    Attachments:
    Simple State Machine.vi ‏18 KB

    neiviv wrote:
    Hi Mathan,
    Is it possible to save the VI in labview 8.0 version
    You don't need it. Pnt's solution is better because it does not use local variables.
    neiviv wrote:
    I added a TRUE to stop the loop but it did not stop and continue back.
    Are you using the "continuous run" button to run the VI???   Don't!
    Use the plain Run button!.
    LabVIEW Champion . Do more with less code and in less time .

  • Elapsed Time delay only works once in state machine

    Hello.  I'm having problems using the elapsed time delay to show the seconds remaining on a wait step in a simple state machine.  I would like to have a front panel count down showing the time left for the step.  I thought the elapsed time delay was the way to do this.  The problem is the vi runs correctly the first time through.  But then after that the timing does not seem to reset back to the times I had set.  If I remove the elapsed time delay and just stick a wait time in the state, the vi runs as I would expect.  This just doesn't give the user an idea of the time remaining.  What am I missing when using the elapsed time delay, or is this just the wrong tool for the job?
    A smaller issue is that I would like to move the tasks, in this case the LED's outside the loop so I don't have to repeat code.  But when I tried moving them outside with only leaving the constants inside the state they did not work as I expected.  If you have tasks like the operation of a set of booleans that you are used in several states, what is the cleanest way to do this without repeating code?
    Thanks for the help.
    Danny
    Solved!
    Go to Solution.
    Attachments:
    Elapsed Time Delay.vi ‏39 KB

    The problem is that the Auto Reset on the express VI resets the start time of the timer as soon as the time has completed.  So you are essentially restarting the #1 timer immediately and then go on to #2.  Once #2 is completed, #1 has already passed 10 seconds as well.
    What you need to do is use the reset input for the express VI, but only have that be true the first time it is called.  By using a shift register and the implies function on those loops, you can do that.
    As for the duplication of states, don't have a state 1 and a state 2.  Just have a Run state.  Use a shift register to maintain a value for what your next state will be and a case structure to based on that to show what booleans should be lit and what the next state will be.
    Message Edited by Ravens Fan on 06-12-2009 10:56 AM
    Attachments:
    Example_VI_BD.png ‏2 KB

  • Problem with state machine

    Hi! I've got a VI intended to control a storage tank. I've tried to do that by creating a simple state machine that changes the value(on/off) of some valves basing on 2 conditions:
    -when a certain temperature reaches a pre-set value AND its derivative is <0, the state must change from on to off,
    -when some time passes the state must change from off to on.
    Unfortunately I can't get this work as it never changes state (e.g if I start with on always remain on "on" and viceversa).
    Could you please tell me what I'm doing wrong? I'm attaching the screenshots of the 2 states.
    Thanks!
    Solved!
    Go to Solution.
    Attachments:
    screenshot1.jpg ‏302 KB
    screenshot2.jpg ‏300 KB

    It looks like your shift regsiter might not be wired correctly.
    Attachments:
    screenshot1.jpg ‏303 KB

  • Queued State Machine skipping states?

    Hi,
    I started out writing my application using a simple state machine but I realized it was necessary to make the application more interactive and prevent the UI from freezing when interupted. For example, I want the user to be able to abort the test by clicking the stop button or a reset button that sends the state machine sequential flow to the reset state.
    I implemented the my QSM by looking at the example in the link below.
    https://decibel.ni.com/content/docs/DOC-14169
    However, the problem now is that the state machine no longer runs sequentially as in my initial simple state machine. Sometimes a state is repeated and at other times a state is skipped. By skipped, I meant it didn't follow the order I tried to implement in my code. I flush the queue before any new user input so I don't know what's causing this behavior in my application.  Has anyone experienced this type of problem before? If so how can it be fixed.
    Thanks

    Hi
    I'm still trying to find a solution to this problem. I was able apply a temporay remedy in an earlier application but in my current application, I'd have to find a permant fix to it.  This problem is described in comment number 4 of the community example code link below. I tried to apply the recommended solution but it didn't work. Perhaps, I was doing it the wrong way. How will the example code be modified to fix the problem described in the comment? I will appreciate any suggestions.  Thanks
    https://decibel.ni.com/content/docs/DOC-14169 
    Comment4
    This pattern has a potential risk of get cycled or get into unwanted states. Let me explain it. When you click on button, an event occurs and typically an element is enqueued to the queue. But in the lower loop another element is enqueued (in this case Report or Process). So when you for example want to go to idle state by clicking on the Stop button, you go to idle state but then you go to report or process state because the element was enqueued behind the idle element as explained above. The solution is to check if the queue is empty before enqueuing the element in the lower loop:
    If the queue is empty, it is safe to enqueue element in lower loop:
    If it is not empty (this occurs when an element is enqueued in the upper loop due to event occurence), the element will not be enqueued:

  • Help with cycling sequence structure, I may need a state machine?

    Hi All,
    So I have this VI that needs to control two solenoid valves by opening and closing them through the digital outputs.
    I want the program to have a function like this
    Phase 1: Valve 1 open, Valve 2 closed (Amount of time for this defined by user)
    Phase 2: Both valves closed (for .1 seconds)
    Phase 3: Valve 1 closed, Valve 2 open (Again, this amount of time is defined by user)
    and I want it to cycle through phase 1-3 100,000 times. However, every 10,000 cycles of phase 1-3 I want it to change the condition on Phase 2 so that both valves are closed for an hour instead of .1 seconds, then after this hour loop I want it to return back to the original cycling conditions (.1 sec instead of 1 hour) until it does another 10,000 cycles.
    I was thinking that a sequence loop would be fine because I would wire it up with timing and a counter, and every time it goes to the last sequence it would increase the counter so that when its at the phase 2 timing I can use a case structure (if counter > 10,000 hold 1 hour, if counter <10,000 hold .1 sec) and then in the last sequence reset the counter to 1 if it is >10,000.
    I thought a sequence structure would be good for this but I'm fairly new to labview and if theres a better way to do this I'm open to suggestions .
    Attached is my code so far, except that I have not finished wiring the ports for valve B
    Attachments:
    Adhesive Pressure Cycling.vi ‏100 KB

    First, you should avoid the use of a sequence structure. Don't even consider it to be an option. At least not at this stage of your learning. Learn how to use data flow. Also, avoid the use of local/global variables. They tend to lead to race conditions which in turn result in some difficult bugs to find and fix. Think of the wires as your variables.
    As for the time delay in your state machine, your actual state should delay for a short time like 100 ms. Use the current time of day to determine when you have reached your desired timeout. If you use a single delay of an hour your program will be unresponsive for that hour. Users tend to get very annoyed if they try to stop the program and they have to wait a long time for it to actually stop.
    Here is a basic example that shows the concept in a state machine.
    When naming states for your state machine give them a meanigful name. Use a typedefed ENUM for your state variable. For simplicity sake the example attached does not use a typedef. But naming things like State 1, State 2 and so on makes the code difficult to read and understand. Your Open/Close valves states can be written in such a way that they are generic and take the valve data as input. At a minimum I would create a subVI to do this so you only have one piece of code to manage. You could have explcit states though such as Open Valve A and Open Valve B that call your generic Open Vavle subVI with the appropriate input data.
    One last comment, the express VIs tend to be very inefficient. They are OK for learning how things are done but I would implement their functionality directly. For example, the express VIs tend to open, initialize, do something, close the instrument. You really don't have to do all of that every time. Open and Initialize once in the begining (hint, this could be a state), put the stuff that does the work in appropriate states/subVIs (other states) and then close at the end of your application (the exit state for example).
    Mark Yedinak
    "Does anyone know where the love of God goes when the waves turn the minutes to hours?"
    Wreck of the Edmund Fitzgerald - Gordon Lightfoot
    Attachments:
    Simple Delay in State Machine.vi ‏15 KB

  • 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

  • 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

  • How do I add new data to the same file in a State Machine?

    Hello,
    I have a State Machine, with a State where 3 samples of data are collected in a For Loop. I would like to save this data in a file and keep adding new data to the same file each time I get to this state. The problem I'm running into is that each time I reach this State, my old data in the Excel file gets replaced with the new data instead of being continuously added in the same file.
    Ive tried Shift Registers but I may not be using them correctly since my file keeps displaying only 3 new data points.
    Any ideas will be appreciated!
    Thank you, so much.
    -Peter

    Where should I place these shift registers? Where should I place my File I/O VIs? Is it possible to use the Write to Spreadsheet File VI in this situation?
    Ive attached a very simple example of the problem. Thank you.
    Attachments:
    StandardStateMachine 2.vi ‏16 KB

  • Discrepancy between execution time of state machine and flat code

    I am trying to optimize the performance of my application, and I've found that the same code executed as a case in a state machine, and flat on the block diagram takes a dramatically different amount of time to run. I'm trying to figure out what I'm missing here. The picture shows a test vi I threw together (the next post will have the diagram image for the "Add New" case of my Buffer Engine.vi - basically the same as what is in frame 5). The fifth frame in the sequence is what I am concerned about. It shows that executing the case in the state machine takes ~700ms, and flat, ~113ms.
    Any thoughts?
    Chris
    Attachments:
    Test Times.jpg ‏124 KB

    Thanks for the suggestion Altenbach. I had to insert a for loop to replace array subset indivually for each column of new data to place in the buffer, but even with the extra processing, the result was about 80% faster. I guess I'll have to come up with a system to track where to place the data (it was convenient to always drop the data at the end..), but that shouldn't be an issue.
    However, this suggestion doesn't address the original concern. The same array resizing was going on in both the subvi and the sequence frame. This improvement should increase the performance of each, but doesn't explain the difference.
    As an aside, I contemplated using a queue, but without the ability to dequeue from both the beginning and the end, I don't see how I can use them for this. I want to trash the oldest data, not hold up the acquisition. In any case, I don't think it would be faster because the memory isn't pre-allocated. Now I am considering just storing the data in a control, and passing the reference as necessary. The question is, is reading the value from a control faster than reading from a shift register?
    Thanks again.
    Chris

  • Finite state machine using jsf ?

    I am building an online payment module and would like to implement it using a finite state machine. I am hoping that someone may give us advice on how to build it with jsf.
    Firstly, I am just beginning with jsf.
    Here is the example: Let's say that in the module there are 7 possible states that the user may be in, each represented by a jsp. I cannot decide where to manage state transitions. One option is to change states in the backer bean of every state, but that is dispersing transition logic across all my backer beans. The other option I can see is to have one single actionListener and have all action events pass through the 'processAction' method, keeping all the state management logic in one place.
    Please comment on either of these two approaches...or any alternatives :)
    Thanks in advance !
    Mark

    Sounds like a state machine in combination with a decorator on the ViewHandler might do the trick.
    Off the top of my head I'd suggest creating a managed bean in session scope that keeps track of the state in the user's session (the state machine). Check the bean from the ViewHandler decorator when a page is requested and direct the user to the correct page if they are trying to navigate to a page that conflicts with what is allowed for their current state.
    Your actionlisteners or action methods could change the user's state in the session as they process their actions.
    http://forum.java.sun.com/thread.jsp?forum=427&thread=502322
    The above thread discusses the use of a decorator to control navigation for authentication purposes, but it should be adaptable to this use.
    Is that plausable or am I smoking crack? :-)
    -jeff howard

Maybe you are looking for

  • Excel sheet with tabs

    Hi all, I have an excel sheet with 2 spread sheets. 1 hidden and other visible. 1) How to read the excel so that the hidden fields dont come into the internal table in which the data is read? 2) when the data is read from the visible tab of the excel

  • Help removing imessage from a phone number no longer being used by an iphone

    Hi everyone. Hoping for some help with a bizarre issue. I switched from an iphone 3gs to an android a few months ago, but when some (not all) friends w/ iphone's text me, it tries to send it as an imessage from their phones. I  don't receive the text

  • Do your versions of catalyst support video?

    Hi, I am really new to Catalyst but I have spent hours on tutorials and I think I am getting the hang of it. The problem I am having is that I cannot seem to add any video to my work. When I go to the Prerelease help page, there is a section on video

  • How do you recompile the kernel for oracle linux 6.3

    Hello, I have installed Oracle linux 6.3 default settings on x86_64 bit pc I have some questions: 1. What public yum repositories contain the oracle linux 6.3 kernel source code ? 2. Is the oracle linux 6.3 kernel source code on OracleLinux-R6-U3-src

  • Can not download iOS 5

    I just bought my Iphone 4 32 g in Canada.  Sync'd it with my Itunes on  my pc.  Will not allow me to update iOS 5 downloads (did both download & install as well as download only) both times downloads but then states that network connection timed out.