Python を使用して VeriStand で自動フレーム処理を構成する

更新しました Jul 5, 2024

環境

ソフトウェア

  • VeriStand

プログラミング言語

  • Python

VeriStand XNET では、自動フレーム処理 (Automatic Frame Processing, AFP) でのカスタム チェックサムとローリング カウンタの追加がサポートされています。 Python で実装されたniveristandパッケージには、NI VeriStand システム定義ファイルと対話する API (アプリケーション プログラミング インターフェイス) が含まれています。この記事では、Python スクリプトを使用して VeriStand XNET で AFP を構成する方法を紹介します。
VeriStand システム定義ファイルを使用して AFP を直接設定する必要がある場合は、VeriStand XNET で AFP 機能を設定する方法についての記事 を参照してください。
 

Python で VeriStand システム定義をスクリプト化する場合、VeriStand 開発チームは、公式にサポートされているniveristandパッケージにある機能を活用することを推奨しています。

スクリプトに関して言えば、従うべきアクションの大まかな手順は次のとおりです。

  1. 新しいSystemDefinitionオブジェクトをインスタンス化します。

  2. システム定義 API を使用して、次のことを行います。

    1. 新しい項目 (ユーザー チャネル、CAN ポートなど) をSystemDefinitionに設定します。これは、システム定義を構成する全体的なツリー構造 (システム エクスプローラーでシステム定義を表示するときにユーザーに表示されるのと同じ階層構造) にエントリを追加することによって行われます。

      • 注意:作成されたすべてのシステム定義オブジェクトを、生成されたシステム定義に反映するには、この既存の構造に追加する必要があります。これらのオブジェクトをインスタンス化するだけでは十分ではありません。
    2. 必要に応じて、システム定義内の既存の項目のプロパティを更新/構成します。

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

上記のコードが正常に実行されると、VeriStand システム定義ファイル Test.nivssdf が次のパスに作成されます。
C:\Users\Public\Documents\