This commit is contained in:
John Long
2013-06-14 07:32:19 -05:00
commit 6b55205c8c
39 changed files with 1884 additions and 0 deletions
+50
View File
@@ -0,0 +1,50 @@
<?php
require_once dirname(__FILE__) . '/../../Phpmodbus/ModbusMasterUdp.php';
// Received bytes interpreting Mixed values
$data = Array (
"0" => 0,
"1" => 1,
"2" => -1,
"3" => pow(2,15)-1,
"4" => -pow(2,15)
);
function byte2hex($value){
$h = dechex(($value >> 4) & 0x0F);
$l = dechex($value & 0x0F);
return "$h$l";
}
function printPacket($packet){
$str = "";
$str .= "Packet: ";
for($i=0;$i<strlen($packet);$i++){
$str .= byte2hex(ord($packet[$i]));
if($i % 2)
$str .= "_";
}
$str .= "</br>";
return $str;
}
echo "Endianing off <hr>";
// Print mixed values
for($i=0;$i<count($data);$i++) {
echo $data[$i] . " --> ";
$v = IecType::iecINT($data[$i], 0);
echo printPacket($v);
"<br>";
}
echo "Endianing on <hr>";
// Print mixed values
for($i=0;$i<count($data);$i++) {
echo $data[$i] . " --> ";
$v = IecType::iecINT($data[$i], 1);
echo printPacket($v);
"<br>";
}
?>