PHP Classes

php Serial Hexadecimal

Recommend this page to a friend!

      PHP Serial  >  All threads  >  php Serial Hexadecimal  >  (Un) Subscribe thread alerts  
Subject:php Serial Hexadecimal
Summary:how to send hexadecimal data to serial port
Author:dung le
Date:2013-09-28 14:36:30
Update:2014-06-19 11:58:39

  1. php Serial Hexadecimal   Reply   Report abuse  
Picture of dung le dung le - 2013-09-28 14:36:30
Hello there,

Could you please tell us if We can send a hexadecimal such as FE and 00 or FE and 01 to the serial port's external device?.

Please help us, because php serial port communication is exactly what we need. And we have been searching the web for a few days :( without luck until we find this forum.

Many thanks!

We hope to hear from you.


the program looks like this:

* Simple serial relay script for turning my sprinkler system on and off from the web!
* Utilizes the PHP Serial class by Rémy Sanchez <>
* (Thanks you rule!!) to communicate with the QK108/CK1610 serial relay board!

//check the GET action var to see if an action is to be performed
if (isset($_GET['action'])) {
//Action required

//Load the serial port class

//Initialize the class
$serial = new Ilib_SerialPort();

//Specify the serial port to use... in this case COM1

//Set the serial port parameters. The documentation says 9600 8-N-1, so
$serial->confBaudRate(9600); //Baud rate: 9600
$serial->confParity("none"); //Parity (this is the "N" in "8-N-1")
$serial->confCharacterLength(8); //Character length (this is the "8" in "8-N-1")
$serial->confStopBits(1); //Stop bits (this is the "1" in "8-N-1")
//Device does not support flow control of any kind,
//so set it to none.

//Now we "open" the serial port so we can write to it

//Issue the appropriate command according to the serial relay
//board documentation
if ($_GET['action'] == "on") {
//to turn relay number 1 on, we issue the command
echo(" fe and 01");

} else if ($_GET['action'] == "off") {
//to turn relay number 1 off, we issue this command
echo(" fe and 00");

//We're done, so close the serial port again


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Sprinkler System Controller</title>

<h1>Sprinkler System Controller</h1>
<a href="<?=$_SERVER['PHP_SELF'] . "?action=on" ?>"> Click here to
turn the system on.</a>
<a href="<?=$_SERVER['PHP_SELF'] . "?action=off" ?>"> Click here to
turn the system off.</a>


  2. Re: php Serial Hexadecimal   Reply   Report abuse  
Picture of Eric Leclerc Eric Leclerc - 2014-06-19 11:58:39 - In reply to message 1 from dung le
I want to know if you succeed on this way because I want to do the same.