06-23-2016 10:52 AM
Sorry if this is such a rookie question but I've searched a lot and found no elegant solution to my problem.
I have a PLC with which I communicate via a VI (MB Ethernet Master Query Write Single Coil).
In an event structure, I have assigned each of my 15 relay on the PLC to open when I press the associated boolean.
In other word, when I activate the boolean on my front panel, it triggers an event that send the corresponding Modbus adress and the boolean value to the Modbus VI.
Now for my issue:
I want to create a protection that if there's an error, if the Main VI is stopped or if the window is accidentally closed, it will close all channels
But for the VI to do that, I need to send, in sequence, all the adresses (0-15) as well as a FALSE state for each of them.
And I'm just at lost on how to do that.
Thanks for any help
06-23-2016 11:01 AM
06-23-2016 11:09 AM - edited 06-23-2016 11:13 AM
I need to send a FALSE to each of the 15 adresses in succession so that all physical channel would close to prevent problems.
(For all I care, it could be done in parallel but as far as I understand what I made, I can only send one adress and one boolean at a time to the VI, the alternative would be to duplicate the VI, but this seemed like a clumsy way to handle things and a potential communication problem by fulling the buffer)
06-23-2016 12:28 PM
06-23-2016 12:31 PM
06-23-2016 12:43 PM
in which case do you expect error? I assumed this is the main VI so you can hide the options which lets the user to close the application accidentally. Generally we must have a shutdown sequence in which we can close the things we have to. So put all the addresses in an array and loop it in a for loop to close everything in a sub vi. So whenever you need to shutdown you can all this VI. Does it make sense?
BTW:@PalanivelT: How would a re-entrant vi solve the issue?
06-23-2016 01:07 PM
Put a for loop that will turn off all channels after main while loop.
To process application close I usually use Filter events (app -> instance close? or VI-> Front Panel Close?) and discard them. After a last action of VI I close the front panel (invoke node) if needed. I am used to doing that because I am not completely sure event structure processes the frame "App Instance close" before really closing application. And it definitely does not process anything after this event.
06-23-2016 01:09 PM
I mean it as a protection against accidental closing, VI error (mainly communication error over ethernet), if the computer shuts down etc. as well as an startup condition so everything always start up as closed (the timeout)
I tried to cover as much as possible, you could be surprised as to how clever students can be when it come to breaking stuff.
I'm looking for the reentrant VI (I'm really a novice with just the basic course of how to make loops, and save files so I need to learn everything from the bottom) The Wrapper thing left me baffled but eventually I should figure how to use it.
I was thinking about using an array in a FOR loop with 15 iterations, but I don't know how exactly to extract the adresses one at a time and combining them with a boolean False each time.
I'm not sure if this is clear?
06-23-2016 02:56 PM - edited 06-23-2016 03:04 PM
In Tools - VI properties -> Appearance -> Customize you can Disable possibility to close window or you can discard it and process.
Application instance close? event happens, when you close project window, or, possibly when another vi calls StopLabview function. It will not help against task manager task abort or computer shut down.
Edit: it helps against shutdown: it processes event and loop when I press Windows Start button -> Shut down. Possibly if it takes longer than windows timeout, it will force destroy it.
I do not know how you make your address, if it is 0 - 14, see below - connect your Write Relay state vi instead of fake picture
Edit 2: If WriteVI can be reentrant, you can parallelize closing loop so that all relay close at the same time, not one after one. I do not know how long each one takes, so it might or might not speed up closing all.