11-21-2012 10:04 AM
Hi all,
I am trying to write a custom device to control certain aspects of my system definition (specifically another custom device). I am having trouble accomplishing this because I cannot find a way to write to a VeriStand channel that is outside of my custom device.
The help for the Get Channel Data Reference (which I would usually use to get a data reference so that I could use the Set Channel by Data Reference.vi) specifically says that I cannot obtain write access for a channel outside of my custom device.
Is there any way for me to get write access to a channel outside of my custom device?
I realize that I can create system mappings to output channels of my custom device, but I'm not crazy about a bunch of system mappings because they're not very visible and I'd like the user to only need to use my configuration pages. I also realize that it's probably possible for me to create these mappings programmatically from my custom device configuration, but I haven't been brave enough to venture down that road yet....
I am using VeriStand 2011 SP1 and LabVIEW 2011 SP1.
Thanks,
Chris
Project Engineer
Certified LabVIEW Developer
Solved! Go to Solution.
11-26-2012 06:57 PM
Hi Chris,
Unfortunately, I believe you have answered your own question: You cannot directly write to channels outside the custom device; you need to use system mappings.
11-28-2012 03:49 PM
So now I'm wandering down the dark alley that is the VeriStand .NET API....
I've successfully created system mappings using the SetDataSourceValue method. However, I can't find a way to delete those same mappings. I figure there has to be a way to do that.....
right?
11-28-2012 07:37 PM
11-29-2012 08:18 AM
Jarrod,
So I don't think that worked.
I just created a .NET constant, since I didn't know where to find a null constant:
This just gave me an empty mapping (which will throw an error on deployment):
Is there a different way I should be doing this?
Thanks!
11-29-2012 09:25 AM
BaseNodeType is part of the SystemStorage assembly, which is something used internally and not intended for public use. The publicly documented API is the SystemDefinition API, which has available documentation and is a little more user-friendly.
In the SystemDefinition API there is a class called "Utilities" which has an AddMapping(Channel Source, Channel Destination) method, and a ClearMapping(Channel Destination) method. These work as expected, and clear the mapping entirely (not just creating an invalid mapping with a null source, like your screenshot). This would be the preferred method of adding and removing mappings.
However, if you wanted to stick with your existing code, I think you can accomplish what you want by removing the "SetDataSourceValue" method and replaching it with a "RemoveProperty" method. The name wired into "RemoveProperty" will stay the same ("DataSource"). This will actually entirely clear the mapping from the channel, instead of remapping it to a null channel.
Regards,
Devin
11-29-2012 10:25 AM
I should also mention that you can get your custom device into the SystemDefintion API in a similar way as you're getting into the SystemStorage API in your screenshot. Instead of using "Item Reference to Pointer.vi", there are a series of VIs available to convert from the U64 ID to a SystemDefinition API reference. These can be found in the following library:
<LabVIEW>\vi.lib\NI Veristand\Custom Device Offline API\Custom Device Offline API.lvlib
The VI you're looking for would be "ID to BaseNode.vi".
In my previous message, I mentioned the method in the "Utilities" class. There are actually some issues with this, so instead, a better method to use would be DeleteChannelMappings(string[] channelPathDestinations) in the Root class. There are also methods in this class to get a list of mappings, add new mappings, and to clear all mappings.
In the example below I navigate to the channel I want to unmap, get the SystemDefinition API reference, gets its path, then get a reference to the Root of the System Definition (the base node in the tree) and delete any mapping to this channel.
11-29-2012 03:09 PM
Devin K,
Thanks!
I used your first solution (RemoveProperty) and it seems to work great.
I didn't implement the second solution with the System Definition API just because I had something working and didn't want to break it. However, now that I look at it more closely, I wonder, would it work on an RT system? (since it's the offline API)
Again, thanks a million! It's working great now!
11-29-2012 03:30 PM
No problem!
All of the APIs are .NET and are therefore not supported on RT. But, even if that wasn't the case, channel mappings are all done at configuration-time and can't be modified at runtime. Once the System Definition is compiled for deployment, it can't be changed.
11-29-2012 03:38 PM
Wow, this is what I get for posting while on a conference call!
Yes, I am doing all of this on the Windows configuration side, so my previous concerns are unwarranted and rather silly.