473,390 Members | 1,216 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,390 software developers and data experts.

Reading COM1 with php-win

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
16 4120
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

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
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
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
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
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
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
>>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
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
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
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
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
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
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

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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Ian Pawson | last post by:
I have php 4.3.3 on my local IIS5.1 server (XP) in ISAPI mode. It all works ok except that it does not seem to be reading the php.ini file as any changes I make are not shown up when doing a...
3
by: Hayden Kirk | last post by:
Does anyone know why the ASPI module of php is not reading my php.ini in my c:\winnt directory? Won't read it no matter what I do
29
by: rjames.clarke | last post by:
I am developing an online application and the last thing I need to get a handle on is security. This app is very heavy with forms. Business critical data will be entered via forms and inserted in...
2
by: Tony | last post by:
I'm trying to setup PHP5 on a test server at work. I removed PHP 4 and setup PHP5 as a clean install. I did the manual install per the instructions. The machine run Windows Server 2003 with IIS...
3
by: ambrish | last post by:
How can I read any text(PDF/Doc/PPT/rtf/etc.) file using PHP. Ambrish
1
by: shaahid786 | last post by:
hallo, Plz tell me how can i read an Excell File using php code. its very urgent if sombody is on line plz tell me fast.coz i have to work on that. i have already search on diffrent sites...
6
by: eholz1 | last post by:
Hello Users, I am not sure if this is the place to post an imagemagick question - please advise. I have imagemagick 6.3 installed, runs from command line ok, etc. I have tried (several times...
15
by: himilecyclist | last post by:
My State government organization has written a PHP/MySQL application which has been in production for about 6 months and has been highly successful. We are now embarking on a similar database...
4
by: boonboy28 | last post by:
I have a BS microcontroller sending data over the serial port to a pc with php. the data is indeed sent as it is displayed within the terminal window. So I have sent and received data over the serial...
1
by: hott5hotj | last post by:
I have been trying to create an authentication system using PHP5+, MYSQL 5+ and APACHE2+ using Actionscript3. When I got the codes together my password and usernames would not check against the MYSQL...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.