I want to pass binary strings (in hex format) to the serial port and recieve a binary string in response. The first target is ok, but for the second I encoutered some problems.
The code is something like that:
Code: Select all
$streamSeriale=fopen("COM3:", "w+b");
if(!($streamSeriale)) {
echo "Errore nell'apertura della porta seriale.";
}
else {
define("LEGGI_TEMP", "010300010001D5CA");
$hexString = SET_TEMP;
$binString = pack("H16",$hexString);
fwrite($streamSeriale, $binString);
fflush($streamSeriale);
sleep(1);
$read_string = '';
//while ($read_string=="")
while(!feof($streamSeriale))
$stringaLetta = fread($streamSeriale,7);
/******************************************
At this point the script waits indefinitely....
**************************************/
}
pack("H*", bin2hex($read_string));
echo "Valore letto: $read_string";
*/
}Even though the COM port recieve buffer is limited, there should be a "software buffer" provided by the O.S. (win in this case)... and the data shouldn't be lost!
Note that I've tried to comunicate with my serial modem and in this case the reception works(but in thsi case I recieve AT strings, not binary packets).
I'll thank anybody who has an idea about what could be the problem...this situation is frustrating me!!! Thanks.
Msssimo