promo ~master

Modbus over TCP payloads


To use this package, run the following command in your project's root directory:

Manual usage
Put the following dependency into your project's dependences section:

promo

A minimal D library to build Modbus over TCP payloads.

This package implements the binary formatting of MODBUS requests and responses when transported over a MODBUS TCP/IP network. It focuses solely on the creation of the data blob (including the MBAP header and PDU), without handling the transport layer (i.e., TCP socket communication).

For networking, the user is expected to rely on Phobos or any other library of choice.

Features

  • Encodes MODBUS TCP request/response payloads
  • Supports MBAP header creation
  • Stateless and lightweight
  • Fully compatible with standard MODBUS TCP/IP devices
  • Pure D implementation

Installation

Add this package as a dependency in your dub.sdl or dub.json project file.

dub.sdl

dependency "promo" version="~>0.1.0"

dub.json

"dependencies": {
    "promo": "~>0.1.0"
}

MBAP Header Structure

Each MODBUS TCP frame starts with a 7-byte MBAP (MODBUS Application Protocol) header:

FieldSizeDescription
Transaction ID2 bytesIdentifier for pairing requests and responses
Protocol ID2 bytesAlways 0 for MODBUS
Length2 bytesNumber of remaining bytes (Unit ID + PDU)
Unit ID1 byteIdentifies the MODBUS slave device

This header is followed by the Protocol Data Unit (PDU), which includes the function code and associated data.

Usage Example

See cli.

Notes

  • This library does not implement TCP communication.
  • You are expected to use std.socket or a similar transport layer to send and receive the data.
  • Error handling and response parsing are also outside the scope of this package (for now).

Contributing

Pull requests and issues are welcome. If you find a bug or want to add support for additional MODBUS function codes, feel free to contribute!

License

MIT

Authors:
  • Orfeo Da Vià
Dependencies:
none
Versions:
~master 2025-Jun-13
Show all 1 versions
Download Stats:
  • 0 downloads today

  • 0 downloads this week

  • 0 downloads this month

  • 0 downloads total

Score:
0.3
Short URL:
promo.dub.pm