Programming TCP or UDP communication with the NI-XNET IP stack first requires you to generate a JSON configuration string. This JSON configuration defines the IP stack that you create with the NI-XNET IP stack API and is how you implement, for example, the type of addressing you use in your application (static or DHCP).

The JSON that NI-XNET requires is governed by a schema that installs with the driver. The default installation location for this schema is %Public\Documents\National Instruments\NI-XNET\Documentation\xnetIpStackSchema-n.json, where n is a version number. Refer to this schema to understand the following:

  • The information that your program needs to provide
  • The name the information should have to create a valid JSON string

This procedure describes how to implement addressing in the configuration file: either static addressing, using IPv4 or IPv6 addresses, or DHCP using IPv4 addresses.

Complete the following steps to create a JSON configuration for the NI-XNET IP stack:

  1. Form an array of VLAN configurations:
    1. name: Use an empty string "" for IP stacks that have a single VLAN.
    2. isTagged: Identify whether the VLAN has a tag.
    3. id: Include the VLAN ID only if the VLAN has a tag.
    4. IPv4.mode: Set depending on your addressing scheme.
      • Static addressing: If a user specifies an address, set to enabled; if a user does not specify an address, set to disabled.
      • DHCP: For the server, set to static; for clients, set to dhcp.
    5. IPv4.staticAddresses: Set depending on your addressing scheme.
      • Static addressing: Allow a user to input IPv4 addresses.
      • DHCP: For the server, form this field from a static IPv4 address for the server, an IPv4 subnetMask, and a dhcpServer configuration; for clients, accept the IPv4 addresses that the server generates.
    6. IPv6.mode: Set depending on your addressing scheme.
      • Static addressing: If a user specifies an address, set to enabled; if a user does not specify an address, set to disabled.
      • DHCP: Set to disabled.
    7. (Static addressing only) IPv6.staticAddresses: Allow a user to input IPv6 addresses.
    8. (Static addressing only) staticArpTable: Allow a user to input a static ARP/NDP table.
  2. Form an array of MAC configuration clusters/structs:
    1. address: Set a value of generated to have NI-XNET generate local MAC addresses.
    2. VLANs: Pass in the array of VLAN configurations you created in step 1.
  3. Form an array of XNET interface (physical interface) clusters/structs:
    1. name: Pass in the name of the interface, for example, ENET1.
    2. MACs: Pass in the array of MAC configurations you created in step 2.
  4. Form a stack configuration cluster/struct:
    1. schema: Pass in the latest version of the schema installed on your system.
    2. xnetInterfaces: Pass in the array of XNET interfaces you created in step 3.
  5. Create a single string out of the configuration with Flatten to JSON; set enable LabVIEW extensions? to False so the configuration can support non-LabVIEW code.

LabVIEW Programming Examples for Configuring the NI-XNET IP Stack

For an example of creating this configuration for TCP or UDP communication with basic static addressing, refer to the XNET Example IP Stack Config - Single Interface.vi in the NI-XNET IP Stack Simple TCP.lvproj or NI-XNET IP Stack Simple UDP.lvproj examples.

For an example of creating this configuration to implement DHCP, refer to XNET Example IP Stack Config - DHCP Config.vi in the NI-XNET IP Stack Simple DHCP.lvproj example.

Now that you have generated the JSON configuration string for the IP stack, continue with establishing communication using either TCP or UDP.