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

Similar Messages

  • 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

  • I am having difficulty including text with iPhotos I want to share through email.  I get a red exclamation mark along with a statement stating that the text doesn't fit into the designated text area.  This is so frustrating.

    I am having difficulty including text with iPhotos I want to share through email.  I get a red exclamation mark along with a statement stating that the text doesn't fit into the designated text area.  This is so frustrating. Before iLire11 I was easily able to share photos with email messages.  Arghhhh!

    In the iPhoto preferences you can set Apple Mail as your e-mail client and then it will work exactly as before
    LN

  • HELP!!!! I have spent hours trying to find out how to embed an image with a link or a Microsoft Word document with a hyperlink built within the document -- not as an attachment! Does ANYONE know the secret? Can it be done, or not! My PC clients do it.

    HELP!!!! I have spent hours trying to find out how to embed an image with a link, or embed a Microsoft Word document with a hyperlink built within the document -- not as an attachment into my email -- but where it shows as the email content when opened! Does ANYONE know the secret? Can it be done, or not? My PC clients do it all the time easily. Then I want to be able to send the embedded image/document (not as an attachment, but visable within the email when opened) to many email contacts at once, BUT the individuals receiveing them DO NOT SEE the other email contacts. Cannot seem to be able to find anything on being able to do these 2 tasks.PLEASE, SOMEONE, HELP!!!

    Don't know if this applies to Lion, but read here:
    http://www.makeuseof.com/tag/create-html-announcement-mail-iweb-mac/

  • TFS 2012 - How to Import bulk of historical WI's via EXCEL, with already progressed values in State field within the excel

    A user wants to import into TFS, ~ 500 historical bugs that were created and maintained in an excel template outside TFS. While they were maintained outside TFS, the user changed among others, the value of their Status field as well, i.e. there are bugs
    in a progressed state e.g. already in status Closed.
    Since normally in TFS, one could not directly create a new bug in State = Closed, an error would be yielded when trying to import them as is into regular Team Project. Can u please advise how to easily solve this, without hindering the state diagram of the
    model in TFS, and as possible by utilizing GUI of Excel / TFS / other available tool for this purpose ?
    Kind thx,

    Hi!
    You may use excel features for this. Simply copy & paste the state column:
    Publish 500 new bugs.
    Copy & paste the state column from your source table and publish.
    But the reason for state may not be correct. So you may use the more difficult way:
    For Source table create the custom state columns (for the cmmi template states Proposed->Active->Resolved->Closed) by this rules:
    (Active state column) if (source state == "Active" || source state == "Resolved" || source state == "Closed") { value = Active } else { value = source state }
    (Resolved state column) if (source state == "Resolved" || source state == "Closed") { value = Resolved } else { value = source state }
    (Closed state column) if (source state == "Closed") { value = Closed } else { value = source state }
    Then Publish new bugs.
    Copy&paste (Active state column) values and publish.
    Copy&paste (Resolved state column) values and publish.
    Copy&paste (Closed state column) values and publish.

  • Help me with a state machine design

    I have a little bit of a problem.  I have a system with several modes, each selected by the user and called with a case structure.  Each case in the case structure is its own state machine with a few states (like 4-6).  Now here's the catch.  I need one of the states within one of the modes to call and execute an entirely different mode (and all of its states) without actually changing the mode command, and to do so every iteration until I jump out of that state into another state within the first mode.
    Is there a simple way to do that that I'm just not thinking of?
    Lee Jay

    Lee, my first thought would be to use just a big state machine.  For example if each mode needs 4 states, mode 1 gets states 0-3, mode 2 get states 4-7, and so on.  This way, if you need to change modes in the middle of another mode, you just direct the state selector to the state that starts the mode.  (If that makes sense).  It's not real elegant, but it works fairly well as you still maintain the flexibilty of the state machine design, including the ability to add and rearrange cases. 
    Don't forget you can use any method to select the cases, including strings, so you have full flexibility with how you setup case select.
    Troy

  • Double Click Property Node not functioning with Queued State Machine

    I am writing an application which relies on input from the operator to start different steps in a process of steps.  I am using a queued state machine, however I cannot get the Double-Click property of my listbox to function with in this Queued state machine.  I have tried Creating a refrence to the Listbox and creating a property node from that refrence.  I have tried a property node of the control.  The double click functon works only if the queueing is not occuring.  It has something to do with the queue but I am at a loss as to what is causing it.  Any help would be GREATLY appreciated.  I have attached a simplified version of the state machine with the double click function.  Thanks for any help on this.  It is written in LV7.1
    Attachments:
    Test Q.llb ‏55 KB

    Hi
    Its  Simple....
    Your Properrty node is not getting read..... dont understand how..
    see the attachment...
    now laugh at your small mistake... (even i have the habbit of making such small mistakes ;-) )
    Message Edited by Tushar Jambhekar on 01-11-2006 11:38 AM
    Tushar Jambhekar
    [email protected]
    Jambhekar Automation Solutions
    LabVIEW Consultancy, LabVIEW Training
    Rent a LabVIEW Developer, My Blog
    Attachments:
    Test Q.llb ‏55 KB
    Picture.JPG ‏44 KB

  • Serial commands with a state machine

    Hi,
    I am reading with VISA from a serial device. I write to the serial the start character and the device is sending some data.
    Now after I read the data I want to stop the sending by writing to serial a stop character. The reading is in a separate loop.
    I want to make a stop button that writes to serial and a start button that writes to serial and reads the data. Is there any way to do this without a state machine ?
    Btw, is there any examples for a Serial reading and writing state machine ?
    Solved!
    Go to Solution.

    Remove your first while loop.  You are initializing the serial port over and over again until you press OK.  You only need to initialize once.  Put all of the code before the loop.  The loop should just delay for a few mS until the OK is pressed.  You should always put a dely in a loop so as not to chew up 100% CPU time.  Even a 0mS delay will allow the CPU time to do other things.
    In the second loop, since you have an event structure, you don't need a delay.  But you do need to wire in a value to the Timeout hourglass icon on the top left corner.  I typically use 100.  Again this is to prevent 100% CPU usage.
    Do you understand data flow execution?  This means that a loop or block of code or a function will not execute until all of its inputs are present.  Your third loop will not start until you press the quit button because you have two wires going from the second loop to the third.  These wires will only pass their data to the third loop when the second loop is over (pressing the quit button).  When you press quit, the second loop terminates and data goes to the third loop.  Now all of the third loop's inputs are present and it can execute.  This is not what you want.  Delete the wires between second and third loop.  Then the third loop will execute from the beginning.  The serial read control will tell it when to read and when not to read.  You will need to pass the VISA Resource Name to the third loop by using a Local Variable.  From your statement, it sounds like you already did this.  Pass a no error condition into the third loop also.  You can make one or use a local variable of error in.
    In the third loop, you have the VISA Close inside the loop.  This is not good.  The VISA session will close before you read.  Move this to after the third loop.  Then it will close only after the third loop stops.
    After you delete the wires between loops 2 and 3, you will have to merge errors from the second and third loops to make sure you catch all errors.
    In each one of your loops, replace the VISA Session terminals and Error terminals with shift registers.  This is good practice and is recommended by NI.  With terminals, if there is an error on one loop iteration, it will get lost because the next iteration takes in the original no error condition from the left side.  With a shift register, the error gets propogated to the next loop iteration.  If your loop executes zero times (For Loops can do this), the output of the VISA terminal will be a null value and the VISA close will cause an error.  With a shift register, even if the loop does not iterate at all, the VISA Session value on the input will be propogated to the output.
    I think that is enough for now.  Please make these changes and re-post your vi.  You are making good progress.
    - tbob
    Inventor of the WORM Global

  • How to read data with different XML schemas within the single connection?

    I have Oracle 11g database
    I access it through jdbc:oracle:thin, version 11.2.0.3, same as xdb.
    I have several tables, each has one XMLType column, all schema-based.
    There are three different XML schemata registered in the DB
    I may need to read the XML data from several tables.
    If all the XMLTypes have the same XML schema ,there is no problem,
    If the schemata are different, the second read throws BindXMLException.
    If I reset the connection between the reads of the XMLType column with different schemata, it works.
    The question is: how can I configure the driver, or the connection to be able to read the data with different XML schemata without resetting the connection (which is expensive).
    The code to get the XMLType data is textbook implementation:
    1   ResultSet resultSet = statement.executeQuery( sql ) ;
    2   String result = null ;
    3    while(resultSet.next()) {
    4   SQLXML sqlxml = resultSet.getSQLXML(1) ;
    5   result = sqlxml.getString() ;
    6   sqlxml.free();
    7   }
    8   resultSet.close();
    9    return result ;

    It turns out, that I needed to serialize the XML on the server and read it as Blob. Like this:
    1    final Statement statement = connection.createStatement() ;
    2    final String sql = String.format("select xmlserialize(content xml_content_column as blob encoding 'UTF-8') from %s where key='%s'", table, key ) ;
    3   ResultSet resultSet = statement.executeQuery( sql ) ;
    4   String result = null ;
    5    while(resultSet.next()) {
    6   Blob blob = resultSet.getBlob( 1 );
    7   InputStream inputStream = blob.getBinaryStream();
    8   result = new Scanner( inputStream ).useDelimiter( "\\A" ).next();
    9   inputStream.close();
    10   blob.free();
    11   }
    12   resultSet.close();
    13   statement.close();
    14
    15   System.out.println( result );
    16    return result ;
    17
    Then it works. Still, can't get it work with XMLType in resultset.On the client unwrapping XML blows up when trying to switch to different XML schema. JDBC/XDB problem?

  • ADF Faces  IF statement available within the  page?

    I am making a page using ADF Faces.
    I want to create an IF statement in a page that will display some markup on one condition and on another display some other markup.
    For example, I am using an iterator to build a table. I would like to have the background color of the row alternate based on the iterator count % 2 ( also how can I get the count of the iterator).
    Also, I would want to make the text color highlight based on some condition such as is foo==bar make the text red etc.
    Anyone know how to do this simple simple task in ADF Faces?
    **Note the if from JSF core is not available in Jdeveloper for whatever reason. Any help would be appreciated.
    Also, I don't want to just set some property of some element based on a condition with EL.
    Lets say there is a whole section of the page that I only want to show is a condition is true. Is this impossible in ADF Faces? Is there something fundamental I am missing about this framework?
    Edited by: user2809800 on Dec 6, 2010 12:49 PM

    For conditional rendering of group of fragments, you can use switcher component.
    See the sample for switcher here: http://jdevadf.oracle.com/adf-richclient-demo/faces/components/switcher.jspx
    Code:
    <af:switcher id="s1" defaultFacet="#{<CONDITION> == 'true' ? 'two' : 'three'}">
    <f:facet name="two">
    <af:outputText id="ot2" value="Two"/>
    </f:facet>
    <f:facet name="three">
    <af:outputText id="ot3" value="Three"/>
    </f:facet>
    </af:switcher>
    For changing the text color based on the condition, you could use the EL expression in InlineStyle (it is a simple case) Otherwise, you can use skinning to change the same.
    Sample:
    <af:outputText id="ot4" value="#{bindings.FirstName.inputValue}"
    inlineStyle="#{bindings.FirstName.inputValue == 'Steven' ? 'color:red' : null}"/>
    Thanks,
    Navaneeth

  • File sharing works with one xp machine, not the other

    Hi folks, I just switched over to Mac! So far so good with my new macbook. I have two identical gateway xp machines. Strange thing is, the macbook connects perfectly to one of the gateways for file and print sharing, but cannot connect to the other. In finder the name of the computer appears under "shared", but when I click on it, after attempting to connect, it says "connection" failed. For the xp machine in question, I have run the home networking "wizard" and have used trouble shooter. The computer has a unique name on the network, and the directories have been set for sharing. I've tried removing the firewall--though the firewall is instructed to permit networking. So, what can I do? Thanks everybody.

    Interesting.
    On the troublesome XP box, set the permissions for your shares are set that "everyone" can read the share. (No need to give write access).
    I am assuming that you are using XP Pro and staying away from "Simple File Sharing".

  • Email will not send to email address with a full stop within the name as it drops the last name ie jim.smith@.... changes to jim@....

    I am trying to reply or send a email to a email address that has a full stop in the username ie [email protected] When the email sends it drops the surname ie [email protected] I have checked the address from the reply and it is correct even if I type it in it still has the same issue. Does anybody have an idea of what I can do. Thanks

    The Addons support forum is over here:
    https://forums.addons.mozilla.org/
    Separate forums with separate login credentials. Unfortunately each forum under mozilla.org was started at a separate time ''[years apart]'', by a different project group, and user credentials weren't centralized. About a year ago the plan was to have [https://login.persona.org/ Mozilla Persona] ''[a centralized login system]'' "consolidate" all the different Mozilla domain login credentials for users, but I haven't seen that even start to happen yet.

  • What's wrong with my State Machine structure? I'm new to LabView

    I've been recently introduced to LabView, and in my current project I've created an "Enum Constant" with 9 items. Le'ts say, for example, each item says:
    "First Item"
    "Second Item"
    "Third Item"
    ...etc
    then I created a case structure, and used the "Add case for every value" option.
    My problem is that later on, I noticed that in the Case Structure, my cases show numbers "0, Default" "1" "2" ...  instead of saying "First Item" or "Second Item" .... etc
    I don't know what in the world I've done to change the display of the values, and I can't figure out the way to change it back lol
    Side Notes:
    --The enum constant (obviously attached to the case structure) still has the same values "First Item" "Second Item" "Third Item"
    --The enum constant (again, attached to the case structure) has a tunnel that goes through a While Loop with a Shift Register, and there's a little coercion dot right there at the input terminal. I don't know what to do about it.
    -- I can't attach the VI for moral reasons, so I tried to explain my problem as simple as I could 

    You should also make the enum a type def. Otherwise you're going to run into synchronization issues if you need to modify the enum list. Without a type def you'd have to update every single enum instance on your block diagram, and it's a pretty safe bet that you'd likely miss on. By using a type def you'd only need to modify the list in one place and all instance of that type def would be updated. The LabVIEW Help discusses creating and using type defs.

  • Why Hiring Actions are not visiable with other login ID within the server.

    Dear Friends,
    I have scenario as follows.
    I have one server and all congiguration is done with one employee login ID also able to see Hiring actions through PA40 in same server. And when we login with other Authorized login id im not able to see those Hiring actions through PA40.
    Parameters are set through SU01, Server is same and both the Login ID has got proper authorizations.
    Please help me out with your valuable suggestions.
    Thanks,
    Shab.

    Hi,
    Go to SU01 and give ur user id
    go to parameters
    and maintain MOL and UGR maintained as country grouping (eg:40 (India)) save and refresh the system
    then try
    Regards,
    naveen

  • Problems with cut and paste within the code editor in JDeveloper 10.1.3 EA

    Copy and pasting doesn't work as expected. If I copy some code and paste it somewhere else, i get completely different code, (it seems to paste a piece of code from somewhere else in the source).
    I tried expanding + signs, this didn't help.
    I'am running JDeveloper on Windows XP Professional.
    Does anybody else have the same problem.
    Is this a bug?

    We've tracked down this issue thanks to Tullio's supplying us with a reproducible testcase. It's related to the "Automatically Copy Paste Imports" preference (which is on by default) in the Tools->Preferences->Code Editor category of IDE preferences. It seems to also be related to having renamed a source path directory to have a name that is only different by case from the name it originally had. Disabling this preference is a workaround for EA1.
    For example, if you started out by creating your workspace with a source directory named "Src", then later renamed it to "src", this seems related to the situation when this issue can occur. Renaming the directory back to match what it was before is another workaround for EA1.

Maybe you are looking for