TheUnknownOnes / phosphor7

The translation of the fabulous Snap7 library to PHP
Apache License 2.0
10 stars 10 forks source link

Problem using PHP8.0 #7

Closed JosepFarreLlados closed 1 year ago

JosepFarreLlados commented 1 year ago

Connecting with Siemens LOGO OBA8 and PHP7.4, read and write examples works (/phosphor7/examples/ ). Using PHP8.0 DBRead function return wrong values. Any feedback with PHP8?

dixi83 commented 1 year ago

I think we have a classic big/little endian issue here... Can you post the var_dump($buffer), the output you get and the expected value? Thanks

BTW... does a logo support AreaDB 0x84?? I have no recent experience with LOGO's but the old ones certainly didn't. Maybe the 8 series have this because PHP7.4 could read it as @JosepFarreLlados said.

JosepFarreLlados commented 1 year ago

Using "read_db.php" code as follows:

  1. <?php
  2. require_once("../src/phosphor7.php");
  3. $c = new TSnap7MicroClient();
  4. $c->ConnectTo("192.168.1.102", 1, 0);
  5. $buffer = "";
  6. $c->DBRead(1, 132, 4, $buffer);
  7. var_dump(bin2hex($buffer));
  8. $c->Disconnect();
  9. ?>

*using PHP7.4, the var_dump($buffer) output is: /Test.php:12: string(8) "00000005"

*using PHP8, the var_dump($buffer) output is: /Test.php:12: string(0) ""

The expected value is "00000005", according with PHP7.4. I'm using LOGO OBA8 version: 6ED1 052-1FB00-0BA8. With PHP7.4 I can use examples "read_db" and "write_db" correctly.

dixi83 commented 1 year ago

Thanks, I was wrong, the problem lies deeper. From PHP7 to 8 PHP changed a lot of recources to Objects: https://www.php.net/manual/en/migration80.incompatible.php#migration80.incompatible.resource2object

we need to change is_resource($this->FSocket) to is_resource($this->FSocket) || $this->FSocket instanceof Socket

I am already working on this. @FabrizioC or @chaosben expect a pull request in the coming days. I don't have access to a LOGO! 8 but i have S7-300 and a 1200 available to test stuff. if this works, a LOGO should work as well. I think @JosepFarreLlados can confirm this if it works.