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")