Php Extension Serial Port
Php documentation: Reading serial port with Event and DIO. Php documentation: Reading serial port with Event and DIO. RIP Tutorial. HTTP Client Based on Event Extension; Reading serial port with Event and DIO; Spawning non-blocking processes with procopen. Serial port access in PHP with Windows (XP and higher). The php serial extension by thebyteworks. That's why I've written and compiled a univeral tool for serial port access that can be called by PHP via the shell extension. My own C workaround Structure: comxs.exe. Can PHP running on a Linux webserver open, via the internet, a remote laptop's serial port and issue instructions? I'd like to have a web page (internet surfer) invoke PHP code from a website and open a remote, standard, internet connect laptop's serial port.
I am looking for a way to communicate with RS232 serial COM port on windows. I have found 2 solutions on the net, one which is not totally free (introduces deliberate delays on the function) and another with limited capability on Windows. The latter can only write to a COM port on Windows, not read.
I can't look at the code of the first solution since it is compiled into a .dll (makes sense, otherwise people can just edit the delay and not purchase it..) and the second one seems only to use fopen() to open the port and later fwrite() to it for writing, just like one would do to a stream. But apparently freading it returns nothing.
I know it's possible as the first solution did it, although it does require Apache to use php-cgi module instead of php5module.
Any ideas?
Buy Serial Port
dsolimano7 Answers
Every solution above is either inefficient or too much work.
You can just use the PHP-DIO library (dio_fcntl, dio_open, dio_read, dio_write, dio_seek, ..). It's also in the PHP manual's entry for DIO:
This PECL package isn't available by default. To get it for Windows if you have PHP 5.2.x greater than 5.2.6, you can download it as part of a ZIP:
Both of these links were found in http://www.deveblog.com/index.php/download-pecl-extensions-for-windows/
Here is the build from Linux, just get it and do the phpize/configure/make/make install thing.
I don't know whether it should be used in an Apache session, but go for it.
user633183The easiest way to tackle this would be to write a program in another language (such as C++) and then execute it from your php script with system()
. Doing Comm I/O in C++ is trivial.
This assumes you have enough access to the server to configure it to allow the executable to be run by php, etc.
SoapBoxSoapBoxYou need to set up the com port using a DOS-like command.
For example, the following line executes the command through php:
To display the results you can use:
Create the resource id:
Write to port:
Read from port:
Maybe someone can help me with the fgets
problem. It stacks there for exactly one minute if TO=on
, or stacks there forever if TO=off
. It seems to be a 'MODE COM
' option so maybe a DOS expert can help.
Comsol multiphysics tutorial pdf. COMSOL Multiphysics gives you complete control over both the definitions and use of your material properties through the Model Builder and Material Browser. The Material Browser allows you to manage all of your model’s materials in one place, and can be complemented by the Material Library. To download the MPH-files, log in or create a COMSOL Access account that is associated with a valid COMSOL license. Note that many of the examples featured here can also be accessed via the Application Libraries that are built into the COMSOL Multiphysics ® software.
Perhaps instead of fgets
, one should use fgetc
, since fgets
capture through to the newline
, while fgetc
captures a single character. If a new line isn't encountered, it may block until there is one or until the buffer is flushed. The one minute delay may be windows flushing its buffer on an interval.
Another possible way would be to use the Win32 API through something like w32api_register_function()
or ffi and then use serial communications calls to get it to work under Windows.
I had the same problem and already considered writing my own php extension when I came across this solution which is popular with Arduino developers - 'serproxy' (found it at many places, ie. http://www.lspace.nildram.co.uk/freeware.html ) sets up a tcp stack to/from the serial ports and allowed me to use the php socket functions to communicate with it.
Another option is to use an object via ActiveX on windows. There are several, mostly commercial serial objects for COM on windows. You can also expose a .Net based object and register it for COM use as well. Of course, this does presume you have control on the server to register a COM control, as you would need a serial interface.
Another issue is resource contention if this is for use via the Web. If this is for a serial printer, for instance, then a print queue manager would be your best option over direct communication.
Tracker1Tracker1If you want to deal with sms using com port then here is the most famous php serial communication class by Rémy Sanchez with google sample code. Here is a thread which includes that topic.
Not the answer you're looking for? Browse other questions tagged phpserial-portcommunication or ask your own question.
I have machine connected to my system through serial port. When a message is triggered from machine through serial port, I have to get a hit a PHP file, is it possible?
1 Answer
Serial Port Arduino
dio
php extension is what you need.you can install it like this
and this is a code sample :
also you can use this PHP-Serial repository.
here you can see sample code for this:
Ebrahim PoursadeqiEbrahim Poursadeqi