01-31-2018 11:52 AM
Background: I am trying to write a VI which controls relays via rs232. I have the rs232 parts figured out in veristand so I just need to send Veristand a numeric double based on 8 booleans.
01-31-2018 12:02 PM - edited 01-31-2018 12:06 PM
Use "boolean array to number" and index into a lookup table (array) containing the desired output as a function of input.
Please attach a simplified version of your code so we can give more specific suggestions.
@larboc wrote:
For example:Bool 1 goes high, output is 8Output stays at 8 until another bool is clicked.bool 1 goes low output is 0bool 2 goes high output is 9bool 3 goes low output is 1
Your example is not unique enough. I assume that the output depends solely on the boolean pattern and not on e.g. previous states or transitions. Since there are 256 possible patterns, you should list them all unless there is a simplified mathematical term that can uniquely calculate a new output for each input.
01-31-2018 01:15 PM - edited 01-31-2018 01:16 PM
I thought about doing that but was hesitant due to the number of options (256) that will have to be manual entered as it is not a pattern.
I tried using an event structure, which appears to work fine when running in labview, but when I export it to veristand, the output never changes from 0.
See attached .vi. which only has two relays in it for a trial, eventually it will get 8.
01-31-2018 02:04 PM - edited 01-31-2018 02:07 PM
@altenbach wrote:
Use "boolean array to number" and index into a lookup table (array) containing the desired output as a function of input.
Please attach a simplified version of your code so we can give more specific suggestions.
@larboc wrote:
For example:Bool 1 goes high, output is 8Output stays at 8 until another bool is clicked.bool 1 goes low output is 0bool 2 goes high output is 9bool 3 goes low output is 1Your example is not unique enough. I assume that the output depends solely on the boolean pattern and not on e.g. previous states or transitions. Since there are 256 possible patterns, you should list them all unless there is a simplified mathematical term that can uniquely calculate a new output for each input.
The math means this won't work unless I'm missing something. All booleans ON results in 255, all booleans OFF results in 0. Any number between 0 and 255 could mean a bunch of different things in the array and you could get to any number a few different ways. I.E. Toggling bool 1 on and toggling bool #2 would both produce 255 when toggled on if everything else was on.
I think the case structure example I posted up and my initial explination should explain what needs to happen, I just need to get it working in veristand.
01-31-2018 02:12 PM
@larboc wrote:
I thought about doing that but was hesitant due to the number of options (256) that will have to be manual entered as it is not a pattern.
No matter what, you need to deal with all possible cases, so a LUT is still simplest.
If only certain combinations are possible, you can enter all expected values and leave the rest of the entries at their default.
What is the pattern for all expected combinations of booleans? Does it only depend on the last switched?
(Also note that your event structure use is bad. Once the event fires, the boolean has been read long ago, so you'll get the state value from the tunnel instead of the current value. You need to place the terminal inside their respective cases or read from the "newval" event data node.)
01-31-2018 02:20 PM
I will look at my case structure.
I'm controlling 8 relays with a serial relay board.
To toggle a relay, I send a serial command.
0....7 turns off a respective relay
8....15 turns on a respective relay
I want 8 radio buttons which control the relays, they can be hit in any combination. When one gets toggled up or down, I want the .vi to output the corresponding number to turn ONLY the corresponding relay on or off.
A lookup table won't work.
For an example:
All the buttons are toggled off, which sends zero to the 0 index in the array. Index 0 in the array would tell it to send what number out? The correct number could be anything from 0...7. See the problem?
01-31-2018 02:23 PM - edited 01-31-2018 02:23 PM
Assuming I have your pattern figured out correctly, this should work.
01-31-2018 02:25 PM
larboc wrote:For example:Bool 1 goes high, output is 8Output stays at 8 until another bool is clicked.bool 1 goes low output is 0bool 2 goes high output is 9bool 3 goes low output is 1
You still have not explained the logic and this description is not sufficient. E.g. how can boolean go low if it was never set to high (last line)?
Please start with a known state and do a few more examples for buttons going on or off and what the resulting numeric should be.
One possible way would be the following. Code. Now the output only depends on the last used switch and it's new state.
(If this should be used as a subVI, get the previous state from a feedback node instead. No event structure)
01-31-2018 02:27 PM
(I guess Tim had a similar Idea :D)
01-31-2018 02:44 PM
@larboc wrote:
I want 8 radio buttons which control the relays, they can be hit in any combination. When one gets toggled up or down, I want the .vi to output the corresponding number to turn ONLY the corresponding relay on or off.
So, why not use a radiobutton control? (probably needs a few tweaks)