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:
-
Instantiate a new SystemDefinition
object.
-
Use the System Definition API to:
-
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.
-
Update/configure properties of existing items within the system definition as desired.
-
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")