0
我有Metler Toledo BC60網絡支持的體重秤。 它在我的本地網絡上使用本地IP地址。我可以ping通它,並通過端口82連接到它。如果我發送它一個「W」,然後按Enter鍵,我得到一個從它返回的數字,這是當時的重量。通過PHP套接字從Metler Toledo BC60網絡支持的體重秤讀取體重
如何通過PHP訪問此重量以用於我的應用程序?
我的想法是這樣的,但是我沒有得到任何東西:
<?php
// host and port to connect to
$host = "192.168.0.115";
$port = 82;
// connect to the port
$fp = fsockopen($host, $port, $errno, $errstr);
// if connection not successfull, display error
if (!$fp)
{
die("no connection");
}
else
{
// connection successfull
fwrite($fp, "W\r\n"); //Request Weight
$got = fgets($fp);
// display the data
echo $got;
fclose($fp);
die();
}
?>
該代碼對我來說看起來不錯。檢查'fwrite()'的返回值以確保它不是錯誤的。並做一個'var_dump($ got);'來看看你是否得到了空字符串vs false。 –
您可能還想嘗試'ini_set(「auto_detect_line_endings」,true);' –