VeriStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Programmatically adding VS custom device

Solved!
Go to solution

Hey everyone,

 

So I was wondering if there is a way to programmatically add a custom device to an SDF in VeriStand.  I  have a program that runs through some calibration stuff and after that is done I'd like to automatically add a custom device to the SDF.  So far I have only found a way to get a current list of custom devices - not add one.


Does anyone know how to do this?


Thanks.

0 Kudos
Message 1 of 11
(8,881 Views)
Solution
Accepted by topic author joedowdle

I'm assuming you're using the .NET system definition API to modify the sdf before deploying.

 

In that case, there is a constructor for a custom device that takes in the GUID of the main page. Once that is done, use the AddCustomDevice method on the SDF's CustomDevices node.

 

When you have the custom device .NET reference (the object) you can configure it with .NET calls like add channel/section and set properties. Although, since most custom devices have an initialization VI that does most of this, you can actually call the initialization VI if you want. To do that, get the NodeID from the CustomDevice object and pass that to the connector pane of the initialization VI.

 

Hope this helps!

Stephen B
Message 2 of 11
(8,873 Views)

That has helped a bunch - I didn't see the AddCustomDevice method earlier, must have missed it.

 

So just for clarity (and for anyone else that might read this), would this code be correct?  Obviously given that it has the correct strings.

 

example.png

Message 3 of 11
(8,868 Views)

yep!

Stephen B
0 Kudos
Message 4 of 11
(8,863 Views)

Awesome, thanks.

0 Kudos
Message 5 of 11
(8,837 Views)

Hi everyone,

 

I'm C# .Net developer and I don't achieve to add an existing custom device by code. Another department of my company deliver me custom devices and I save them in the default NI directory on my computer. I have to add them automatically to a new System Definition File (and other stuff).

When I add one to a System Definition File with the System Explorer it works great. The channels are presents and working. So I think the problem doesn't come from the CDs...

But when I add one by code, it seems to be broken. Channels are under the CD but they don't have the right icons and the CD is not working.

 

See my code to understand my misbehaviour :

 

bool isAdded;
CustomDevice newDevice = new CustomDevice(init.EntityName, init.Guid); foreach (InitItem channel in init.Channels) newDevice.AddCustomDeviceChannelIfNotFound(channel.Name, channel.Guid, out isAdded); target.GetCustomDevices().AddCustomDevice(newDevice);

I think that the main problem is in the CD's XML because the only Guid found is the CD one. I don't have any information about channels... So I use always the same guid : 03D3BB99-1485-13A6-561D1F898F032919

 

I hope my description is clear enough.

Thanks in advance.

 

Regards,

R.A.

0 Kudos
Message 6 of 11
(8,413 Views)

I think that the main problem is in the CD's XML because the only Guid found is the CD one. I don't have any information about channels... So I use always the same guid : 03D3BB99-1485-13A6-561D1F898F032919

Yes that is the problem. The channels will have a different GUID than the custom device main item itself. You should create the custom device main item as you are already doing... but for what to do next... that depends on the custom device.

 

For example, custom device A may require this layout:

  • Custom Devices
    • A (GUID: abcd)
      • Channel (GUID: efgh)
      • Channel (GUID: efgh)
      • Channel (GUID: efgh)

 

Custom device B may require this layout:

  • Custom Devices
    • A (GUID: 23ab)
      • Channel (GUID: 33af)
      • Channel (GUID: 33af)
      • Channel (GUID: 33af)
      • Section (GUID: iaijfe)
        • Channel (GUID: 9fan)

 

Only the developer of the custom device can provide this structure information to aid you in creating the structure under their custom device with the .NET API. They will also have to inform you what properties to set on each item if there are any configuration settings for the custom device.

 

If you don't have access to the developer, you can create the custom device in the system explorer, save the sysdef, then open it in a text editor and reverse-engineer all the information you need by looking at the XML.

Stephen B
Message 7 of 11
(8,400 Views)

Thank you Stephen,

 

My custom devices may look like A and B examples.

So I will do some reverse-engineering on sysdef at first.

 

But is it possible to export all the XML structure of a custom device during design ? It should be easier for us.

 

Regards,

R.A.

0 Kudos
Message 8 of 11
(8,388 Views)

The XML structure of the custom device doesn't dictate it's layout in the system explorer. The LabVIEW code of the custom device programatically creates the layout in the system explorer, hence you must ask the author how to do the same thing with your C# code (or reverse engineer it)

Stephen B
0 Kudos
Message 9 of 11
(7,990 Views)

Ok, thanks Stephen.

 

Have a nice day,

R.A.

0 Kudos
Message 10 of 11
(7,987 Views)