How to Configure Automatic Frames Processing in VeriStand Using Python

Updated Feb 5, 2024

Environment

Software

  • VeriStand

Programming Language

  • Python

In VeriStand XNET,  adding a custom checksum and rolling counter in Automatic Frame Processing(AFP) are supported. The niveristand package implemented in Python contains APIs (Application Programming Interface) that interact with the NI VeriStand system definition file. This article will introduce how to configure AFP in VeriStand XNET through Python script.
If you need to configure the AFP directly using the VeriStand system definition file, you may refer to this article, How to Configure the AFP Function in VeriStand XNET.

 

For scripting a VeriStand system definition in Python, the VeriStand team recommends leveraging the functionality found in the officially supported niveristand package.

In terms of the scripting, the high-level sequence of actions to follow is the following:

  1. Instantiate a new SystemDefinition object.

  2. Use the System Definition API to:

    1. Populate new items (user channels, CAN ports, etc.) into that SystemDefinition. This is done by adding entries into the overall tree structure that composes the system definition(the same hierarchical structure that is visible to the user when viewing the system definition in System Explorer).

      • Note: All system definition objects that are created must be added to this existing structure for them to be reflected in the generated system definition. Instantiating these objects alone is not sufficient.
    2. Update/configure properties of existing items within the system definition as desired.

  3. Call to save_system_definition_file to write the constructed system definition into a file on disk at the specified path.
    Below is an example code to demonstrate the configuration:

from niveristand import systemdefinitionapi

# Create the system definition
systemDefinition = systemdefinitionapi.SystemDefinition(
    "Test System Definition",
    "Test Description",
    "Author",
    "1.0.0.0",
    "Controller",
    "Windows",
    "C:\\Users\\Public\\Documents\\Test.nivssdf")
target = systemDefinition.root.get_targets().get_target_list()[0]
xnet = target.get_hardware().get_chassis_list()[0].get_xnet()

# Create a database and add it into the system definition
database = systemdefinitionapi.Database("NIXNET_example")
target.get_xnet_databases().add_database(database)

# Create the CAN port
canPort = systemdefinitionapi.CANPort("TestCANPort", 1, database, "CAN_Cluster", 100000)

# Set the Automatic Frame Processing info for the CAN port
canPort.set_automatic_frame_processing("NI VeriStand 2011_CRC8", "National Instruments\\NI VeriStand 2011_CRC8.enb", [0,0,0,0])

# Add the CAN port into the system definition
xnet.get_can().add_can_port(canPort)

# Add an outgoing frame under the CAN port
signalBasedFrame = systemdefinitionapi.SignalBasedFrame("TestFrame", 123, database, "CAN_Cluster", 64, 0, False, [])
canPort.get_outgoing().get_cyclic().add_signal_based_frame(signalBasedFrame)

# Add the Automatic Frame Processing section to the frame
automaticFrameProcessing = signalBasedFrame.create_automatic_frame_processing()

crc = automaticFrameProcessing.get_crc()
counter = automaticFrameProcessing.get_counter()

# TODO: Perform any other needed configuration
crc.afp_data = [1,1,0,0]
counter.afp_data = [1,1,0,0]
crc.remove_alternate_channel()
counter.remove_alternate_channel()

# Save the system definition
saved, error = systemDefinition.save_system_definition_file()

if saved:
    print("Save success")
else:
    print("Save failure")

After successfully executing the code above, you should have a VeriStand system definition file name Test.nivssdf created at the following path:
C:\Users\Public\Documents\