PHP Classes

PHP Serial: Communicate with a serial port

Recommend this page to a friend!

  Author Author  
Name: Rémy Sanchez <contact>
Classes: 4 packages by
Country: France France
Age: 28
All time rank: 1039 in France France
Week rank: 23 Up2 in France France Up
Innovation award
Innovation award
Nominee: 3x

Winner: 1x

  Detailed description   Download Download .zip .tar.gz   Install with Composer Install with Composer  
This class can be used to communicate with a serial port under Linux or Windows.

It takes the path (like "/dev/ttyS0" for linux or "COM1" for windows) of serial device and checks whether it is valid before opening a connection to it.

Once the connection is opened, it can send data to the serial port, and read answers (reading is only implemented for Linux).

The class may also change connection parameters for the given serial device.

The class is working with Linux for read and write operations, but under Windows it only works for write operations. Under Windiws try accessing the serial port through network with serproxy instead.

The class have been reported to work fine with Mac OS X, but it was not tested it.

PHP Serial

PHP Serial was written at a time where I did not know any other language than
PHP and I started to get seriously bored with its abilities.

I somehow got hold of a « Citizen C2202-PD » point-of-sale display, and I wanted
to play around with it. I also managed to get the documentation of it, and
created a convenience class to access the serial port though the Linux file.

Afterwards, I posted it to [PHP Classes](,
and this probably is what brought it any visibility.


include 'PhpSerial.php';

// Let's start the class
$serial = new PhpSerial;

// First we must specify the device. This works on both linux and windows (if
// your linux serial device is /dev/ttyS0 for COM1, etc)

// We can change the baud rate, parity, length, stop bits, flow control

// Then we need to open it

// To write into
$serial->sendMessage("Hello !");

State of the project

Interestingly enough, this piece of code that is widely untested has created a
lot if interest ever since it was created, and especially nowadays with
everybody toying around with Arduinos and Raspberry Pis. I receive about 1 email
every month asking for help with the code or sending patches/suggestions.

I think that it is time for me to remove the dust off this project and to give
it a full visibility on modern tools, aka GitHub.

### Bugs

There is **lots** of bugs. I know there is. I just don't know which are they.

### Platform support

* **Linux**: the initially supported platform, the one I used. Probably the less
  buggy one.
* **MacOS**: although I never tried it on MacOS, it is similar to Linux and some
  patches were submitted to me, so I guess it is OK
* **Windows**: it seems to be working for some people, not working for some
  others. Theoretically there should be a way to get it done.

### Concerns

I have a few concerns regarding the behaviour of this code.

* Inter-platform consistency. I seriously doubt that all operations go the same
  way across all platforms.
* Read operations. Reading was never needed in my project, so all the tests I
  did on that matter were theoretic. I was also quite naive, so the API is
  probably not optimal. What we need is to re-think reading from scratch.
* Configuration done by calling functions. This is so Java. It would be much
  better to be able to pass a configuration array once and for all. Furthermore,
  I suspect that the order of call matters, which is bad.
* Auto-closing the device. There is an auto-close function that is registered
  at PHP shutdown. This sounds quite ridiculous, something has to be done about
* Use exceptions. Currently there is an heavy use of the errors system to report
  errors (2007 baby), but this is seriously lame. They have to be replaced by
  actual exceptions.

Call for contribution

I have about 0 time to code or test this project. However, there is clearly a
need for it.

As in all open-source projects, I need people to fit this to their needs and to
contribute back their code.

What is needed, IMHO:

* Address the concerns listed above, and find new ones.
* Create a reproducible test environment for each OS, and prove that each
  feature works (basically, unit-testing).
* Report of use cases, bugs, missing features, etc.

If you feel like doing any of those, do not hesitate to create an issue or a
pull-request, I'll gladly consider consider it :)


PHP Serial
Copyright (C) 2007-2014 PHP Serial's contributors (see CONTRIBUTORS file)

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
GNU General Public License for more details.

You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

  Classes of Rémy Sanchez  >  PHP Serial  >  Download Download .zip .tar.gz  >  Support forum Support forum (39)  >  Blog Blog  >  RSS 1.0 feed RSS 2.0 feed Latest changes  
Name: PHP Serial
Base name: php_serial
Description: Communicate with a serial port
Version: 1.1
PHP version: 5.2
License: GNU General Public License (GPL)
All time users: 16016 users
All time rank: 50
Week users: 27 users
Week rank: 18 Up
  Groups   Rate classes User ratings   Dependents  
  Trackback   Applications   Related pages   Files Files  

Group folder image Unix Use of capabilities specific of POSIX, Unix like operating systems View top rated classes
Group folder image Windows Use of capabilities specific of the Windows operating systems View top rated classes
Group folder image Mac OS Use of capabilities specific of Apple Mac operating systems View top rated classes
Group folder image Hardware Communicate with computer hardware and peripheral devices View top rated classes


Get value from a machine
Get value from milk analyzer machine

What is the best PHP rs232 class?
Get data from rs232 in php for data logger

Socket connection to com port
How to communicate with a COM port?

What is the best PHP serial connection class?
Create serial connection

  Innovation Award  
PHP Programming Innovation award nominee
February 2007
Number 2

Prize: One downloadable copy of Komodo Pro
Serial ports are often used to communicate with peripheral devices, such as: modems, POS terminals, special printers, etc..

This class can be used to communicate and configure peripherals connected to a serial port under Linux, simplifying the development of applications that need access serial devices.

Manuel Lemos

  User ratings  
RatingsUtility Consistency Documentation Examples Tests Videos Overall Rank
All time: Good (82%) Good (80%) - Sufficient (78%) - - Not sure (57%) 1595
Month: Not yet rated by the users

  Other classes that need this package  
Class Why it is needed Dependency
Citizen C2202-PD Control Class Uses PHPSerial to communicate with the device Required

  Pages that reference this package  
Arduino has slowed me down!
Arduino has slowed me down! Posted on August 11th, 2009 in Arduino, August, Electronics, Hobbies Sorry folks, I know I’ve been pretty slow to update the site, it’s just that I bought an Arduino Duemilanove development board , an Ethernet shield from sparkfun electronics and some MegaBrite, ShiftBrite and OctoBrite modules from MaceTech...
Comunicación con los puertos serie en PHP
Hace tiempo nos preguntaban como leer de los puertos serie desde PHP, y ahora acabo de encontrar eso mismo y además cómo hacerlo para Windows y para Linux...
Controlar puertos serie desde php
Existen dos extensiones para conseguir comunicarnos con los puertos series del equipo en el que corre nuestra aplicación php...
Escribe mensajes en un display desde cualquier parte del mundo
Hoy, navegando me encontré con una página muy interesante, es un proyecto muy “geek”...
Escribiendo mensajes en un display, a Km de distancia!
Es una curiosa idea que vi hace tiempo y dejé pasar, pero ahora le he visto por tantos blogs que no podía dejar de escribir aquí de ella. Un chico joven ha conectado un display de leds de 120×7pixels y tricolor a un ordenador por el puerto serie (RS232)....
Handy Link: PHP Serial Class
Need a way to talk to your serial devices (Arduino, PIC Micro, etc) using PHP?...
Howto Send/Read SMSs using a GSM modem, AT+ commands and PHP
I need to send/read SMS with PHP...
Interfacing PHP with the Arduino (with a splash OS X)
A while ago I bought an Arduino Diecimila, which is an open-source electronics prototyping platform...
Leer y escribir el puerto serie con php
Buenas, aca hay algo muchachos pero por lo q ví, con esa clase, en windows se puede escribir nomás el puerto, pero en linux se puede escribir y leer el puerto serie...
Nouvelle version de phpSerial
Vous pourrez trouver la nouvelle version de phpSerial, ma classe pour lire/écrire sur le port série depuis linux ou windows (sauf que windows gère pas la lecture) en PHP sur le site PHP Classes.
PHP and Serial Ports
Last month there were at least two enquiries at the Bangalore PHP UG on how to get PHP to communicate with the server’s serial port...
PHP and Serial Ports
In a recent post to his blog, Vinu Thomas posted about a PHP extension that allows your scripts to directly interact with the serial ports on the web server its running on...
PHP and the Arduino - Followup
I’ve had a bit of interest on the original entry, asking for more detail on the code used in the video demonstation at the end...
PHP ile COM balantysy
Asag&#305;da ki linkleri bir incele istersen...
PHP Serial Class for OSX
Below is an archive of my PHP Serial Class page from my old site.
PHP Serial port
Just searching for php serial port class came up with this link.
PHP ve Serial Port
PHP ve Serial Port
vakti zamaninda kendim yazm&#305;stim ama ticari bir is oldugu için o kodlar&#305; koyamiyorum buraya... ama altta verdigim classin çalist&#305;g&#305;n&#305; biliyorum.
PHP: Your imagination is your limit
Do you think PHP was only developed for write Web-Sites?...
Possible way to control Parallel port through ID php
Possible, use this class...
Tarificador de llamadas telefónicas en PHP
Se me ocurren dos soluciones: Puedes usar una clase llamada PHP Serial que creo seria la mejor forma...

Latest pages that reference packages Latest pages that reference packages

  Applications that use this package  
No pages of applications that use this class were specified.

Add link image If you know an application of this package, send a message to the author to add a link here.

  Related pages  
Homesite of setserial, used by phpSerial

  Files folder image Files  
File Role Description
Files folder imageexamples (3 files)
Files folder imagesrc (1 file)
Accessible without login Plain text file php_serial.class.php Class The class itself
Plain text file composer.json Data Sync with GitHub
Plain text file CONTRIBUTORS Data Sync with GitHub
Plain text file COPYING Data Sync with GitHub
Accessible without login Plain text file example.php Example A small example
Plain text file Data Sync with GitHub

  Files folder image Files  /  examples  
File Role Description
  Plain text file dummy.php Example Sync with GitHub
  Plain text file sms.php Example Sync with GitHub
  Plain text file VS421CPNTA.php Example Sync with GitHub

  Files folder image Files  /  src  
File Role Description
  Plain text file PhpSerial.php Class Sync with GitHub

Install with Composer Install with Composer - Download Download all files: php_serial.tar.gz
NOTICE: if you are using a download manager program like 'GetRight', please Login before trying to download this archive.