01-25-2016 11:52 AM
Hello Everyone,
I am new to XControls, and am trying to use these to make a generic numeric indicator that will take in an array of waveforms from an analog measurement and allow the user to view the first value of a waveform he selects by selecting the desired channel name from the waveform array. I have the XControl working, with a ring automatically populated from the NI_ChannelName fields of the input waveform array, and the ring value being used to index the waveform array to select the desired data.
What I would like to do next is automatically set the ring control value in the XControl to the value the user had selected the last time he ran the VI that uses the indicator. However, the ring control properties do not seem to be accessible from the VI that uses the XControl, and no general XControl properties seem to be accessible from the Facade VI in the XControl. The ring value isn't part of the waveform array input wired to DataIn, so I don't have a good method for passing data to the ring control outside of what is in this waveform array. I could add the value to the waveform array, if this helps, but XControl indicators don't pass their DataOut back to the calling VI to enable me to record the value the user selected.
Is there a good way to both read and write the properties of facade items in an XControl from the VI that is using the XControl?
I apologize for not posting my code; the computer with the LabVIEW license is having network issues at the moment. I will post the code when I can.
Thanks!
Erik
Solved! Go to Solution.
01-25-2016 05:38 PM
In your Container State cluster typedef, include a reference to a ring control.
In your Facade vi, in the Direction Change case, create a reference to your ring, and wire it to a Bundle by Name that sends it to the Display State Out. Also be sure to write TRUE to State Changed in the Action output.
In your xctl, select New -> Property. Name it after the property in the ring that you want to access. Use the Display State In cluster (in your new property VI) to access the reference to the ring; wire it to a property node. Change the Value control to the appropriate type & wire it to the desired property.
Be sure to wire the error path through everything that could generate an error.
When you drop an instance of the xctl, and create a property node from it, your new property will be available.
01-27-2016 09:04 AM
Impressive, thank you for the help! I never would have navigated my way through this on my own, but your instructions worked on the first try.
Some clarifications for anyone else using this:
In your Container State cluster typedef <State.ctl in the XControl>, include a reference to a ring control <replace the default control in the State cluster with a Control Refnum, and name it similarly to the ring control that is part of the XControl>.
In your Facade vi, in the Direction Change case <I used the Data Change case because the ring value updates when data changes>, create a reference to your ring <this reference is linked to the actual ring control that the user is interacting with>, and wire it to a Bundle by Name that sends it to the Display State Out. Also be sure to write TRUE to State Changed in the Action output.
In your xctl, select New -> Property. Name it after the property in the ring that you want to access. Use the Display State In cluster (in your new property VI <either or both Read and Write VIs, depending on what you want to be able to do using property nodes; I only used Read>) to access the reference to the ring; wire it to a property node. Change the Value control to the appropriate type & wire it to the desired property <selected in the property node>. <I selected the Value property in the property node, which was a variant, so I also had to wire in a variant to data block.>
Be sure to wire the error path through everything that could generate an error.
When you drop an instance of the xctl, and create a property node from it, your new property will be available.
01-27-2016 09:10 AM
Edit: I wired up both the read and write VIs for the new property, as I ended up wanting to do both.
01-27-2016 09:11 AM
The best place for send the reference value to the State cluster is the Direction Change case, not the Data Change case.
The reference value only changes on loading, or dropping the control, (both of which call the Direction Change case), it doesn't change when the data changes.
01-27-2016 09:25 AM
I have tried wiring up the change in both Direction Change and Data Change, and it works in both, but I agree that Direction Change is the better place to wire this. I did not realize from the description of Direction Change that changing the value of the ring control would trigger this event.
01-28-2016 03:45 PM
Now that I have this custom property, I would like to be able to programmatically access it using a property node that is not linked to the XControl, but uses a reference to the XControl. I've read several posts about how to gather and traverse the reference hierarchy in a VI, and I think I can get an array of references that only contain these XControls, but I can't get a property node to keep the custom property of the XControl when it is not linked directly to the XControl.
Is there a way to get custom properties using references? Alternatively, is there a way to get an array or cluster of all properties and their values for a given reference, in which I could find the custom property?
Thanks!
01-28-2016 03:51 PM
It works the same as a non-Xcontrol: create a reference to the Xcontrol, wire it to a property node. The custom properties of the Xcontrol will be available in the property node.
As a side note, if you needed to access a lot of properties of the ring, create a custom property of the Xcontrol that outputs a reference to the ring.
01-28-2016 03:58 PM
That is true for a specific reference to a single XControl. However, I am using this same XControl more than once, and I would prefer not to create a reference to each individual XControl, but instead use a chain of property nodes starting with a This VI reference to return an array of references to all of the copies of this XControl. When I implement this strategy, the custom properties are no longer available because LabVIEW is treating the reference array as if it could contain any class available from the last property node, not just the class of this XControl.
Is there an approach that doesn't involve individual references or links to each copy of the XControl?
01-28-2016 04:02 PM
Is this because the control reference returned is of the Control class? You can use the to more specific function to cast the reference to a more specific one. I've seen some people make their XControls show up in the class browser but never did it before. I assume if you did that then it would work.
Unofficial Forum Rules and Guidelines
Get going with G! - LabVIEW Wiki.
17 Part Blog on Automotive CAN bus. - Hooovahh - LabVIEW Overlord