|
Posted by Jerry Stuckle on 12/27/06 01:15
>>I need to read incoming bytes on a COM port but I do not want to have
>>the script hang if there is nothing to read.
>>
>>Is there any way to have PHP interrogate a COM port buffer to see if
>>there is any content before reading it?
>>
>>Any other method to achieve the result would also be welcome.
>>
>>Cheers,
>>
>>Fred.
>
>
(Top posting fixed)
hackajar@gmail.com wrote:
> Windows "COM" ports (like com1, com2, etc) do not have a buffer. They
> are a serial interface that connects directly to the CPU (or CPU bridge
> I suppose with newer motherboards). You will have to be running in a
> loop waiting for data on the COM port to get data off it.
>
> Think:
>
> while(0) {
> $getData = comportcheckfuntion('com1'); //You would have to write
> this function or get one off internet
> if($getData) //do your stuff here
> else sleep(1); //sleep for a second and then let loop check com port
> again.
> }
>
> Cheers,
> Hackajar
> bloggsfred00@hotmail.com wrote:
>
Incorrect.
First of all, the serial port hardware itself has a 16 byte (or larger)
buffer built in.
Secondly, the COM port, like all devices in Windows, goes through a
driver. Your program doesn't talk to the chip itself; it talks to the
driver (through Windows). This driver has two buffers - a transmit and
a receive buffer. And IIRC, both are 4K. But I haven't written any COM
port software since WINNT, so this may have been increased in later
versions.
But it has not been decreased.
P.S. Please don't top post.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Navigation:
[Reply to this message]
|