要使用 Python 編寫 VeriStand 系統定義腳本,VeriStand 團隊建議使用官方支援的niveristand
套件中的功能。
就腳本編寫而言,要遵循的高階操作順序如下:
-
實例化一個新的SystemDefinition
物件。
-
使用系統定義 API 去:
-
將新專案(使用者通道、CAN 連線埠等)填入該SystemDefinition
。這是透過將條目新增至組成系統定義的整體樹狀結構(與使用者在系統資源管理器中查看系統定義時可見的相同層次結構)來完成的。
- 注意:建立的所有系統定義物件都必須新增到此現有結構中,以便它們反映在產生的系統定義中。單獨實例化這些物件是不夠的。
-
根據需要更新/設定系統定義中現有專案的屬性。
-
呼叫save_system_definition_file
將建置的系統定義寫入磁碟上指定路徑的檔案。
下面是演示設定的範例程式碼:
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")