LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to find the index of a changed array control

Solved!
Go to solution

Hello, I have a array control on my front panel containing switches. Once one of the switches is flipped I would like to find the array index of said switch, along with the value. ( I am using an event structure to coordinate this)

I am using this to send on/off events to my GOOP "DAQ object".

Any insight or examples would be greatly appreciated.

0 Kudos
Message 1 of 18
(63,992 Views)
Solution
Accepted by topic author Gaffinator

There is an event data node for "new val" and "old val" Compare them with != (not equal) and use "search array" for the value TRUE. Use the returned index go index into the "New val" array to get the new value.

 

WhatChanged.png

 

Message 2 of 18
(63,990 Views)
Solution
Accepted by topic author Gaffinator

This should work. It returns -1 if you create a new value though (i.e increase the size of the array)

changedValue.png\

Edited to add the value via indexing, but I saw my Lack of LabVIEW Programming Speed was Disturbing...


GCentral
Message 3 of 18
(63,978 Views)

But yes, as cbutcher said, you need to possibly add code to detect size changes.

 

Also be aware that e.g. using "val(sgnl)" you can create situations where either all array values remain the same (found index = -1) or more than one (or even all!) changed at the same (more than one TRUE to find). The current code only gives you the changed element with the smallest index. IF this is of concern, you need to add more code to detect and handle all the possible scenarios.

 

If the array is a more advanced datatype (e.g. an array of a complicated cluster), you might need to dig a little deeper, of course.

Message 4 of 18
(63,965 Views)

Hey thanks a lot guys, I will do some error checking to check for an increased array size (-1).

I do have another question that you might be able to help me with.

The goal is to flip a switch, and change the corresponding digital out signal.

Should I store the DO channels in an array and check based on that?

0 Kudos
Message 5 of 18
(63,951 Views)

We probably need more detail. Are you writing each DO independently or are you writing all at once using boolean array to define all switches. Can you show us some code?

0 Kudos
Message 6 of 18
(63,946 Views)

I think it would be best to only write one DO independently each time a switch is flipped.

Yeah i can attach my project, Keep in mind that I am a true novice

0 Kudos
Message 7 of 18
(63,941 Views)

There's left over code from the first version of it.

So ignore the MainV1.2.2.trash and the DAQEngineV4.2.trash

0 Kudos
Message 8 of 18
(63,939 Views)

If you have an array of tasks and they're in the same order as the switches, you can use the code posted above.

 

This perhaps isn't the most typical way to set up a collection of DO lines though - I'd think that a single task with multiple channels is more common using DAQmx, and some hardware also allows writing a numerical value to a port, rather than a line.

 

To write a port, you can convert an array of 8 booleans to a number using the Boolean Array to Number node and then write that value.

 

To write N channels (in a single task), you can pass the entire array to the Write node (regardless of which changed). This might be simpler?

 

If your lines are on physically separated hardware, I don't think (could be wrong) that they can be grouped in one DAQmx task. If you're not using DAQmx, not relevant, but worth keeping in mind. This post from 2007 discusses it with different PXI devices but maybe things change. https://forums.ni.com/t5/LabVIEW/Is-it-possible-to-add-multiple-devices-in-one-task/m-p/607164/highl...


GCentral
0 Kudos
Message 9 of 18
(63,937 Views)

So I thought that i should use a task with multiple channels was the right way to go about it.

A basic breakdown of my project would be to learn how to read Digital and Analog signals as well as how to generate them. My first version I was able to accomplish this. For the revision, I was tasked with implementing labview objects instead of asynchronously controlling a daq VI. And then I was tasked with scaling this so i could tentatively have N channels of each.

I just still have a little hard time grasping which of these I should group to tasks.

I believe i should have all my analog inputs as a Task. And i had though to do the same for my DO

(Right now in my project my AO AI DO DI are all tasks)

The actual signals will be coming from respective cards in a cdaq chasis.

0 Kudos
Message 10 of 18
(63,924 Views)