From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Learn QMH

Hi 

I am trying to learn QMH by creating this program. There are three looops, one event handling loops and two message handling loops. But the program is not entering or starting the third loop or second message handling loop. Can anyone explain why is that. I have attached the program. Thank you. 

0 Kudos
Message 1 of 9
(1,044 Views)

You have a data dependency between your Write and Read loops.  You cannot have wires going between two loops that are to be running in parallel.

 

Generally for serial communications, I handle the read and the write in the same loop.  I tend to use the timeout capability of the queue to perform a read.  Granted, this only works if you are not constantly sending the loop commands.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 2 of 9
(1,022 Views)

A few things jump out at me: I suspect the item in bold is your problem.

  • Try and keep you block diagrams within one screen, you shouldn't have to scroll on a block diagram as it makes your code much less readable
  • Remember that LabVIEW is based on the dataflow paradigm. This means that a node or structure requires all of its inputs before it will run. Your bottom loop requires data from your middle loop. This means that your bottom loop will not start until the top loop has finished
  • I would structure your read and write commands in one loop controlled by one queue. Periodically write a command which causes data to be read from your device. You can then have other states to perform write functions. This means that both the read and the write functionality can share one reference to the modbus connection
  • You shouldn't need all of the wait functions
  • Try and avoid using local variables. It is asking for you to have a problem with a race condition
  • You are doing the right thing using type deffed enums as the command type for your queues. This does mean you don't have to have a default case in your handlers. Indeed I would try and avoid that. Have a case for every command you can send. It avoids difficult to debug problems caused by enquiing a unhandled command which then runs the default case
0 Kudos
Message 3 of 9
(1,018 Views)

Well I can have the write and read in the same loop, but the thing is I am using this to learn QMH, that is why I have read in a seperate loop. Write loop after writing will go to idle state and read loop will be constantly reading. That is what i am trying to do. So how do I do that. I tried removing the wiring between the two loops and used a local variable instead.  But that didnt help either. Its still not working. So what can be done to correct this. Thank you. 

0 Kudos
Message 4 of 9
(1,007 Views)

@govindsankar wrote:

Well I can have the write and read in the same loop, but the thing is I am using this to learn QMH, that is why I have read in a seperate loop. Write loop after writing will go to idle state and read loop will be constantly reading. That is what i am trying to do. So how do I do that. I tried removing the wiring between the two loops and used a local variable instead.  But that didnt help either. Its still not working. So what can be done to correct this. Thank you. 


I can't look at your code, but from the previous posts i'd say: You use 2 queues, one for ordering the Read loop and the Reading loop queues stuff in the 2nd queue that the 3rd loop consumes and writes to disk.

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 5 of 9
(1,002 Views)

As previously mentioned by crossrulz and me, I'd handle both the reading and writing in the same loop with a single queue.

 

This means that you can store all of the information required for that device in shift register(s) on that loop, eliminating the need to try and share communication references between loops with local variables which is something I very much would not recommend.

 

This is still a QMH, and is how I personally structure a good majority of my code. As a general rule, if I am going with this sort of design strategy I would have one queue for each device I am communicating with. You can then start taking it a step further and put your entire handling loop in a sub vi to start modularising your code and tidying up the block diagram.

 

You can trigger your 'read' case with some other section of code which enqueus the 'read' command periodically, like what you are are doing in the timeout event structure, or you could set a timeout of the dequeue case as a trigger to read from your device. Personally I would have a totally separate loop which does nothing but write the read case ever x seconds because as crossrulz said, using timeouts can cause problems if the timeouts never actually happen

0 Kudos
Message 6 of 9
(977 Views)

Ok yes it is still a QMH if I put both read and write in the same loop. But then what I want to learn is multiple loops. So what you are telling me is that this is not possible. I will have to try something different to learn multiple loops, something different where there is no data flow from one loop to the other. 

0 Kudos
Message 7 of 9
(923 Views)

It's just that multiple communication loops to the same resource aren't recommended.  What you COULD do is, let's say, add a logging loop.  Just log anything  - just time stamps, for instance - on demand.  Maybe add something from your read to it.

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

@govindsankar wrote:

Ok yes it is still a QMH if I put both read and write in the same loop. But then what I want to learn is multiple loops. So what you are telling me is that this is not possible. I will have to try something different to learn multiple loops, something different where there is no data flow from one loop to the other. 


See my previous answer. Multiple loops work fine, just use 1 queue for each. E.g. can the 2nd loop queue up stuff for the 3rd loop. 

If it's the best solution is another matter. 🙂

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 9 of 9
(879 Views)