GithubHelp home page GithubHelp logo

phpmodbus's People

Watchers

 avatar

phpmodbus's Issues

read coil : the length of received data is wrong

What steps will reproduce the problem?
1.Use the exmaple "example_fc1.php".

What is the expected output? What do you see instead?

If I want to read 10 coils :

the excepted output
it will show me 10 coils state.

instead output
it shows  me 11 coils.

What version of the product are you using? On what operating system?
Phpmodbus_0.5.r70

Please provide any additional information below.
the line 305 of the file "ModbusMaster.php" should be modified as following:

if($di == $quantity) continue;

Original issue reported on code.google.com by [email protected] on 2 May 2012 at 10:16

modbus query failed first time

What steps will reproduce the problem?
1.I am trying to connect and read some registers from a remote device
2.When the remote device is connected through 3G router the first attempt 
usually fails
3.After one or two refreshes I can read registers
4. Timeout parameter doesn't seem to help

What is the expected output? What do you see instead?
Error message at the first atempt is:
readMultipleRegisters: START
exception 'Exception' with message 'socket_connect() failed.
Reason: ()Operation now in progress' in 
/home/public_html/functions/Phpmodbus/ModbusMaster.php:109 Stack trace: #0 

What version of the product are you using? On what operating system?
phpmodbus0.8

Please provide any additional information below.


Original issue reported on code.google.com by [email protected] on 7 May 2014 at 8:00

Implementing Modbus Read Input Registers 04 (0x04)

We are working with a modbus device using all kind of holding and input 
registers. (Here input register are labelled according to doc: MODBUS 
APPLICATION PROTOCOL SPECIFICATION V1.1b3). We need to read information from 
both register types and the device follows the register addressing and function 
codes to read them canonically.

Looking at the protocol there is no fundamental difference between the already 
implemented FC3 and the proposed FC4 function codes besides the function code 
used on the modbus interface.

We propose the following addition to the code to handle FC4:

    // Patch 2013-03-08 to introduce FC4 read input registers

  /**
   * readMultipleInputRegisters
   *
   * Modbus function FC 4(0x04) - Read Multiple Input Registers.
   * 
   * This function reads {@link $quantity} of Words (2 bytes) from reference 
   * {@link $referenceRead} of a memory of a Modbus device given by 
   * {@link $unitId}.
   *    
   *
   * @param int $unitId usually ID of Modbus device 
   * @param int $reference Reference in the device memory to read data.
   * @param int $quantity Amounth of the data to be read from device.
   * @return false|Array Success flag or array of received data.
   */
  function readMultipleInputRegisters($unitId, $reference, $quantity){
    $this->status .= "readMultipleInputRegisters: START\n";
    // connect
    $this->connect();
    // send FC 4    
    $packet = $this->readMultipleInputRegistersPacketBuilder($unitId, $reference, $quantity);
    $this->status .= $this->printPacket($packet);    
    $this->send($packet);
    // receive response
    $rpacket = $this->rec();
    $this->status .= $this->printPacket($rpacket);    
    // parse packet    
    $receivedData = $this->readMultipleInputRegistersParser($rpacket);
    // disconnect
    $this->disconnect();
    $this->status .= "readMultipleInputRegisters: DONE\n";
    // return
    return $receivedData;
  }

  /**
   * fc4
   *
   * Alias to {@link readMultipleInputRegisters} method.
   *
   * @param int $unitId
   * @param int $reference
   * @param int $quantity
   * @return false|Array
   */
  function fc4($unitId, $reference, $quantity){
    return $this->readMultipleInputRegisters($unitId, $reference, $quantity);
  }  

  /**
   * readMultipleInputRegistersPacketBuilder
   *
   * Packet FC 4 builder - read multiple input registers
   *
   * @param int $unitId
   * @param int $reference
   * @param int $quantity
   * @return string
   */
  private function readMultipleInputRegistersPacketBuilder($unitId, $reference, $quantity){
    $dataLen = 0;
    // build data section
    $buffer1 = "";
    // build body
    $buffer2 = "";
    $buffer2 .= iecType::iecBYTE(4);                                                // FC 4 = 4(0x04)
    // build body - read section    
    $buffer2 .= iecType::iecINT($reference);                                        // refnumber = 12288      
    $buffer2 .= iecType::iecINT($quantity);                                         // quantity
    $dataLen += 5;
    // build header
    $buffer3 = '';
    $buffer3 .= iecType::iecINT(rand(0,65000));                                     // transaction ID
    $buffer3 .= iecType::iecINT(0);                                                 // protocol ID
    $buffer3 .= iecType::iecINT($dataLen + 1);                                      // lenght
    $buffer3 .= iecType::iecBYTE($unitId);                                          // unit ID
    // return packet string
    return $buffer3. $buffer2. $buffer1;
  }

  /**
   * readMultipleInputRegistersParser
   *
   * FC 4 response parser
   *
   * @param string $packet
   * @return array
   */
  private function readMultipleInputRegistersParser($packet){    
    $data = array();
    // check Response code
    $this->responseCode($packet);
    // get data
    for($i=0;$i<ord($packet[8]);$i++){
      $data[$i] = ord($packet[9+$i]);
    }    
    return $data;
  }
    // End of patch 2013-03-08


As the original modbus document calls FC3 Read Holding Registers The proposed 
solution leaves the existing FC3 as PHP function readMultipleRegisters and 
introduces FC4 as readMultipleInputRegisters


Original issue reported on code.google.com by [email protected] on 8 Mar 2013 at 2:13

TCP Socket connect timeout

What steps will reproduce the problem?
1. connection OK, loop on readcoils OK
2. unplug network cable


What is the expected output? What do you see instead?
Socket connect timeout should be $this->$timeout_sec.
Instead, the system TCP/syn timeout apply.


What version of the product are you using? On what operating system?
last version

Please provide any additional information below.
in ModbusMaster.php, after "// Connect the socket", I added :
    socket_set_option($this->sock, SOL_SOCKET, SO_SNDTIMEO, array('sec' => $this->$timeout_sec, 'usec' => 0));

Thuis solves the problem.


Thank you for your lib, it is usefull !

Best regards,
Gautier Husson


Original issue reported on code.google.com by [email protected] on 24 Sep 2012 at 8:23

Attachments:

Problem with endianness

Hi,
I'm using the lastest version of PHP (5.3) and phpmodbus returns some errors in 
this version. Researching, I've found an error (or so I think) with the 
variable "endianess" (endianness). In the lastest version of phpmodbus, you 
specify the variable "endianness" into the methods as 0, but exist a "global" 
variable called "endianess" that isn't used. I think the solution is to replace 
the var "$endianness" for "$this->endianess" in the methods.

Thanks


Original issue reported on code.google.com by [email protected] on 7 Sep 2011 at 9:44

Missing PhpType::bytes2string function

What steps will reproduce the problem?
1. Missing PhpType::bytes2string function

What is the expected output? 
PhpType::bytes2string($bytes) returns s string included in bytes "" (ASCII
coding)



Original issue reported on code.google.com by [email protected] on 13 May 2009 at 12:25

()Connection Refused

What steps will reproduce the problem?
All

What is the expected output? What do you see instead?

System = Embedded, running apache server with php5 (php works).

Running 'test.fc26.php', watching log output I get a '()connection refused'.  
I've verified that port 502 is open and the sockets are enabled in php build.

What version of the product are you using? On what operating system?

Using latest version of the product on Ubuntu 12.10.

Please provide any additional information below.

Trying to communicate with an IDEC D12 Type PLC.  PLC is listening on port 502.


Original issue reported on code.google.com by [email protected] on 27 Jun 2013 at 3:15

Problem to connect without localhost

What steps will reproduce the problem?
1. Conncection OK from localhost 
2. Connection fail without localhost


What is the expected output? What do you see instead?
No connect error message

What version of the product are you using? On what operating system?
Phpmodbus_0.5.r70 and Windows 7

Please provide any additional information below.
Is necessary to do any change or additional configuration to test from a 
external server?
The excepcion message:
exception 'Exception' with message 'socket_connect() failed.
Reason: ()Connection refused' in /home/public_html/example/ModbusMaster.php:102

I have tested in others hosting providers and the result is similar but not the 
same:
Warning: socket_connect() [function.socket-connect]: unable to connect [110]: 
Connection timed out in 
/home/u634979041/public_html/driver/ModbusSocketsDriver.php on line 100
readCoils: START
exception 'Exception' with message 'socket_connect() failed.
Reason: ()Connection timed out' in 
/home/public_html/example/ModbusMaster.php:102

Original issue reported on code.google.com by [email protected] on 2 Dec 2012 at 11:36

TCP ?

Is it possible to get it in TCP ?


Original issue reported on code.google.com by [email protected] on 13 Sep 2011 at 2:17

FC 3 and FC 4

How can i read the registers 30000-3XXXXX (Analoge Inputs)?
The example FC3 and FC4 are similar. And booth are reading the registers 
40000-XXXXXX.
Any ideas or solutions for this problem?

Original issue reported on code.google.com by sponi78 on 24 Sep 2014 at 7:24

Modifications I had to make.

Hello Jan,
You can find my modifications between the two lines in the attached files:
// ddileo start
modification....
// ddileo end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Issues:
The "local port number" used to change every time I called the function.
My server used to accept the requests from only one port.
I had to bind the socket to a specific local port ("socket_bind").
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
In order to avoid Warnings from my server I had to add the following 
declaration:
$endianness = 0;
and initialization:
$rpacket = str_pad('',256);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Many thank for your work.
Have a nice 2011.

Daniele Di Leo

Original issue reported on code.google.com by [email protected] on 1 Jan 2011 at 5:59

Attachments:

Undefined Variable: buffer1

What steps will reproduce the problem?

execute example_750841_Mmemory.php


What is the expected output? What do you see instead?

Undefined variable: buffer1 in ModbusMasterUdp.php on line 239


Original issue reported on code.google.com by [email protected] on 13 Feb 2010 at 7:06

The bytes are inverted in a word

Hi all,

I've a device where the bytes are inverted.
I had to exchange their position to get the right value.

This is applicable for the PLC T-Box, the AC Monitor PQube, ...

The possibility to invert the bytes should be includes in the class.

File : PhpType.php
------------------
public static function bytes2float($values, $endianness = 0) {
        $data = array();
        $real = 0;

        //HDT : invert the position of the bytes
        $values0=$values[0];
        $values1=$values[1];
        $values[0]=$values[2];
        $values[1]=$values[3];
        $values[2]=$values0;
        $values[3]=$values1;

        // Set the array to correct form
        $data = self::checkData($values);
        // Combine bytes
        $real = self::combineBytes($data, $endianness);
        // Convert the real value to float
        return number_format((float) self::real2float($real),2);
    }


Original issue reported on code.google.com by [email protected] on 4 Sep 2013 at 2:31

readMultipleRegisters decimal and hexadecimal

What steps will reproduce the problem?
1.$recData = $modbus->readMultipleRegisters(100, 100, 10);


What is the expected output? What do you see instead?
Most of the time the result in the array is in hexadecimal, sometimes in 
decimal.

What version of the product are you using? On what operating system?
last

Please provide any additional information below.
Check this:
http://novacontrol.com.ve/smw/index.old.php
D0 = 1  D1 = 1 (hexadecimal)
D14 = 0 D15 = 255 (decimal)

Original issue reported on code.google.com by [email protected] on 17 Nov 2012 at 8:03

IecType::float2iecReal() does not return correct value type

1. IecType::float2iecReal() does not return iecReal type value, but PHP
integer. The IecType::iecReal2float() value input is PHP integer, but not
iecReal.

I expect the iecReal return as made by IecType::iecReal() or renaming of
those functions.

I advice to add two new functions
* IecType::float2real() that returns PHP integer interpretation of real
* IecType::real2float() with input as PHP integer
and to change the function functionality
* IecType::float2iecReal() will return iecReal of real
* IecType::iecReal2float() will have input as iecReal of real

Original issue reported on code.google.com by [email protected] on 20 Jan 2009 at 12:31

Documentation mistake

I have found a mistake in documentation of the readWriteRegisters function.
The text excerpt " ... Simultanously, it returns $quantity of Bytes from
reference  referenceRead." 

Modbus is word (2 bytes) oriented. For that the documentation excerpt
should be " ... Simultaneously, it returns $quantity of words (2 bytes)
from reference $referenceRead.". Check also the other functions!!!



Original issue reported on code.google.com by [email protected] on 20 Jan 2009 at 1:12

bytes2float() function

What steps will reproduce the problem?
1. I miss a function that returns PHP float of the 4 bytes that represents
IEC real value.

What is the expected output? 
{{{
/**
 * The function converts array of 4 bytes to float value. The conversion
result 
 * is based on the IEC Real value included in the byte set. The return value 
 * depends on order of the bytes (endianning).
 *   
 */ 
function bytes2float($values, $endianness = 0){
    $real = 0;
    // Combine bytes
    if ($endianness == 0)
      $real = (($values[3] & 0xFF)<<16) | 
        (($values[2] & 0xFF)<<24) | 
        (($values[1] & 0xFF)) | 
        (($values[0] & 0xFF)<<8);
    else
      $real = (($values[3] & 0xFF)<<24) | 
        (($values[2] & 0xFF)<<16) | 
        (($values[1] & 0xFF)<<8) | 
        (($values[0] & 0xFF));
    // Convert the real value to float    
    return IecType::iecReal2float($real);
}
}}}

Please use labels and text to provide additional information.


Original issue reported on code.google.com by [email protected] on 20 Jan 2009 at 12:55

writeSingleRegister does not get any response

What steps will reproduce the problem?
try {
    // FC 3
    // read 1 word (2 bytes) from device ID=1, address=381
    $recData = $modbus->readMultipleRegisters(1, 381, 1);
    $values = array_chunk($recData, 2);
    foreach( $values as $bytes ) {
        $read_value = PhpType::bytes2signedInt($bytes);
        echo "read drop value=".$read_value;
    }
}
catch (Exception $e) {
    // Print error information if any
    echo $modbus;
    echo $e;
    exit;
}
try {
    // FC6
    // Data to be writen
$data = array(61);
$dataTypes = array("INT");
$modbus->writeSingleRegister(0, 381, $data, $dataTypes);
    echo "Written successfully!!!\n";
}
catch (Exception $e) {
    // Print error information if any
    echo $modbus;
    echo $e;
    exit;
}
try {
    // FC 3
    // read 1 word (2 bytes) from device ID=1, address=381
    $recData = $modbus->readMultipleRegisters(1, 381, 1);
    $values = array_chunk($recData, 2);
    foreach( $values as $bytes ) {
        $read_value = PhpType::bytes2signedInt($bytes);
        echo "\nread drop value=".$read_value;
    }
}
catch (Exception $e) {
    echo $modbus;
    echo $e;
    exit;
}


What is the expected output? What do you see instead?
I would of course expect it to first output the original value of address 381 
(which is correctly read = 60), then write a new value (61), and finally read 
that out and print it.

For some reason, the write command does not get any reply and therefore times 
out. However, I tested with another modbus client to do the same thing, and 
logged the traffic with wireshark. (Check the attached files, the not working 
version is made with libphpmodbus).

Here's the output of the script:

The output is:
read drop value=60
readMultipleRegisters: START
Connected
Packet: c5bb000000060103017d0001
Send
Wait data ... 
Data received
Packet: c5bb00000005010302003c
Modbus response error code: NOERROR
Disconnected
readMultipleRegisters: DONE
writeSingleRegister: START
Connected
Packet: 2e30000000060006017d003d
Send
Wait data ... 
Wait data ... 
Wait data ... 
Wait data ... 
Wait data ... 
Wait data ... 
Wait data ... 
Wait data ... 
Wait data ... 
Wait data ... 
Wait data ... 
Wait data ... 
Wait data ... 
Wait data ... 
exception 'Exception' with message 'Watchdog time expired [ 5 sec]!!! 
Connection to 10.0.0.23 is not established.' in 
/home/kristian/public_html/Phpmodbus/ModbusMaster.php:162 Stack trace: #0 
/home/kristian/public_html/Phpmodbus/ModbusMaster.php(537): ModbusMaster->rec() 
#1 /home/kristian/public_html/modbus-reg-test.php(97): 
ModbusMaster->writeSingleRegister(0, 381, Array, Array) #2 {main}



What version of the product are you using? On what operating system?
I'm using Phpmodbus_0.6.r98 on Linux.

Please provide any additional information below.



Original issue reported on code.google.com by [email protected] on 28 Jan 2013 at 8:00

Attachments:

error code exception

What steps will reproduce the problem?
1.If the modbus slave return error code, phpmodbus could not throw the exception

What is the expected output? What do you see instead?

the expected output is as following:
exception 'Exception' with message 'Modbus response error code:1' in 
C:\AppServ\www\Phpmodbus\ModbusMaster.php:180 Stack trace: #0 
C:\AppServ\www\Phpmodbus\ModbusMaster.php(277): 
ModbusMaster->responseCode('Z????????') #1 
C:\AppServ\www\Phpmodbus\ModbusMaster.php(212): 
ModbusMaster->readCoilsParser('Z????????', 10) #2 
C:\AppServ\www\modbus\example_fc1.php(10): ModbusMaster->readCoils(2, 0, 10) #3 
{main}

I see as following:
Modbus response error code: NOERROR

What version of the product are you using? On what operating system?
Phpmodbus_0.5.r70

Please provide any additional information below.
I think the line 179 of the file "ModbusMaster.php" should be modified as 
following:

if((ord($packet[7]) & 0x80) > 0) {

Original issue reported on code.google.com by [email protected] on 2 May 2012 at 8:19

How can I read a register in "FLOAT" data type?

What steps will reproduce the problem?
1. Call Float register
2.
3.

What is the expected output? What do you see instead?
Since the register is in Float the PM1200 from schneider electric Power Meter 
responds with a time out so the script returns the "watchdog" response.


What version of the product are you using? On what operating system?
TCP version of the 2 jan


Please provide any additional information below.
Is there any way to call to a float value and return in a float data type then 
pass it to string o int or any other value so we can use this script to work 
with that meter...

Thanks in advance.


Original issue reported on code.google.com by [email protected] on 19 Jan 2012 at 4:48

Request features

Hi,

very good idea to write it in PHP (rare).

Is it possible to get it in TCP ?

Is it possible to have a config/xml file for repetitive works of
reads/write registers ?

Thanks.

Original issue reported on code.google.com by [email protected] on 11 Mar 2010 at 6:43

Consider LGPL licensing

Hello,

I'm interested in investigating the use of phpmodbus in a commercial software 
package called Ubersmith.

http://www.ubersmith.com/

Unfortunately, without an LGPL license, this is not a possibility. Would you 
consider relicensing the phpmodbus package as LGPL?

http://www.gnu.org/licenses/lgpl.html

Thanks, and have a good week.

Regards,
Mike

Original issue reported on code.google.com by [email protected] on 6 Dec 2012 at 4:39

Custom Request

We can't Create the readSlaveId function (code 0x11) or some Custom function 
without include it ModbusMaster.php due to private function.

There is a way to add some custom function to ModbusMaster class

Original issue reported on code.google.com by [email protected] on 1 Oct 2013 at 8:17

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.