added a namespace

pull/1/head
Ondřej Hruška 9 years ago
parent c676c06e2e
commit 5300b2a867
  1. 4
      .gitignore
  2. 2
      .hgignore
  3. 7
      .hgtags
  4. 27
      LICENSE
  5. 82
      README.md
  6. 32
      composer.json
  7. 3
      examples/README.md
  8. 3
      src/IecType.php
  9. 6
      src/ModbusMaster.php
  10. 5
      src/ModbusMasterTcp.php
  11. 5
      src/ModbusMasterUdp.php
  12. 3
      src/PhpType.php
  13. 3
      tests/README.md
  14. 210
      tutorials/Phpmodbus/Phpmodbus.pkg
  15. BIN
      tutorials/Phpmodbus/wago_logo.png

4
.gitignore vendored

@ -0,0 +1,4 @@
/vendor
composer.lock
*~

@ -1,2 +0,0 @@
vendor
.svn

@ -1,7 +0,0 @@
a88b5a87fb4cd49f16ce72062cce19d55f1fbf98 0.2
a7f90c18859d31922bdd8c61299e2790f5e2eb1a 0.3
bdf8b3f414c4d08fc0edf9fd1953f55db26e4bac 0.4
1e09b0da7d8c62a9a292ee51540feac9de4c1222 0.4.1
e1262f028e180c2719564f840ffa1a9f8672b6be 0.5
079f8ac1f49faf4e6bbb84d62c39eee1507805f2 0.6
5885b1a0d0dc89577eeb871ee2c3fba8e70dd4fb 0.7

@ -1,3 +1,26 @@
+---------------------------------------------------------+
| ACKNOWLEDGEMENTS |
+---------------------------------------------------------+
This project is based on work by Jan Krákora, (c) 2004-2013.
The original license is reproduced below.
https://code.google.com/archive/p/phpmodbus/
Further improvements - John S. Long and other contributors
https://github.com/adduc/phpmodbus
Cleanup and namespaces - Ondřej Hruška, 2016
https://github.com/MightyPork/phpmodbus
+---------------------------------------------------------+
| ORIGINAL LICENSE |
+---------------------------------------------------------+
The Phpmodbus License, Version 1
============================
@ -60,3 +83,7 @@ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
End of file.

@ -1,45 +1,47 @@
phpmodbus
=========
This project deals with an implementation of the basic functionality of the Modbus TCP and UDP based protocol using PHP.
It's a copy of the releases from the project page over at [Google Code](https://code.google.com/p/phpmodbus/) with
composer support added.
Features
--------
* Modbus master
* FC1 - Read coils
* FC2 - Read input discretes
* FC3 - Read holding registers
* FC4 - Read holding input registers
* FC5 - Write single coil
* FC6 - Write single register
* FC15 - Write multiple coils
* FC16 - Write multiple registers
* FC22 - Mask Write register
* FC23 - Read/Write multiple registers
Example
-------
# phpmodbus
Implementation of the basic functionality of the Modbus TCP and UDP based protocol using PHP.
This is a fork of the original project at https://code.google.com/p/phpmodbus/
> **What's new**
>
> This fork adds a namespace and fixes issues encountered when porting to PHP 7
Implemented features:
* Modbus master
* FC1 - Read coils
* FC2 - Read input discretes
* FC3 - Read holding registers
* FC4 - Read holding input registers
* FC5 - Write single coil
* FC6 - Write single register
* FC15 - Write multiple coils
* FC16 - Write multiple registers
* FC23 - Read/Write multiple registers
Example:
```php
// Modbus master UDP
$modbus = new ModbusMaster("192.168.1.1", "UDP");
// Read multiple registers
try {
$recData = $modbus->readMultipleRegisters(0, 12288, 5);
}
catch (Exception $e) {
// Print error information if any
echo $modbus;
echo $e;
exit;
}
// Print data in string format
echo PhpType::bytes2string($recData);
require_once dirname(__FILE__) . '/Phpmodbus/ModbusMaster.php';
// Modbus master UDP
$modbus = new ModbusMaster("192.168.1.1", "UDP");
// Read multiple registers
try {
$recData = $modbus->readMultipleRegisters(0, 12288, 5);
}
catch (Exception $e) {
// Print error information if any
echo $modbus;
echo $e;
exit;
}
// Print data in string format
echo PhpType::bytes2string($recData);
```
For more see [documentation][] or [FAQ][].
For more see [http://code.google.com/p/phpmodbus/downloads/list documentation] or [http://code.google.com/p/phpmodbus/wiki/FAQ FAQ].
[documentation]: https://code.google.com/p/phpmodbus/downloads/list
[FAQ]: https://code.google.com/p/phpmodbus/wiki/FAQ
Note:
* The PHP extension php_sockets.dll should be enabled (server php.ini file)

@ -1,17 +1,21 @@
{
"name": "adduc/phpmodbus",
"description": "Composer version of PhpModBus",
"license": "LGPL",
"authors": [
{
"name": "Honza Krakora",
"email": "krakora.jan@googlemail.com"
}
],
"autoload": {
"classmap": [ "Phpmodbus" ]
},
"require": {
"ext-sockets": "*"
"name": "MightyPork/phpmodbus",
"keywords": ["phpmodbus","modbus"],
"description": "PhpModbus with namespaces and updated to PHP 7",
"license": "LGPL",
"require": {
"php": "^5.3.2 || ^7.0",
"ext-sockets": "*"
},
"authors": [
{
"name": "Honza Krakora",
"email": "krakora.jan@googlemail.com"
}
],
"autoload": {
"psr-4": {
"PHPModbus\\": "src/"
}
}
}

@ -0,0 +1,3 @@
Those examples have not been updated to use namespaces.
They may not work. Just for reference.

@ -1,4 +1,7 @@
<?php
namespace PHPModbus;
/**
* Phpmodbus Copyright (c) 2004, 2013 Jan Krakora
*

@ -1,4 +1,7 @@
<?php
namespace PHPModbus;
/**
* Phpmodbus Copyright (c) 2004, 2013 Jan Krakora
*
@ -15,9 +18,6 @@
*
*/
require_once dirname(__FILE__) . '/IecType.php';
require_once dirname(__FILE__) . '/PhpType.php';
/**
* ModbusMaster
*

@ -1,4 +1,7 @@
<?php
namespace PHPModbus;
/**
* Phpmodbus Copyright (c) 2004, 2012 Jan Krakora
*
@ -15,8 +18,6 @@
*
*/
require_once dirname(__FILE__) . '/ModbusMaster.php';
/**
* ModbusMasterTcp
*

@ -1,4 +1,7 @@
<?php
namespace PHPModbus;
/**
* Phpmodbus Copyright (c) 2004, 2012 Jan Krakora
*
@ -15,8 +18,6 @@
*
*/
require_once dirname(__FILE__) . '/ModbusMaster.php';
/**
* ModbusMasterUdp
*

@ -1,4 +1,7 @@
<?php
namespace PHPModbus;
/**
* Phpmodbus Copyright (c) 2004, 2012 Jan Krakora
*

@ -0,0 +1,3 @@
Probably broken and dubious.
Left from the original repo.

@ -1,210 +0,0 @@
<refentry id="{@id}">
<refnamediv>
<refname>Phpmodbus user's guide</refname>
<refpurpose>Phpmodbus How-to</refpurpose>
</refnamediv>
<refsynopsisdiv>
<author>
Jan Krakora
<authorblurb>
{@link mailto:krakora.jan@googlemail.com email}
</authorblurb>
</author>
</refsynopsisdiv>
{@toc}
<refsect1 id="{@id intro}">
<title>Introduction</title>
<para>
Phpmodbus is a PHP library for the Modbus protocol. The library implements
Modbus TCP/UDP master class with subset of the most used Modbus commands.
</para>
<para>
The library implements:
<itemizedlist>
<listitem><para>FC 1: read multiple coils</para></listitem>
<listitem><para>FC 2: read input discretes</para></listitem>
<listitem><para>FC 3: read multiple registers</para></listitem>
<listitem><para>FC 4: read multiple input registers</para></listitem>
<listitem><para>FC 5: write single coil</para></listitem>
<listitem><para>FC 6: write single register</para></listitem>
<listitem><para>FC 15: write multiple coils</para></listitem>
<listitem><para>FC 16: write multiple registers</para></listitem>
<listitem><para>FC 23: read write registers</para></listitem>
</itemizedlist>
</para>
<para>
For more about Modbus protocol see [{@link http://www.modbus.org}] or
[{@link http://en.wikipedia.org/wiki/Modbus Wiki}]
</para>
</refsect1>
<refsect1 id="{@id install}">
<title>Install</title>
<para>
At the first, it is supposed an PHP solution has been already installed on
your server (LAMP, WAMP, MSS+CGI etc.).
</para>
<para>
Copy the Phpmodbus library to your PHP project folder.
</para>
<para>
Create a PHP script and assign the library using require_once() command
<programlisting role="c">
<![CDATA[require_once dirname(__FILE__) . '/Phpmodbus/ModbusMaster.php'; ]]>
</programlisting>
</para>
<para>
To create UDP Modbus master object communicating to an modbus slave
e.g. at IP address 192.168.1.1 write
<programlisting role="c" linenumbering="numbered" startinglinenumber="2">
<![CDATA[ $modbus = new ModbusMaster("192.168.1.1", "UDP"); ]]>
</programlisting>
</para>
<para>
To create TCP Modbus master use
<programlisting role="c" linenumbering="numbered" startinglinenumber="2">
<![CDATA[ $modbus = new ModbusMaster("192.168.1.1", "TCP"); ]]>
</programlisting>
</para>
<para>
To read 5 words (10 bytes) from the device ID=0 and its memory address 12288
use try-catch method call
<programlisting role="c" linenumbering="numbered" startinglinenumber="3">
<![CDATA[try {
// Function processing
$recData = $modbus->readMultipleRegisters(0, 12288, 5);
}
catch (Exception $e) {
// Exception processing, e.g. print error information
echo $modbus;
echo $e;
exit;
}]]>
</programlisting>
</para>
<para>
To process the function byte stream, use conversion to PHP types in
</para>
<programlisting role="c" linenumbering="numbered" startinglinenumber="15">
<![CDATA[echo PhpType::bytes2string($recData); ]]>
</programlisting>
<para>
For other examples see sections bellow.
</para>
</refsect1>
<refsect1 id="{@id examples}">
<title>Examples</title>
<para>
This section presents library features and examples
</para>
<refsect2 id="{@id example_fc1}">
<title>FC1 - read mutliple coils</title>
<para>
FC1 functionality example
</para>
<para>
{@example example_fc1.php}
</para>
</refsect2>
<refsect2 id="{@id example_fc2}">
<title>FC2 - read input discretes</title>
<para>
FC2 functionality example
</para>
<para>
{@example example_fc2.php}
</para>
</refsect2>
<refsect2 id="{@id example_fc3}">
<title>FC3 - read mutliple registers</title>
<para>
FC3 functionality example
</para>
<para>
{@example example_fc3.php}
</para>
</refsect2>
<refsect2 id="{@id example_fc4}">
<title>FC4 - read multiple input registers </title>
<para>
FC4 functionality example
</para>
<para>
{@example example_fc4.php}
</para>
</refsect2>
<refsect2 id="{@id example_fc5}">
<title>FC5 - write single coil</title>
<para>
FC5 functionality example
</para>
<para>
{@example example_fc5.php}
</para>
</refsect2>
<refsect2 id="{@id example_fc6}">
<title>FC6 - write single register</title>
<para>
FC6 functionality example
</para>
<para>
{@example example_fc6.php}
</para>
</refsect2>
<refsect2 id="{@id example_fc15}">
<title>FC15 - write mutliple coils</title>
<para>
FC15 functionality example
</para>
<para>
{@example example_fc15.php}
</para>
</refsect2>
<refsect2 id="{@id example_fc16}">
<title>FC16 - write mutliple registers</title>
<para>
FC16 functionality example
</para>
<para>
{@example example_fc16.php}
</para>
</refsect2>
<refsect2 id="{@id example_fc23}">
<title>FC23 - read write registers</title>
<para>
FC23 functionality example
</para>
<para>
{@example example_fc23.php}
</para>
</refsect2>
<refsect2 id="{@id wago_example}">
<title>Dump of M-memory from WAGO 750-84x series coupler.</title>
<para>
Dump of M-memory from WAGO 750-84x series coupler.
</para>
<para>
{@example example_750841_Mmemory.php}
</para>
</refsect2>
<refsect2 id="{@id datatype}">
<title>Data conversion to PHP types.</title>
<para>
Conversion of the data bytes, received from Modbus, to a PHP type.
</para>
<para>
{@example example_datatype.php}
</para>
</refsect2>
</refsect1>
<refsect1 id="{@id back_comp}">
<title>Back compatibility</title>
<para>
This version is back compatible to the last versions. Just use
<programlisting role="c">
<![CDATA[require_once dirname(__FILE__) . '/Phpmodbus/ModbusMasterUdp.php';
$modbus = new ModbusMasterUdp("192.168.1.1");
// ... ]]>
</programlisting>
</para>
</refsect1>
</refentry>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

Loading…
Cancel
Save