<?php require_once dirname(__FILE__) . '/../../Phpmodbus/ModbusMasterUdp.php'; // Received bytes interpreting Mixed values $data = array("0" => 125, "1" => 98, "2" => 0, "3" => 0, "4" => 0, "5" => 0, "6" => 0, "7" => 0, "8" => 0, "9" => 0, "10" => 0, "11" => 0, "12" => 255, "13" => 255, "14" => 255, "15" => 255, "16" => 158, "17" => 88, "18" => 97, "19" => 168); // Print mixed values foreach ($data as $d) { echo ord(IecType::iecBYTE($d)) . "<br>"; }
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>\n"; return $str; } echo "Endianing off <hr>\n"; // Print mixed values for ($i = 0; $i < count($data); $i++) { echo $data[$i] . " --> "; $v = IecType::iecREAL($data[$i], 0); echo printPacket($v); "<br>\n"; } echo "Endianing on <hr>\n"; // Print mixed values for ($i = 0; $i < count($data); $i++) { echo $data[$i] . " --> "; $v = IecType::iecREAL($data[$i], 1); echo printPacket($v); "<br>\n"; }
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>"; }