Skip to content
This repository has been archived by the owner on Apr 18, 2023. It is now read-only.

Problem to convert in float #2

Open
ELGUEROUEL opened this issue Jan 4, 2020 · 3 comments
Open

Problem to convert in float #2

ELGUEROUEL opened this issue Jan 4, 2020 · 3 comments

Comments

@ELGUEROUEL
Copy link

require_once("../src/phosphor7.php");

$c = new TSnap7MicroClient();

$c->ConnectTo("10.11.6.2", 0, 0);

$buffer = "";
$c->DBRead(7, 48, 2, $buffer); // I want read value of energy
var_dump(bin2hex($buffer));
$c->Disconnect();
I have in output 477d but it is false ( because is not real)

@chaosben
Copy link
Collaborator

I'm sorry, but i have no cpu to test it.
Can anyone else please test and debug this issue?

@ELGUEROUEL
Copy link
Author

thanks for your replay .
I tested it .
I have a cpu 1500

@cervejapils
Copy link

If you want lo read a float value (in PLC named REAL), use s7_phphelper::getS7_Real.
I test it on S7-300 CPU and work well.
Remember to read 4bytes for every REAL value.

require_once("../src/phosphor7.php");
require_once("../src/s7_phphelper.php");

$c = new TSnap7MicroClient();

$c->ConnectTo("192.168.1.216", 0, 2);
$floatBuff = "";
$c->DBRead(101, 38, 8, $floatBuff);    // from DB101.DBB38 for 8 bytes
$c->Disconnect();

$fVal  = s7_phphelper::getS7_Real($floatBuff, 0);
echo "1st float: " . $fVal . "\n";    // 12.34 in my PLC

$fVal  = s7_phphelper::getS7_Real($floatBuff, 4);
echo "2nd float: " . $fVal . "\n";    // 5.6 in my PLC

For S7-1500 the data block must have the flag optimized block off.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants