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.
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.
04-05-2022 06:59 AM
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.
04-05-2022 07:38 AM
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.
04-05-2022 07:47 AM
A few things jump out at me: I suspect the item in bold is your problem.
04-05-2022 08:09 AM
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.
04-05-2022 08:21 AM
@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.
04-05-2022 10:22 AM - edited 04-05-2022 10:22 AM
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
04-06-2022 04:05 AM
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.
04-06-2022 07:52 AM
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.
04-06-2022 08:59 AM
@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. 🙂