PHP and Serial Ports

Written on April 9, 2007 | by vinu |

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. I didn’t think it was possbile, but here’s what a quick google search turned up:

PHP Serial Extension:

This PHP extension for Windows allows you to communicate directly with the serial port through PHP.

This is a loadable extension for PHP running on Windows implementing serial port handling and communications. Once installed in PHP environment you can programm PHP applications to control serial device hosted on server from remote location; these devices can be anything from video switcher, cameras pan/tilt, ham radios, media players, home automation boxes, GSM modems/terminals (send/receive SMS), only your imagination and needs are the limits.

Link: http://www.easyvitools.com/phpserial/index.html
Link to installation instructions and usage: http://www.easyvitools.com/phpserial/php_ser_reference.html

PHP Serial Class

If you’re a solution in Linux, here’s the PHP class you’re looking for. PHPClasses.org has a PHP Serial Class which allows you interact with your serial ports in Linux

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. It takes the path 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. The class may also change connection parameters for the given serial device.

Link: http://www.phpclasses.org/browse/package/3679.html

If you’ve used any of these solutions for your applications, do let me know your feedback.

Attaining qualifications like 642-425 and 642-432 make one go for 642-444 and 642-511 as well.

Bookmark and share: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • del.icio.us
  • Digg
  • StumbleUpon
  • BlinkList
  • blogmarks
  • Furl
  • Slashdot
  • Spurl
  • Technorati
  • YahooMyWeb
  • DZone
  • e-mail
  • Facebook
  • Google
  • IndianPad
  • Live
  • Ma.gnolia
  • NewsVine
  • Reddit
  • TwitThis
  1. 15 Responses to “PHP and Serial Ports”

  2. By Rémy Sanchez on Apr 9, 2007 | Reply

    Hello,
    I wrote the phpSerial class, so I could test serial port through PHP. It is working realy fine for controlling a customer display. I am writing additional components for the class in order to be able to read the serial port and use it under windows.

    I will be pleased to answer to questions, as far I can ^^

  3. By vinu on Apr 10, 2007 | Reply

    Thanks Rémy. We’ll be interested to get any updates to your class, especially the ability to read from the serial port.

  4. By Rémy Sanchez on Jun 2, 2007 | Reply

    I just released my new version. Adds :
    - Support of windows
    - Easy configuration of serial port
    - Reading (linux only)

  5. By vinu on Jun 2, 2007 | Reply

    Thanks for the update Rémy.

  6. By wayne hutchison on Jun 16, 2007 | Reply

    Dear Remy:
    I am developing my own open source home automation/robotics system. I currently use Apache/PHP/Serial Extender in Windows, but need to port all to Linux/Debian/Slackware.
    Could you show me how to use your php_serial.class in PHP?
    I need to send/receive characters from Web page to serial port. Any help would be greatly appreciated :))

    Sincerely,
    Wayne Hutchison, VoX Automation, LLC

  7. By vinu on Jun 18, 2007 | Reply

    Wayne,
    You can contact Rémy over at:
    http://remy.is-a-geek.org/moi/

  8. By stonicus on Jul 6, 2007 | Reply

    Awesome class. How soon before you’ll have read capability for Windows?

  9. By Rémy Sanchez on Jul 25, 2007 | Reply

    Thanks for the “awsome” =D
    But I don’t think I ever manage to get reading for windows… I already tried a lot of different functions, and each time it acts as if the stream was empty… So for a pure PHP implementation I don’t think it is possible (or maybe on win 9x only, but actualy I have no time for testing it).
    Maybe you can connect to some serproxy server instead

  10. By Ilya on Aug 18, 2007 | Reply

    Hello!

    Great class! One problem though that I couldn’t find a solution for.

    When I receive a response back from the RS-232 device I communicate with, for some reason my script
    (utilizing the serial class) echoes every character of the response back to the serial device.
    E.g. when I connect to the serial port with hyper terminal and send a command to it — it works fine, but when I type something back on the hyper terminal I get every single character echoed back — so that have 2 symbols for each one I type on the screen if the local echoing is on and
    just 1 symbol for each one I type if the local echoing is off.
    Could anyone please tell me what I need to do to disable the echoing back? I’d really appreciate your help.

    Thanks!

  11. By Rav on Mar 15, 2008 | Reply

    Hey.. this isn’t working for me.. I am using Fedors core 4.. I tried to connect thru Stty1 and it does nothing…. no error msg too..

  12. By Lara on Mar 17, 2008 | Reply

    Hi
    I need to send some data to a printer conected to serial port (com)
    and i wnat know the function in PHP that did this operation
    Thanks

  13. By Mike FIeld on Mar 18, 2008 | Reply

    Hi,

    I am able to read/write to a serial port under windows with nothing more exotic than the code below. I am just working on exec()ing a ‘mode’ command to set the port speeds and so on.

    Mike
    <?php
    function readInput($f,$t)
    {
    $i=0;
    $buffer = “”;
    while($i “.$buffer;
    }

    error_reporting(E_ALL);

    $f = fopen(”COM4″,”r+”);
    if(!$f)
    {
    die(”Unable to open serial portn”);
    }
    $i=0;
    fwrite($f,”Hellorn”);
    while(true)
    {
    fwrite($f,”AT-”);
    sleep(1);
    readInput($f,5);
    fwrite($f,”AT+CMGF=1-”);
    sleep(1);
    readInput($f,5);
    fwrite($f,”AT+CMGW=”0212266816″-”);
    sleep(1);
    readInput($f,5);
    fwrite($f,”AT+CMSS=1-”);
    sleep(1);
    readInput($f,5);
    $i++;
    }

    fclose($f);
    ?>

  14. By EDWINSPIRE on Apr 21, 2008 | Reply

    Saludos:
    He programado en PHP un software que permite comunicarse con el puerto serial, enviarle un comando AT y leer su respuesta.
    El software esta diseñado para enviar y recibir SMS tanto en formato PDU como en modo Texo.
    Para mas informacion y descargas visiten edwinspire.890m.com hagan clic en PROGRAMACION PHP

    Translation (google translate):

    Hello!
    I programmed a PHP software that allows you to communicate with the serial port, send an AT command and read its response.
    The software is designed to send and receive SMS in either mode as PDU Texo.
    For more information and downloads visit edwinspire.890m.com click on PHP Programming

  1. 2 Trackback(s)

  2. Apr 16, 2007: developercast.com » Vinu Thomas’ Blog: PHP and Serial Ports
  3. May 4, 2007: Notícias e links - 03/05 « PHP-BR

Post a Comment

About Me

Here's my blog on stuff I keep finding on the Web. More

Want to subscribe?

 Subscribe in a reader Or, subscribe via email:
Enter your email address:  
On the Go? Get this on your Widsets: Add to my Widsets
Find entries :