Possible Duplicate:
PHP preg_match to get a word after space, which is where it a word KG
I'm developing web application with PHP,My apps is communicate with scale digital, i'm using help with phpserial class. My problem is data is output in my browser mistmatch with output in scale digital. When in scale digital is 16KG, so in browser output is NT,ST+16KG and then i refresh again the browser get other, like ~!NT,ST+16KG, 16KG. My question, how to get data in browser just 16KG.
This is script to read data:
<?php
$serial = new phpSerial();
$serial->deviceSet("/dev/ttyUSB1");
$serial->confBaudRate(9600); //Baud rate: 9600
$serial->confParity("none"); //Parity (this is the "N" in "8-N-1")
$serial->confCharacterLength(8); //Character length (this is the "8" in "8-N-1")
$serial->confStopBits(1); //Stop bits (this is the "1" in "8-N-1")
$serial->confFlowControl("none");
$serial->deviceOpen();
$serial->sendMessage(chr(1));
$tes = $serial->readPort();
print_r($tes);
// get result ~!NT,ST+16KG, 16KG or NT,ST+16KG
$serial->deviceClose();
?>
And this is code function readPort from class phpSerial.
function readPort ($count = 0) {
if ($this->_dState !== SERIAL_DEVICE_OPENED)
{
trigger_error("Device must be opened to read it", E_USER_WARNING);
return false;
}
$content = ""; $i = 0;
if ($count !== 0)
{
do {
if ($i > $count) $content .= fread($this->_dHandle, ($count - $i));
else $content .= fread($this->_dHandle, 128);
} while (($i += 128) === strlen($content));
}
else
{
do {
$content .= fread($this->_dHandle, 128);
} while (($i += 128) === strlen($content));
}
return $content;
}
I'm developing use linux, port scale digital detect in /dev/ttyUSB1, i mean this problem is ASCII, so any help me with my problem. Thanks.