Hello everybody.
I've developed a script that communicates with a weight scale serial port and prints the data to the user.
Here's how I make the connection:
$port='COM6';
$baud='4800';
$data='7';
$stop='1';
$parity='N';
$xon='on';
$command = exec('mode '.$port.': baud='.$baud.' data='.$data.' stop='.$stop.' parity='.$parity.' xon='.$xon.'');
$fd = dio_open($porta.':', O_RDWR | O_NOCTTY | O_NONBLOCK);
if(!$fd)
{
echo "Error to access {$port}!";
}
else
{
sleep(5);
while (true)
{
$buffer = dio_read($fd);
if ($buffer)
{
echo $buffer;
}
sleep(1);
}
dio_close($fd);
}
The problem is that the script only works correctly after I open a connection with Hyperterminal or PUTTY. It looks like the PHP itself doesn't open the connection with port COM6. If I try to run the script without opening a connection without Hyperterminal or PUTTY, it doesn't read anything.
Someone know why is this happening? I'm using Windows, Apache 2.2 and PHP 5.3
Thanks in advance and sorry for my english.