Active9 months ago

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?

dsolimano

PHP by default does not offer good COM port support however a PHP extension called Direct IO does offers low level access to IO. We will use this extension for serial port communication. On unix system install the extension using PECL, open. Linux/php serial port read - How to stop fread() waiting forever if no new data? I'm working through exactly the same issue as described by skaap2k. (11/04/07 12:01 AM, ID: 22503690). I think we have a problem with communication here. What I meant to convey is that the php script stalls, waiting for serial data. The linux operating system. PHP USB serial port call from Windows to Linux. So similarly windows software like 232Analyser, can connect to COM3 and send code in DEC like 1,255,255,255,255,5.

7,6473 gold badges41 silver badges57 bronze badges
syazsyaz
1,3046 gold badges29 silver badges43 bronze badges

7 Answers

Every solution above is either inefficient or too much work.

Home » HP Scanjet 5400C Series Use the links on this page to download the latest version of HP Scanjet 5400C Series drivers. All drivers available for download have. HP Scanjet - Scanners supported in Windows Vista. Supported scanners. Not supported scanners. The following list of scanners have a basic driver available from HP for Windows Vista, but do not have the complete software solution: Scanjet Model Number. Solution Available. Hp 5470c scanjet.

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.

user633183
77.9k22 gold badges152 silver badges192 bronze badges
Dustin OpreaDustin Oprea
5,3336 gold badges46 silver badges77 bronze badges

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

SoapBoxSoapBox
18.2k3 gold badges41 silver badges82 bronze badges

You need to set up the com port using a DOS-like command.

Open serial port linux

For example, the following line executes the command through php:

To display the results you can use:

Create the resource id:

Write to port:

Hp deskjet f4180 drivers windows 10. HP DeskJet F4180 Latest Printer Driver Update HP DeskJet F4180 Printer Drivers Download Table: Driver Type Version File Size Supported Operating System Download Link HP Deskjet F4180/F2100/F4100 Full Feature Software and Driver 2009-07-17, Version 9.0.1 162.9 MB Windows 8.1 32bit, Windows 8.1 64bit, Windows 7 32bit, Windows 7 64bit, Windows 10 32bit, Windows 10 64bit. The Even driver is free to install.

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.

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.

David Refoua
1,9851 gold badge23 silver badges39 bronze badges
Giorgos Pap

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.

lpfavreau

Open Serial Port Linux

lpfavreau
8,5783 gold badges26 silver badges35 bronze badges

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.

MichaelMichael

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.

Tracker1Tracker1
14.7k9 gold badges68 silver badges99 bronze badges

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

Community
adiadi
10.1k4 gold badges20 silver badges35 bronze badges

Not the answer you're looking for? Browse other questions tagged phpserial-portcommunication or ask your own question.

Active6 years, 8 months ago

I have installed xampp in fedora 13.I am trying to communicate with microcontroller through serial port using php serial class.My code is example.php

The php script gets executed but gives the following warnings .

Warning: Specified serial port is not valid in /opt/lampp/htdocs/xampp/php_serial.class.php on line 147Warning: Unable to set the baud rate : the device is either not set or opened in /opt/lampp/htdocs/xampp/php_serial.class.php on line 241Warning: Unable to set parity : the device is either not set or opened in /opt/lampp/htdocs/xampp/php_serial.class.php on line 295

.. I have used the command : chmod 0777 /dev/ttyUSB0 to give permissions . I have also tried to add the apache user 'prudhvi' to the dialout group by using command : $ usermod -a -G dialout prudhvi

But it doesnt work . When I send a command directly from the terminal using the command : echo 1 > /dev/ttyUSB0 it works and '1' is transmitted to the serial port . But using php I get the above warnings .

I have used the '$whoami' to check name of user and added that user 'prudhvi' to the dialout group . It still doesnt work . Please help me guys.

prudhvi09

Php Serial Port Communication Linux Software Package

prudhvi09prudhvi09

4 Answers

I did this once with Debian to control an Arduino board with a PHP script and initially ran into the same problem.

In Debian, you need to add the Apache user to the dialout group in order to allow it to make serial connection requests. I would assume the same is true for Fedora.

Php Serial Port Communication Linux Software

In Debian the command is:

However I believe Fedora names the Apache user as apache instead. I don't have a Fedora machine to test on, but I would assume the command you need to run is:

You will then need to restart your xampp server.

See the following for reference:

Neal

nealio82nealio82
2,5191 gold badge12 silver badges19 bronze badges

Could you post the lines near / related to '/opt/lampp/htdocs/xampp/php_serial.class.php on line 147'?

Serial Port Communication

I suspect that you are trying to set the device incorrectly (as Marc indicated). Either that or the port is already in use from other testing you are conducting at the same time. I'm not sure if the script you are running provides errors specific to ports you are trying to attach to already being in use.

PilipoPilipo

First test a hello world type php script to testyour basic installation.

Then verify the web server / php engine is running as a user which is in a group allowed to access the applicable /dev/ttyWHATEVER device file corresponding to the serial port. It would be surprising if that were true by default - you'll probably have to add it to the 'dialout' or similar group.

Add some fault checking / reporting to your code.

Chris StrattonChris Stratton
36.3k5 gold badges66 silver badges106 bronze badges

Credit goes to Marc B's comment for causing me to look this up, and he's dead on: http://www.phpclasses.org/browse/file/17926.html

I believe that calling $serial->deviceSet('/dev/ttyUSB0'); will fix it, but you may have to modify the source of php_serial.class.php to work on /dev/ttyUSB instead of /dev/ttyS.

zebediah49zebediah49

Not the answer you're looking for? Browse other questions tagged phplinuxserial-communication or ask your own question.