<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Problem with two parallel While loops in LabVIEW</title>
    <link>https://forums.ni.com/t5/LabVIEW/Problem-with-two-parallel-While-loops/m-p/2317336#M727770</link>
    <description>&lt;P&gt;Because I need to have a permanent control on pressure. It's not just setting the pressure. Once I set pressure to 2Bar I might have to keep it 2Bar for hours. So I have to read it and if it was necessary, send it again to keep it in a constant situation. I dont think I have a better option.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What do you mean your&lt;SPAN&gt;&amp;nbsp;monitor is only 1920x1600? You could simply use CTRL+SHIFT+N to look all over the code. Of course you know that already.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;Has anybody ever faced this issue? What am I suppose to do ?&lt;/P&gt;</description>
    <pubDate>Fri, 15 Feb 2013 17:34:09 GMT</pubDate>
    <dc:creator>mostafanfs</dc:creator>
    <dc:date>2013-02-15T17:34:09Z</dc:date>
    <item>
      <title>Problem with two parallel While loops</title>
      <link>https://forums.ni.com/t5/LabVIEW/Problem-with-two-parallel-While-loops/m-p/2316986#M727707</link>
      <description>&lt;P&gt;I have a serious problem with controlling two parallel While Loop. Here is the deal:&lt;/P&gt;
&lt;P&gt;I have written a VI to send a series of commands called Cycle through Serial Port to a custom hardware. One of these commands is setting motor pressure by sending it's command and changing it's voltage. After setting desired pressure I have to read and control motor pressure, again through serial port in a parallel loop. There is a Pressure Sensor in system and I can obtain current's motor pressure by sending a command and receiving pressure value. In the first While loop I send some commands to hardware including Pressure Setting Command trough a state machine. In the second While Loop I read pressure value and then decide to increase motor voltage or decrease&amp;nbsp; it. Now the problem is in communicating these two loops. In cycle after "Init" state when state reaches "Pressure 2 Bar" motor voltage will increase. Meanwhile I have to control this voltage in parallel While Loop. As you can see I used Local Variable to communicate between these two loops. The problem is that loops are not synchronized. Specially when I switch to "Pressure 3.8 Bar" state during cycle running control loop (second while) is still working based on "Pressure 2 Bar" state not 3.8 bar. Because of this motor pressure goes to 3.8 bar for a sec (becuase of &lt;SPAN&gt;&amp;nbsp;"Pressure 3.8 Bar" state)&amp;nbsp;&lt;/SPAN&gt;and comes back to 2 bar (because the second while still has not gotten that new state,most probably cause of all the delays in the loop) &amp;nbsp;and after couple seconds it goes back to 3.8 bar.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I really don’t know what to do. Is there a way to fix this? Or I should consider a better way to do this?&lt;/P&gt;
&lt;P&gt;I went through Occurrence Palette but couldnt figure out how to embed that in the VI.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sorry for my poor English. I attached VI and it's subVIs as a LLB file. I can explain more details if somebody wants.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Feb 2013 14:33:03 GMT</pubDate>
      <guid>https://forums.ni.com/t5/LabVIEW/Problem-with-two-parallel-While-loops/m-p/2316986#M727707</guid>
      <dc:creator>mostafanfs</dc:creator>
      <dc:date>2013-02-15T14:33:03Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with two parallel While loops</title>
      <link>https://forums.ni.com/t5/LabVIEW/Problem-with-two-parallel-While-loops/m-p/2317022#M727716</link>
      <description>&lt;P&gt;I'm not sure why you need two separate loops.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you not issue the commands and receive the results in the same loop?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I haven't looked at your code (My monitor is only 1920x1600), but I usually attack these things in a single loop:&lt;/P&gt;
&lt;P&gt;Repeat&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; If NeedToSendPressureCommand&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; SendCommand( )&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ExpectedDataType = "Pressure"&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; If NeedToSendFlowCommand&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; SendCommand( )&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ExpectedDataType = "Flow"&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; If DataAvailableAtReceiver&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ReceiveData( )&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; case ExpectedDataType of&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Pressure: &amp;nbsp;HandleNewPressure(ReceivedValue)&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Flow: HandleNewFlow(ReceivedValue)&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; if NOW &amp;gt;= TimeToDoSomething&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;NeedToSendPressureCOmmand = TRUE&lt;/P&gt;
&lt;P&gt;until Stopped.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you do need to synchronize the two loops, then look at the SYNCHRONIZATION palette.&lt;/P&gt;
&lt;P&gt;There are Notifiers, and Rendezvous operators that might help.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Feb 2013 14:57:09 GMT</pubDate>
      <guid>https://forums.ni.com/t5/LabVIEW/Problem-with-two-parallel-While-loops/m-p/2317022#M727716</guid>
      <dc:creator>CoastalMaineBird</dc:creator>
      <dc:date>2013-02-15T14:57:09Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with two parallel While loops</title>
      <link>https://forums.ni.com/t5/LabVIEW/Problem-with-two-parallel-While-loops/m-p/2317336#M727770</link>
      <description>&lt;P&gt;Because I need to have a permanent control on pressure. It's not just setting the pressure. Once I set pressure to 2Bar I might have to keep it 2Bar for hours. So I have to read it and if it was necessary, send it again to keep it in a constant situation. I dont think I have a better option.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What do you mean your&lt;SPAN&gt;&amp;nbsp;monitor is only 1920x1600? You could simply use CTRL+SHIFT+N to look all over the code. Of course you know that already.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;Has anybody ever faced this issue? What am I suppose to do ?&lt;/P&gt;</description>
      <pubDate>Fri, 15 Feb 2013 17:34:09 GMT</pubDate>
      <guid>https://forums.ni.com/t5/LabVIEW/Problem-with-two-parallel-While-loops/m-p/2317336#M727770</guid>
      <dc:creator>mostafanfs</dc:creator>
      <dc:date>2013-02-15T17:34:09Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with two parallel While loops</title>
      <link>https://forums.ni.com/t5/LabVIEW/Problem-with-two-parallel-While-loops/m-p/2317546#M727811</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;@mostafi wrote:&lt;BR /&gt;
&lt;P&gt;What do you mean your&lt;SPAN&gt;&amp;nbsp;monitor is only 1920x1600? You could simply use CTRL+SHIFT+N to look all over the code. Of course you know that already.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;BR /&gt;He means your block diagram is way too large.&amp;nbsp; Using block diagram cleanup helps a little bit to get rid of some of the excess white space.&amp;nbsp; But your code still takes up too many screens.&amp;nbsp; The recommendation for good LabVIEW style is to try to keep block diagram to one screen size.&amp;nbsp; The navigation windows helps to get a rough overall picture of the diagram, but when you have to drag it around so much to figure out what is going on.&amp;nbsp; It is too difficult to figure out how your program works.&lt;/P&gt;</description>
      <pubDate>Fri, 15 Feb 2013 20:11:10 GMT</pubDate>
      <guid>https://forums.ni.com/t5/LabVIEW/Problem-with-two-parallel-While-loops/m-p/2317546#M727811</guid>
      <dc:creator>RavensFan</dc:creator>
      <dc:date>2013-02-15T20:11:10Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with two parallel While loops</title>
      <link>https://forums.ni.com/t5/LabVIEW/Problem-with-two-parallel-While-loops/m-p/2318220#M727966</link>
      <description>&lt;P&gt;If you look at the code in the first while loop which is a state machine, in some states there is a delay around 10 to 30 second.&lt;BR /&gt;What would happen for pressure control if I dont use a parallel while loop to have a permanent control on pressure? It's obvious we wont have control on pressure while those delays occurres.&lt;/P&gt;
&lt;P&gt;Anybody?&lt;/P&gt;</description>
      <pubDate>Sun, 17 Feb 2013 18:54:19 GMT</pubDate>
      <guid>https://forums.ni.com/t5/LabVIEW/Problem-with-two-parallel-While-loops/m-p/2318220#M727966</guid>
      <dc:creator>mostafanfs</dc:creator>
      <dc:date>2013-02-17T18:54:19Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with two parallel While loops</title>
      <link>https://forums.ni.com/t5/LabVIEW/Problem-with-two-parallel-While-loops/m-p/2318226#M727968</link>
      <description>&lt;P&gt;I make it a point to NEVER have a WAIT function inside a state machine.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It sort of defeats the purpose, which I define as "Examine current state; decide whether you've met the conditions to advance to another state, then get out".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example, I have a single state machine VI controlling four identical instruments, via TCP connections.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For some functions, that means issuing a command, waiting 60 seconds, then reading results.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If I waited INSIDE the state machine, then it's tied up waiting on one device and cannot handle any others.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Not a good plan.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To handle this, I have a loop which calls the state machine. &amp;nbsp;After issuing the command, the state goes to "Waiting on Response", and there is a target time of 60 seconds from now.&lt;/P&gt;
&lt;P&gt;It's called over and over in that state, and each time merely compares NOW to the target time. &amp;nbsp;If NOW is past the target, then we read the results.&lt;/P&gt;
&lt;P&gt;the state machine can tell the caller when to call back; that's how I distinguish between an urgent need and nothing-to-do.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;By having the CALLER do the waiting, instead of the state machine itself, the state machine is free to handle another device, or do something else on the same device.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You should be calling the state machine over and over and over anyway. &amp;nbsp;So, have the state machine "control the pressure" on every call, and THEN examine whatever state it's in.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 17 Feb 2013 19:11:42 GMT</pubDate>
      <guid>https://forums.ni.com/t5/LabVIEW/Problem-with-two-parallel-While-loops/m-p/2318226#M727968</guid>
      <dc:creator>CoastalMaineBird</dc:creator>
      <dc:date>2013-02-17T19:11:42Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with two parallel While loops</title>
      <link>https://forums.ni.com/t5/LabVIEW/Problem-with-two-parallel-While-loops/m-p/2319374#M728228</link>
      <description>&lt;P&gt;Thanks&amp;nbsp;&lt;SPAN&gt;Steve&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Now it's getting better ...&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;Could you please attach a simple VI so I can understand it much better?&lt;/P&gt;</description>
      <pubDate>Mon, 18 Feb 2013 20:27:24 GMT</pubDate>
      <guid>https://forums.ni.com/t5/LabVIEW/Problem-with-two-parallel-While-loops/m-p/2319374#M728228</guid>
      <dc:creator>mostafanfs</dc:creator>
      <dc:date>2013-02-18T20:27:24Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with two parallel While loops</title>
      <link>https://forums.ni.com/t5/LabVIEW/Problem-with-two-parallel-While-loops/m-p/2319388#M728231</link>
      <description>&lt;P&gt;Take a look at&amp;nbsp;&lt;A href="http://culverson.com/state-of-the-machine/" target="_blank"&gt;this&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;There's an example linked at the end.&lt;/P&gt;</description>
      <pubDate>Mon, 18 Feb 2013 20:35:50 GMT</pubDate>
      <guid>https://forums.ni.com/t5/LabVIEW/Problem-with-two-parallel-While-loops/m-p/2319388#M728231</guid>
      <dc:creator>CoastalMaineBird</dc:creator>
      <dc:date>2013-02-18T20:35:50Z</dc:date>
    </item>
  </channel>
</rss>

