php_serial.class.php.gz (3.7 kB)
Gives serial access to PHP under linux, OSX and Windows (write-only under Windows).
This class can be used to communicate with a serial port under Linux, OSX 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 example script:
deviceSet("COM1");
// Then we need to open it
$serial->deviceOpen();
// To write into
$serial->sendMessage("Hello !");
// Or to read from
$read = $serial->readPort();
// If you want to change the configuration, the device must be closed
$serial->deviceClose();
// We can change the baud rate
$serial->confBaudRate(2400);
// etc...
?>
Author Rémy Sanche
Thanks Aurélien Derouineau for finding how to open serial ports with
windows
Thanks Alec Avedisyan for help and testing with reading
OSX tweaks added by Rizwan Kassim
copyright under GPL 2 licence
phpserial 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. For full license text see file COPYING included in the source tarball.