10-04-2019 09:55 AM - edited 10-04-2019 10:01 AM
@jackson040 wrote:
I've attempted to implement a third event structure inside another while loop, but the program won't return a reading from the device. I believe this has to do with how I added the new loop
Well, I'm sorry to say it, but you're right!
So, my suggestion was to add those changes to the existing Event Structure. Generally, having more than one Event Structure can lead to unexpected behaviour, particularly when you're new to LabVIEW. (Of course, I don't mean that the behaviour changes when you've used LabVIEW for longer... just maybe you're more likely to expect it!)
The suggestions that involved adding another loop (from johntrich, essentially) should instead have looked like this:
Here, there is no timeout case (in any loop) and there is a separate While loop which contains a Wait function (1000 ms) and then unconditionally enqueues the Read command.
The Read Event case remains in the original Event Structure, so that you can trigger extra reads by clicking the button, if you want.
Yamaeda's solution was more like mine, but would help to reduce the chance of long delays between reads by changing the checking interval to a lower value. It's a bit more complicated (because it requires time checking e.g. with Elapsed Time or similar) and so I haven't created an image here.
Edit: (and important) - I forgot to mention, but in the image above you'll see I added another Stop button. Of course there are other ways to stop multiple loops with only a single button, but you cannot do it in the way that you attempted, because of the principle of dataflow.
The idea here is essentially that a loop (or any other node, structure, subVI (that's a node, but for emphasis...)) will not start until all of its inputs are available. None of the outputs will become available until the loop (node, structure, etc) finishes running/executing.
In your case, the top-most loop had as an external input the boolean control from the middle loop. It was an output of the middle loop. So the top loop couldn't start until after the middle loop finished.
At that point, the value that was output, then an input, would be True. So the top loop would run exactly once. This is marginally better than another common problem, which looks like the following (DO NOT DO THIS!!):
In this case, the loops will read the value of the Stop control before starting to run, and then every loop iteration, they will use the same value (they will never check the control again, because the control is not inside the loop...). As a result, the initial condition is either true (they run one iteration each, and stop) or false (they never stop, until you abort). In either case, the stop button won't make any difference, no matter how much you click it...
10-04-2019 10:10 AM - edited 10-04-2019 10:15 AM
No, do NOT put another event structure. You should only need one event structure in a program. If you want to put another loop then just use a loop with a timer. You can use a notifier to stop the loop. You would then want to put a case in the Read case of the bottom loop that only runs it if the communication has been opened.
Edited to add:
cbutcher's reply overlapped mine. He did a good job in explaining, and his example showed what I was suggesting.
10-04-2019 10:21 AM
I have attempted to implement the same structure attached in this image, but I am now receiving the following error code.
VISA Write in MB Serial Transmit.vi:630007->MB Serial Master Query.vi:1850006->MB Serial Master Query Read Holding Registers (poly).vi->Platinum_MB_SerRead.vi->Platinum_MB_Example Serial Master.vi
I believe this is the same error code I was receiving last night, but I still do not understand what is causing the error. Do you have any ideas on how to remedy this?
10-04-2019 10:30 AM
So, the top loop looks fine now. It's good that you named your buttons appropriately to give the user (perhaps you) a clue as to what each one stops!
Regarding the error, I have the same question as yesterday (sorry it perhaps got lost in the several posts about different solutions to the timeout/queue entry problem).
What is the actual error code?
I don't have the driver you're using (MB something something, I guess it's one of the MODBUS libraries) so I can't check the contents of the subVI, but if you can give the error information rather than the call chain, the reason might become clear(er...) 🙂
10-04-2019 10:47 AM
Sorry about that I didn’t see the bit about the error code as I went through all the posts. I am not completely sure how to find more information with regards to the error. I copied all the information from the “error” window. How do I find this other info?
thanks!
10-04-2019 11:48 AM
I would suggest adding an error indicator here (arrow):
Of course, yours probably has real icons instead of question marks... If any information appears in the circled "error out", that would also be a possible source of information.
Having looked at this a little closer and realised that both of these VIs are the same (and are reading from some resource) I wonder if they are having some conflict with one another.
You might have some success by taking the error output from where the arrow is pointing, and connecting it to the input of the second subVI (with Set Point 1 Setting as the output). This will require disconnecting the current input where it branches. The result would be something like:
This may (may, no promises!) solve your problem.
10-04-2019 01:11 PM
Unfortunately connecting the error out from the first read sub VI to the second read sub VI did not solve the problem, but I did find the error code. There was no accompanying explanation text but the error number was " -1073807346 ". I've tried to find information about this specific code online and have not had any luck so far.
Thank you!
10-04-2019 01:42 PM
"The given session or object reference is invalid."
So something was corrupted in your reference that gets passed around in the pink wire.
Truly you should get rid of those "platinum modbus VI's" and use the straight up NI modbus library. Like I told you in the other thread, the only useful VI in that "Platinum" library is the one that looks up register addresses based on register names.
10-04-2019 02:46 PM - edited 10-04-2019 02:47 PM
Is there a corresponding NI modbus sub VI for all of the Platinum Modbus sub VIs? Or do I need to go in and replace everything in the block diagram?
Is there a way eliminate the error without reworking the block diagram?
10-04-2019 07:16 PM
All platinum is doing is wrapping up the NI modbus VI's and fluffing things up a bit like bundling more stuff into a connection cluster. Open up those VI's and you'll see what they do. Then look at the Serial Master example in the NI library.
I assume you can eliminate the error as soon as you find out what exactly is causing it. Looking for parts of code that close references, or tunnels that use default values if unwired.