Download the PHP package aldas/modbus-tcp-client without Composer

On this page you can find all versions of the php package aldas/modbus-tcp-client. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package modbus-tcp-client

Modbus TCP and RTU over TCP protocol client

Latest Version Packagist codecov

Use Composer to install this library as dependency.

Supported functions

Utility functions

Requirements

Intention

This library is influenced by phpmodbus library and meant to be provide decoupled Modbus protocol (request/response packets) and networking related features so you could build modbus client with our own choice of networking code (ext_sockets/streams/Reactphp/Amp asynchronous streams) or use library provided networking classes (php Streams)

Endianness

Applies to multibyte data that are stored in Word/Double/Quad word registers basically everything that is not (u)int16/byte/char.

So if we receive from network 0x12345678 (bytes: ABCD) and want to convert that to a 32 bit register there could be 4 different ways to interpret bytes and word order depending on modbus server architecture and client architecture. NB: TCP, and UDP, are transmitted in big-endian order so we choose this as base for examples

Library supports following byte and word orders:

Default (global) endianess used for parsing can be changed with:

For non-global cases see API methods argument list if method support using custom endianess.

See Types.php for supported data types.

Data types

Modbus is binary protocol which revolves about addresses of Registers/Word (16bit, 2 byte of data) and Coils (1 bit of data). Coils are booleans but Register/Word or multiple Registers can hold different data types. Following is ways to access different data types from Registers:

Most of the for data types have optional arguments for providing Endian type. By default data is parsed as being Big Endian Low Word first endian.

Exaple: getting uint32 value as Little Endian Low Word First

1bit - 16bit data types

1-16bit data types are hold by Word class which hold 2 bytes of data.

Following methods exists to get different types out of single Word instance:

and following additional methods:

32bit data types

17-32bit data types are hold by DoubleWord class which hold 4 bytes of data.

Following methods exists to get different types out of single DoubleWord instance:

and following additional methods:

64bit data types

64bit data types are hold by QuadWord class which hold 8 bytes of data. NB: 64-bit PHP supports only up to 63-bit (signed) integers.

Following methods exists to get different types out of single QuadWord instance:

and following additional methods:

Strings

ASCII (8bit character) string can be extracted from response as utf-8 string

Example of Modbus TCP (fc3 - read holding registers)

Some of the Modbus function examples are in examples/ folder

Advanced usage:

Request multiple packets with higher level API:

Response structure

Low level - send packets:

Example of Modbus RTU over TCP

Difference between Modbus RTU and Modbus TCP is that:

  1. RTU header contains only slave id. TCP/IP header contains of transaction id, protocol id, length, unitid
  2. RTU packed has 2 byte CRC appended

See http://www.simplymodbus.ca/TCP.htm for more detailsed explanation

This library was/is originally meant for Modbus TCP but it has support to convert packet to RTU and from RTU. See this examples/rtu.php for example.

Example of Modbus RTU over USB to Serial (RS485) adapter

See Linux example in 'examples/rtu_usb_to_serial.php'

Example of Modbus RTU over TCP + higher level API usage

See example in 'examples/rtu_over_tcp_with_higherlevel_api.php'

Example of non-blocking socket IO with ReactPHP/Amp (i.e. modbus request are run in 'parallel')

Example Modbus server (accepting requests) with ReactPHP

Try communication with PLCs quickly using php built-in web server

Examples folder has index.php which can be used with php built-in web server to test out communication with our own PLCs.

Now open http://localhost:8080 in browser. See additional query parameters from index.php.

Changelog

See CHANGELOG.md

Tests

For Windows users:

Static analysis

Run PHPStan analysis compose check


All versions of modbus-tcp-client with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0
ext-mbstring Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package aldas/modbus-tcp-client contains the following files

Loading the files please wait ....