Reply to Re: Reading COM1 with php-win

Your name:

Reply:


Posted by Jerry Stuckle on 01/19/07 00:50

bloggsfred00@hotmail.com wrote:
> Jerry Stuckle wrote:
>> bloggsfred00@hotmail.com wrote:
>>> Jerry Stuckle wrote:
>>>
>>>> bloggsfred00@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)
>>>>>> 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
>>>>>> ==================
>>>>>
>>>>> 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.
>>>> jstucklex@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.
>> jstucklex@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.
jstucklex@attglobal.net
==================

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация