VeriStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Adding channel mappings during Custom Device Initialization

I am using the .NET APIs to "AddChannelMappings" for my Custom Device in the SDF. I'm running this code within the Custom Device Initialization.vi. Prior to this code, I'm adding a channel to the custom device and setting some item properties. After building the configuration, I added the custom device to Veristand and then looked at System Mappings, I see nothing. I went back to my Custom Device project and added the "GetChannelMapping" method immediately after the "AddChannelMappings" and then put up a message dialog showing the result. After building and adding the custom device again, the message dialog indeed shows the mapping (I'm only mapping one model output channel to an input channel of my Custom Device). However, in System Explorer, the mappings are not showing up.

Download All
0 Kudos
Message 1 of 11
(4,743 Views)

The first thing to note (from Application Engineering) is that the code as attached will only work in "offline" mode (Veristand System Explorer not running). Looking now for a way to make it work when the Custom Device is initialized.

0 Kudos
Message 2 of 11
(4,708 Views)

I'm reporting the same behavior: I'm running the method from the Main Page vi of a custom device, receive a 'success' response by the method but don't see any mappings made.

0 Kudos
Message 3 of 11
(4,486 Views)

hi cbacchiani_ges, 

 

My first impression is that we wouldn't normally want to modify the system definition after it's already been deployed.  Can you tell us a little more about why you're wanting to modify the mappings from within the custom device?  What is the bigger picture of what you're trying to accomplish?

I'm hoping we may be able to find a different approach to accomplish it.

 

Kind Regards,

 

David R

Applications Engineer

National Instruments

0 Kudos
Message 4 of 11
(4,451 Views)

Hi Dave,

Perhaps I forgot to specify: indeed I'm trying to modify the SDF from a custom device, but from the Main Page of the 'configuration' part, that in the System Explorer. So, the Veristand project is actually open but not deployed or running.

And the reason is that the custom device should be in a way self-configuring, depending on the input interface of the model.

So far I had a partial success with a workaround: after obtaining the list of the mappings, I save it to a file with the format <source><Tab><destination>, and then import it in the Mappings Editor. I'm just trying to skip that step, although it's not too annoying now.

0 Kudos
Message 5 of 11
(4,438 Views)

cbacchiani_ges,

 

Thanks for the extra clarification!

 

After doing some more digging and talking with a few colleagues, I've confirmed that the .NET API is not able to modify the system definition currently open in the system explorer.

Any changes made to the system definition file will create a separate copy in memory, which can be saved.  However, this still will not affect the system definition loaded in the system explorer. 

 

From what I've been able to find, saving to a file and importing is looking like the most effective workaround.

 

David R

Applications Engineer

National Instruments

0 Kudos
Message 6 of 11
(4,397 Views)

Thank you Dave, that at least cleared the doubt!

I guess that automatically loading the mapping file, if possibile with the API, would incur in the same problem right?

Message 7 of 11
(4,391 Views)

Hey Everyone,

 

I got curious about this because surely there must be some way to do it. So I did a bit of digging and was able to find out one way that we can programmatically map channels while in the system explorer.

 

I got this code from the UDP-Data-Link-Custom-Device on github, and then I updated it a bit.

https://github.com/NIVeriStandAdd-Ons/UDP-Data-Link-Custom-Device/tree/dev/Source

UDP Data Link System Explorer.lvlib >> Configuration Utilities >> "UDP Data Link - Configuration Utilities - Add System Mapping.vi"

Note that this uses an obsolete method for addchannelmappings, update it to the new one which also returns an error.

 

It turns out that you can do this, but you have to use the Utilities under the System Definition API.

Then you have to go all the way down to the base node class, get the root node of the document, and then you can get and add channel mappings on that node.

 

Here is a snippet, and a quick test custom device that I made. You can add the channel mappings from the main page of the custom device, then open the system mappings and see that it has updated.

 

At the root node you can also use the GetSystemMappings method which will return an array of strings for source, and destination.

 

Cheers,

Joel

Download All
Message 8 of 11
(4,383 Views)

Thank you! I'm going to try it, but I have yet to find how to get the initial reference in the snippet

0 Kudos
Message 9 of 11
(4,359 Views)

Glad to help out. 

 

You can get the initial reference from really anything because we're going all the way to the system base node.

 

What I did is use the Reference (Node Ptr control) that comes in on the main page of the Custom device, but it would work on channel pages too using their reference.

0 Kudos
Message 10 of 11
(4,354 Views)