Serial port programming
Posted: Tue Feb 15, 2005 4:56 am
I've spent time searching in the web, but it seems that nobody has written php scripts comunicating with a serial controller through COM port.
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:
As I said I expect to recieve 7 byte in response of the sent message, but nothing is read! I've tested the same string with a "serial port monitor" and everything goes on...the COM port recieves the right 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
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