Modbus 4 j-Java版modbusプロトコル実装

freeFree Technical Resource

This content is free to read, suitable for basic learning and search traffic.

Modbus 4 j-Java版modbusプロトコル実装

GitHub:https://github.com/infiniteautomation/modbus4j

Infinite Automation SystemsとSerotonin SoftwareによるJavaで書かれたModbusプロトコルの高性能で使いやすい実装。ASCI I、RTU、TCP、UDPトランスポートをスレーブまたはプライマリとしてサポートし、自動リクエストパーティション化とレスポンスデータ型解決を行います。

パブリックMavenリポジトリの最新バージョンを使用して、pom.xmlに追加できるようになりました。

<repositories>
    <repository>
        <releases>
            <enabled>false</enabled>
        </releases>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
        <id>ias-snapshots</id>
        <name>Infinite Automation Snapshot Repository</name>
        <url>https://maven.mangoautomation.net/repository/ias-snapshot/</url>
    </repository>
    <repository>
        <releases>
            <enabled>true</enabled>
        </releases>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
        <id>ias-releases</id>
        <name>Infinite Automation Release Repository</name>
        <url>https://maven.mangoautomation.net/repository/ias-release/</url>
    </repository>
</repositories>

依存関係情報は次のとおりです。

<dependency>
    <groupId>com.infiniteautomation</groupId>
    <artifactId>modbus4j</artifactId>
    <version>3.0.3</version>
</dependency>

コアクラス

  • ホストMasterとそのサブクラス:ホストのエントリ、データフローの始点と終点。
  • データポートクラスStreamTransport:データの書き込みと読み出しを担当する。
  • ModbusメッセージクラスModbusMessageとそのサブクラス:Modbusが定義した各種メソッド(FunctionCode)をサポート
  • 送受信データ制御クラスControl:out、retをサポートし、デフォルト200ms、1回。
    • 送受信待合室WaitingRoom:同期送受信ロジックを担当する.
    • Output Request MessageクラスOutgoingRequestMessageとそのサブクラス。
    • 受信Responseメッセージクラス:IncomingResponseMessageとそのサブクラス。
    • MessageParserは受信したメッセージをParseするクラスです。
  • プロトコルデータ型定義:DataType
  • 機能コードの定義:FunctionCode
  • プロトコルレジスタ範囲:RegisterRange

データフロー

  1. を通して。ModbusFactory対応するものの作成Master対象者。
  2. 送信するコマンドを含む。ReadHoldingRegistersRequestこれは、レジスタアドレスと長さを指定する読み取りレジスタCommandです。
  3. Master対象者はこれReadHoldingRegistersRequest変換する。OutgoingRequestMessageオブジェクトを送信しますMessageControl
  4. 駆動層を通して、MessageControlこれを取る。OutgoingRequestMessage対応するCommunicationハードウェア周辺機器(シリアルポート、ネットワークポートなど)に書き込み、データの返却を待ちます。IncomingResponseMessage
  5. 待機しない場合はnullを返し、タイムアウトを警告します。
  6. 効果的なリターンが得られるまで、MessageControl利用するにはMessageParserウィルはIncomingResponseMessage対応に変換するModbusResponse上に戻る。

単体テスト

modbus 4 j/src_test/には一連の単体テストメソッドが定義されており、関連するメソッドを追跡することでmodbusプロトコルの実際の動作フローを理解することができます。

Put this resource to use in a real project?

Go to the Tool Center for message parsing, CRC verification and device debugging, or submit your requirements for selection and integration advice.

Engineer Membership

Turn this article into actionable debugging resources

After activation, you can use advanced message parsing, resource pack downloads, code examples, engineering cases and priority technical support, suitable for real project delivery.

Unlimited Advanced Tools
Resource & Code Packs
Complete Engineering Case Library
Priority Technical Support

Leave a Reply

Your email address will not be published. Required fields are marked *.