By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,979 Members | 960 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,979 IT Pros & Developers. It's quick & easy.

Reading COM1 with php-win

P: n/a
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.

Dec 24 '06 #1
Share this Question
Share on Google+
16 Replies


P: n/a
bl**********@hotmail.com wrote:
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.
Look into the COM object for Windows PHP.
Anything you can do with COM, you can do through that object.

Just don't get confused with what's a COM port (communications)
and what's a COM object (Component Object Model).
Dec 24 '06 #2

P: n/a

Sanders Kaufman wrote:
bl**********@hotmail.com wrote:
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.

Look into the COM object for Windows PHP.
Anything you can do with COM, you can do through that object.

Just don't get confused with what's a COM port (communications)
and what's a COM object (Component Object Model).
I didnt think I was confused, but perhaps I am.

Is there a standard COM Object for serial ports that I can instantiate
through PHP?

Dec 24 '06 #3

P: n/a
bl**********@hotmail.com wrote:
Sanders Kaufman wrote:
>Just don't get confused with what's a COM port (communications)
and what's a COM object (Component Object Model).

I didnt think I was confused, but perhaps I am.

Is there a standard COM Object for serial ports that I can instantiate
through PHP?
http://msdn2.microsoft.com/en-gb/library/aa490273.aspx

In Windows - not so much a COM object, as a suite of API's. In
the MSDN documentation, you can learn about the complexity's of
serial port i/o with API's. If you're not already familiar with
programming Windows, there's a pretty steep learning curve for
API's.

If you have rights to install ActiveX controls on the server,
you can probably pick up one of those for a couple of bucks that
will do what you're asking. Then, Serial I/O will be a snap
through PHP.

Dec 25 '06 #4

P: n/a
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
bl**********@hotmail.com wrote:
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.
Dec 25 '06 #5

P: n/a
Yeah, its the
"$getData = comportcheckfuntion('com1'); "
that is the problem.
I have not been able to find any way to implement that.

dio_read allows you to specify a read size but it objects if you make
it less than 1.

Finding out whether the com port has anything readable is the only
impediment to my making it all work.

Thanks anyway.

Fred.

ha******@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
bl**********@hotmail.com wrote:
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.
Dec 25 '06 #6

P: n/a
I had a look at the APIs before I posted here and was praying for an
easier solution. So far no luck. I have used API calls in PHP before so
if it has to be the APIs then so be it, but I could not find an obvious
"is there any bytes to read" call there either.

I had a quick look at the MSCOMM32.OCX information and thought that
might do the trick, but I am not sure how to go about getting installed
on the server. I have full permissions (I built the server) but have
not played with ActiveX and PHP before.

Any guidance most gratefully received.

Fred.

Sanders Kaufman wrote:
bl**********@hotmail.com wrote:
Sanders Kaufman wrote:
Just don't get confused with what's a COM port (communications)
and what's a COM object (Component Object Model).
I didnt think I was confused, but perhaps I am.

Is there a standard COM Object for serial ports that I can instantiate
through PHP?

http://msdn2.microsoft.com/en-gb/library/aa490273.aspx

In Windows - not so much a COM object, as a suite of API's. In
the MSDN documentation, you can learn about the complexity's of
serial port i/o with API's. If you're not already familiar with
programming Windows, there's a pretty steep learning curve for
API's.

If you have rights to install ActiveX controls on the server,
you can probably pick up one of those for a couple of bucks that
will do what you're asking. Then, Serial I/O will be a snap
through PHP.
Dec 25 '06 #7

P: n/a
Solution:
Read This thread: (all of it!)
http://www.phparch.com/discuss/index.php/m/2980/0/

Merry whatever!

-Hackajar
bl**********@hotmail.com wrote:
I had a look at the APIs before I posted here and was praying for an
easier solution. So far no luck. I have used API calls in PHP before so
if it has to be the APIs then so be it, but I could not find an obvious
"is there any bytes to read" call there either.

I had a quick look at the MSCOMM32.OCX information and thought that
might do the trick, but I am not sure how to go about getting installed
on the server. I have full permissions (I built the server) but have
not played with ActiveX and PHP before.

Any guidance most gratefully received.

Fred.

Sanders Kaufman wrote:
bl**********@hotmail.com wrote:
Sanders Kaufman wrote:
>Just don't get confused with what's a COM port (communications)
>and what's a COM object (Component Object Model).
>
I didnt think I was confused, but perhaps I am.
>
Is there a standard COM Object for serial ports that I can instantiate
through PHP?
http://msdn2.microsoft.com/en-gb/library/aa490273.aspx

In Windows - not so much a COM object, as a suite of API's. In
the MSDN documentation, you can learn about the complexity's of
serial port i/o with API's. If you're not already familiar with
programming Windows, there's a pretty steep learning curve for
API's.

If you have rights to install ActiveX controls on the server,
you can probably pick up one of those for a couple of bucks that
will do what you're asking. Then, Serial I/O will be a snap
through PHP.
Dec 26 '06 #8

P: n/a
>>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)
ha******@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
bl**********@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.
js*******@attglobal.net
==================
Dec 27 '06 #9

P: n/a
Thanks - but even though I read it all I cant see a solution there.
Nothing in that thread pretests the port for data before trying to read
it.

Can you be more specific?

ha******@gmail.com wrote:
Solution:
Read This thread: (all of it!)
http://www.phparch.com/discuss/index.php/m/2980/0/

Merry whatever!

-Hackajar
bl**********@hotmail.com wrote:
I had a look at the APIs before I posted here and was praying for an
easier solution. So far no luck. I have used API calls in PHP before so
if it has to be the APIs then so be it, but I could not find an obvious
"is there any bytes to read" call there either.

I had a quick look at the MSCOMM32.OCX information and thought that
might do the trick, but I am not sure how to go about getting installed
on the server. I have full permissions (I built the server) but have
not played with ActiveX and PHP before.

Any guidance most gratefully received.

Fred.

Sanders Kaufman wrote:
bl**********@hotmail.com wrote:
Sanders Kaufman wrote:
>
Just don't get confused with what's a COM port (communications)
and what's a COM object (Component Object Model).

I didnt think I was confused, but perhaps I am.

Is there a standard COM Object for serial ports that I can instantiate
through PHP?
>
http://msdn2.microsoft.com/en-gb/library/aa490273.aspx
>
In Windows - not so much a COM object, as a suite of API's. In
the MSDN documentation, you can learn about the complexity's of
serial port i/o with API's. If you're not already familiar with
programming Windows, there's a pretty steep learning curve for
API's.
>
If you have rights to install ActiveX controls on the server,
you can probably pick up one of those for a couple of bucks that
will do what you're asking. Then, Serial I/O will be a snap
through PHP.
Dec 27 '06 #10

P: n/a
Got it all going using MSComm32.OCX as a COM object using PHP COM
handling. All very simple when you know how....

Jerry Stuckle wrote:
>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)
ha******@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
bl**********@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.
js*******@attglobal.net
==================
Jan 6 '07 #11

P: n/a
MSComm32.OCX as a COM object under PHP solves the problem simply - when
you know how.

Sanders Kaufman wrote:
bl**********@hotmail.com wrote:
Sanders Kaufman wrote:
Just don't get confused with what's a COM port (communications)
and what's a COM object (Component Object Model).
I didnt think I was confused, but perhaps I am.

Is there a standard COM Object for serial ports that I can instantiate
through PHP?

http://msdn2.microsoft.com/en-gb/library/aa490273.aspx

In Windows - not so much a COM object, as a suite of API's. In
the MSDN documentation, you can learn about the complexity's of
serial port i/o with API's. If you're not already familiar with
programming Windows, there's a pretty steep learning curve for
API's.

If you have rights to install ActiveX controls on the server,
you can probably pick up one of those for a couple of bucks that
will do what you're asking. Then, Serial I/O will be a snap
through PHP.
Jan 6 '07 #12

P: n/a
bl**********@hotmail.com wrote:
Jerry Stuckle wrote:
>>>>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)
ha******@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
bl**********@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.
js*******@attglobal.net
==================

Got it all going using MSComm32.OCX as a COM object using PHP COM
handling. All very simple when you know how....
(Top posting fixed)

Yes, you can use the com activex object, and it does help. But it's not
necessary.

You can even open the COM port as a r/w file if you can accept the
default settings (perhaps set up at boot time). No activex object required.

P.S. Please don't top post. Thanks.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jan 7 '07 #13

P: n/a
Sorry about the top post Jerry, but that is the way Google prefers it,
and the way they make it easy to use. It is actually the way I prefer
it too, but I am not about to try to sell that to others. Diversity is
healthy.

I have come to the conclusion that there is no other way to have
reliable asynchronous comms using PHP on Win32 other than using the
activex object. So far nobody who says otherwise can say how it can be
achieved in any sort of detail.

*ALL* other methods that can be implemented with PHP have no method for
testing the presence of data before a read, and do not return from a
read when there is no data to read. This generally leads to a lockup in
the RX side of the comms at some point or other, even with the most
careful attention to sequences. dio_read() is a case in example.
fread() cannot be specified with a length less than 1 (e.g. zero=get
whats there), and therefore falls into the same trap. Perhaps in a
perfect world with no comms errors ....

I have even tried to implement W32API calls to get the result, but
there is no reliable way of doing that with PHP before 6 so that went
the way of the dodo too (trapped in a PHP5 world for now). It is
returning structures that is the problem.

I have happily implemented MSComm32.ocx with the ultra reliable results
I needed so the question has become moot for me just now, but if you do
know of a way (in detail) then I would be most interested for future
projects.

Cheers,

Fred.

Jerry Stuckle wrote:
bl**********@hotmail.com wrote:
Jerry Stuckle wrote:
>>>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)
ha******@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
bl**********@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.
js*******@attglobal.net
==================
Got it all going using MSComm32.OCX as a COM object using PHP COM
handling. All very simple when you know how....
>

(Top posting fixed)

Yes, you can use the com activex object, and it does help. But it's not
necessary.

You can even open the COM port as a r/w file if you can accept the
default settings (perhaps set up at boot time). No activex object required.

P.S. Please don't top post. Thanks.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jan 16 '07 #14

P: n/a
bl**********@hotmail.com wrote:
Jerry Stuckle wrote:
>>bl**********@hotmail.com wrote:
>>>Jerry Stuckle wrote:
>>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)
ha******@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
>bl**********@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.
js*******@attglobal.net
==================
Got it all going using MSComm32.OCX as a COM object using PHP COM
handling. All very simple when you know how....

(Top posting fixed)

Yes, you can use the com activex object, and it does help. But it's not
necessary.

You can even open the COM port as a r/w file if you can accept the
default settings (perhaps set up at boot time). No activex object required.

P.S. Please don't top post. Thanks.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================


Sorry about the top post Jerry, but that is the way Google prefers it,
and the way they make it easy to use. It is actually the way I prefer
it too, but I am not about to try to sell that to others. Diversity is
healthy.

I have come to the conclusion that there is no other way to have
reliable asynchronous comms using PHP on Win32 other than using the
activex object. So far nobody who says otherwise can say how it can be
achieved in any sort of detail.

*ALL* other methods that can be implemented with PHP have no method for
testing the presence of data before a read, and do not return from a
read when there is no data to read. This generally leads to a lockup in
the RX side of the comms at some point or other, even with the most
careful attention to sequences. dio_read() is a case in example.
fread() cannot be specified with a length less than 1 (e.g. zero=get
whats there), and therefore falls into the same trap. Perhaps in a
perfect world with no comms errors ....

I have even tried to implement W32API calls to get the result, but
there is no reliable way of doing that with PHP before 6 so that went
the way of the dodo too (trapped in a PHP5 world for now). It is
returning structures that is the problem.

I have happily implemented MSComm32.ocx with the ultra reliable results
I needed so the question has become moot for me just now, but if you do
know of a way (in detail) then I would be most interested for future
projects.

Cheers,

Fred.
(Top posting fixed)

A. Because it upsets the flow of the messages
Q. Why is it so bad?
A. Top Posting
Q. What is the most annoying habit on usenet?

Possibly that's the way you prefer it, but the standards for this group
include bottom posting. You will get more attention when you follow the
standards. Many people just skip over messages which include top posting.

And I highly suggest you get a decent newsreader instead of Google
groups. The vast majority of us here do.

As for how to do it - you can use an ActiveX object, as you indicated.
Or, you can write a small PHP extension which will allow you to interact
with the IOCTL calls. The latter would have the advantage of being more
efficient and an ActiveX object, but you'd have to be able to write a
PHP extension.

As for my other comment - you don't need to use an ActiveX object *if
you can accept the default settings*. In your case you can't, because
you don't want the read to block, so you need to use something like an
ActiveX control or an extension.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jan 16 '07 #15

P: n/a

Jerry Stuckle wrote:
bl**********@hotmail.com wrote:
Jerry Stuckle wrote:
>bl**********@hotmail.com wrote:

Jerry Stuckle wrote:
>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)
ha******@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
bl**********@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.
js*******@attglobal.net
==================
Got it all going using MSComm32.OCX as a COM object using PHP COM
handling. All very simple when you know how....


(Top posting fixed)

Yes, you can use the com activex object, and it does help. But it's not
necessary.

You can even open the COM port as a r/w file if you can accept the
default settings (perhaps set up at boot time). No activex object required.

P.S. Please don't top post. Thanks.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Sorry about the top post Jerry, but that is the way Google prefers it,
and the way they make it easy to use. It is actually the way I prefer
it too, but I am not about to try to sell that to others. Diversity is
healthy.
>
I have come to the conclusion that there is no other way to have
reliable asynchronous comms using PHP on Win32 other than using the
activex object. So far nobody who says otherwise can say how it can be
achieved in any sort of detail.
>
*ALL* other methods that can be implemented with PHP have no method for
testing the presence of data before a read, and do not return from a
read when there is no data to read. This generally leads to a lockup in
the RX side of the comms at some point or other, even with the most
careful attention to sequences. dio_read() is a case in example.
fread() cannot be specified with a length less than 1 (e.g. zero=get
whats there), and therefore falls into the same trap. Perhaps in a
perfect world with no comms errors ....
>
I have even tried to implement W32API calls to get the result, but
there is no reliable way of doing that with PHP before 6 so that went
the way of the dodo too (trapped in a PHP5 world for now). It is
returning structures that is the problem.
>
I have happily implemented MSComm32.ocx with the ultra reliable results
I needed so the question has become moot for me just now, but if you do
know of a way (in detail) then I would be most interested for future
projects.
>
Cheers,
>
Fred.
>

(Top posting fixed)

A. Because it upsets the flow of the messages
Q. Why is it so bad?
A. Top Posting
Q. What is the most annoying habit on usenet?

Possibly that's the way you prefer it, but the standards for this group
include bottom posting. You will get more attention when you follow the
standards. Many people just skip over messages which include top posting.

And I highly suggest you get a decent newsreader instead of Google
groups. The vast majority of us here do.

As for how to do it - you can use an ActiveX object, as you indicated.
Or, you can write a small PHP extension which will allow you to interact
with the IOCTL calls. The latter would have the advantage of being more
efficient and an ActiveX object, but you'd have to be able to write a
PHP extension.

As for my other comment - you don't need to use an ActiveX object *if
you can accept the default settings*. In your case you can't, because
you don't want the read to block, so you need to use something like an
ActiveX control or an extension.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Always happy to follow standards so fiercely defended, especially when
it is the incumbents who do the work.

In theory, if I can write a PHP extension there would be nothing
unachievable. Unfortunately I needed something simpler that mere
mortals could make use of.

I always thought "settings" were configuration, not the underlying
functionality. I thought there was no "setting" in PHP that I could
change that would allow me to unblock. I suppose I have learned
something today.

Cheers,

Fred.

Jan 18 '07 #16

P: n/a
bl**********@hotmail.com wrote:
Jerry Stuckle wrote:
>bl**********@hotmail.com wrote:
>>Jerry Stuckle wrote:

bl**********@hotmail.com wrote:

Jerry Stuckle wrote:
>
>
>>>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)
>ha******@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
>>bl**********@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.
>js*******@attglobal.net
>==================
>
Got it all going using MSComm32.OCX as a COM object using PHP COM
handling. All very simple when you know how....
>
(Top posting fixed)

Yes, you can use the com activex object, and it does help. But it's not
necessary.

You can even open the COM port as a r/w file if you can accept the
default settings (perhaps set up at boot time). No activex object required.

P.S. Please don't top post. Thanks.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Sorry about the top post Jerry, but that is the way Google prefers it,
and the way they make it easy to use. It is actually the way I prefer
it too, but I am not about to try to sell that to others. Diversity is
healthy.

I have come to the conclusion that there is no other way to have
reliable asynchronous comms using PHP on Win32 other than using the
activex object. So far nobody who says otherwise can say how it can be
achieved in any sort of detail.

*ALL* other methods that can be implemented with PHP have no method for
testing the presence of data before a read, and do not return from a
read when there is no data to read. This generally leads to a lockup in
the RX side of the comms at some point or other, even with the most
careful attention to sequences. dio_read() is a case in example.
fread() cannot be specified with a length less than 1 (e.g. zero=get
whats there), and therefore falls into the same trap. Perhaps in a
perfect world with no comms errors ....

I have even tried to implement W32API calls to get the result, but
there is no reliable way of doing that with PHP before 6 so that went
the way of the dodo too (trapped in a PHP5 world for now). It is
returning structures that is the problem.

I have happily implemented MSComm32.ocx with the ultra reliable results
I needed so the question has become moot for me just now, but if you do
know of a way (in detail) then I would be most interested for future
projects.

Cheers,

Fred.

(Top posting fixed)

A. Because it upsets the flow of the messages
Q. Why is it so bad?
A. Top Posting
Q. What is the most annoying habit on usenet?

Possibly that's the way you prefer it, but the standards for this group
include bottom posting. You will get more attention when you follow the
standards. Many people just skip over messages which include top posting.

And I highly suggest you get a decent newsreader instead of Google
groups. The vast majority of us here do.

As for how to do it - you can use an ActiveX object, as you indicated.
Or, you can write a small PHP extension which will allow you to interact
with the IOCTL calls. The latter would have the advantage of being more
efficient and an ActiveX object, but you'd have to be able to write a
PHP extension.

As for my other comment - you don't need to use an ActiveX object *if
you can accept the default settings*. In your case you can't, because
you don't want the read to block, so you need to use something like an
ActiveX control or an extension.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Always happy to follow standards so fiercely defended, especially when
it is the incumbents who do the work.

In theory, if I can write a PHP extension there would be nothing
unachievable. Unfortunately I needed something simpler that mere
mortals could make use of.

I always thought "settings" were configuration, not the underlying
functionality. I thought there was no "setting" in PHP that I could
change that would allow me to unblock. I suppose I have learned
something today.

Cheers,

Fred.
Fred,

Yes, settings are configuration. And in many cases the default settings
will work.

But you have an additional requirement - you can't block on the read.
That's why you need your own extension, ActiveX control, etc.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jan 19 '07 #17

This discussion thread is closed

Replies have been disabled for this discussion.